File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // UserName.swift
3+ // V2exOS
4+ //
5+ // Created by m on 2022/9/30.
6+ //
7+
8+ import Foundation
9+ import SwiftUI
10+
11+ struct UserName : ViewModifier {
12+ var username : String
13+ func body( content: Content ) -> some View {
14+ Text ( username)
15+ . foregroundColor ( . secondary)
16+ . fontWeight ( . bold)
17+ . onTapGesture {
18+ if let url = URL ( string: " https://www.v2ex.com/member/ \( username) " ) {
19+ NSWorkspace . shared. open ( url)
20+ }
21+ }
22+ }
23+ }
24+
25+
26+ extension Text {
27+ func linkName( _ text: String ) -> some View {
28+ modifier ( UserName ( username: text) )
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -46,9 +46,8 @@ struct CommentListView: View {
4646 VStack ( alignment: . leading, spacing: 6 ) {
4747 HStack {
4848 if let username = comment. member. username {
49- Text ( username)
50- . foregroundColor ( . secondary)
51- . fontWeight ( . bold)
49+ Text ( " " )
50+ . linkName ( username)
5251 }
5352
5453 if let created = comment. created {
Original file line number Diff line number Diff line change @@ -36,7 +36,8 @@ struct TopicListCellView: View {
3636
3737 HStack ( ) {
3838 if let username = topic. member? . username {
39- Text ( username)
39+ Text ( " " )
40+ . linkName ( username)
4041
4142 Text ( " • " )
4243 }
You can’t perform that action at this time.
0 commit comments