refactor: extract on_user_tapped in UserSearch
This commit is contained in:
@@ -31,35 +31,39 @@ struct UserSearch: View {
|
|||||||
return search_users(profiles: damus_state.profiles, tags: contacts.tags, search: search)
|
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 {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
ForEach(users) { user in
|
ForEach(users) { user in
|
||||||
UserView(damus_state: damus_state, pubkey: user.pubkey)
|
UserView(damus_state: damus_state, pubkey: user.pubkey)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
guard let pk = bech32_pubkey(user.pubkey) else {
|
on_user_tapped(user: user)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user