damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit c05223ca2b651ffa0b98b209751e832515c395d5
parent 5d441d319296a8f8ccea75e64c6ca5e573552610
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 14 Mar 2023 17:12:37 -0600

refactor: extract on_user_tapped in UserSearch

Diffstat:
Mdamus/Views/Posting/UserSearch.swift | 50+++++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift @@ -31,35 +31,39 @@ struct UserSearch: View { return search_users(profiles: damus_state.profiles, tags: contacts.tags, search: search) } + func on_user_tapped(user: SearchedUser) { + guard let pk = bech32_pubkey(user.pubkey) else { + return + } + + while post.string.last != "@" { + post.deleteCharacters(in: NSRange(location: post.length - 1, length: 1)) + } + post.deleteCharacters(in: NSRange(location: post.length - 1, length: 1)) + + + var tagString = "" + if let name = user.profile?.name { + tagString = "@\(name)\u{200B} " + } + let tagAttributedString = NSMutableAttributedString(string: tagString, + attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), + NSAttributedString.Key.link: "@\(pk)"]) + tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2)) + tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2)) + let mutableString = NSMutableAttributedString() + mutableString.append(post) + mutableString.append(tagAttributedString) + post = mutableString + } + var body: some View { ScrollView { LazyVStack { ForEach(users) { user in UserView(damus_state: damus_state, pubkey: user.pubkey) .onTapGesture { - guard let pk = bech32_pubkey(user.pubkey) else { - return - } - - while post.string.last != "@" { - post.deleteCharacters(in: NSRange(location: post.length - 1, length: 1)) - } - post.deleteCharacters(in: NSRange(location: post.length - 1, length: 1)) - - - var tagString = "" - if let name = user.profile?.name { - tagString = "@\(name)\u{200B} " - } - let tagAttributedString = NSMutableAttributedString(string: tagString, - attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), - NSAttributedString.Key.link: "@\(pk)"]) - tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2)) - tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2)) - let mutableString = NSMutableAttributedString() - mutableString.append(post) - mutableString.append(tagAttributedString) - post = mutableString + on_user_tapped(user: user) } } }