Skip to content

Commit 662910b

Browse files
authored
Merge pull request #12 from MoonlightSmile/main
feat: 抽象用户名,点击可跳转用户主页
2 parents 13c29cf + 51bec5f commit 662910b

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

V2exOS/Modifier/UserName.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

V2exOS/Views/TopicDetail/CommentListView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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 {

V2exOS/Views/TopicList/TopicListCellView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)