@@ -13,27 +13,142 @@ struct EditDeveloper: View {
13
13
@State var vm : UserVM
14
14
@State private var tabSelct = 1
15
15
16
+ @State var vmRepo : RepoVM
17
+ @State private var tabSelctRepo = 1
18
+
19
+
16
20
var body : some View {
17
21
Form {
18
22
HStack {
19
- TextField ( " 用户名: " , text: $dev. name, prompt: Text ( " 输入 Github 用户名 " ) )
20
- . onSubmit {
21
- vm = UserVM ( userName: dev. name)
22
- vm. doing ( . updateAll)
23
+ TextField ( " 用户名: " , text: $dev. name, prompt: Text ( " 输入 Github 用户名 dev 或仓库名 dev/repo " ) )
24
+ . onChange ( of: dev. name) { oldValue, newValue in
25
+ let dn = dev. name. components ( separatedBy: " / " )
26
+ if dn. count > 1 {
27
+ vmRepo = RepoVM ( repoName: dev. name)
28
+ vmRepo. doing ( . inInit)
29
+ dev. repoName = dn. last ?? " "
30
+ dev. repoOwner = dn. first ?? " "
31
+ } else {
32
+ vm = UserVM ( userName: dev. name)
33
+ vm. doing ( . updateAll)
34
+ dev. repoName = " "
35
+ dev. repoOwner = " "
36
+ }
23
37
}
24
38
TextField ( " 描述: " , text: $dev. des)
25
39
}
26
40
}
27
41
. padding ( EdgeInsets ( top: 10 , leading: 10 , bottom: 0 , trailing: 10 ) )
28
42
43
+ if dev. name. components ( separatedBy: " / " ) . count > 1 {
44
+ repoEventView ( )
45
+ } else {
46
+ devEventView ( )
47
+ }
48
+ }
49
+
50
+ @ViewBuilder
51
+ func repoEventView( ) -> some View {
52
+ HStack {
53
+ VStack ( alignment: . leading, spacing: 10 ) {
54
+ HStack {
55
+ Text ( vmRepo. repo. name) . font ( . system( . largeTitle) )
56
+ Text ( " ( \( vmRepo. repo. fullName) ) " )
57
+ }
58
+ HStack {
59
+ Image ( systemName: " star.fill " ) . foregroundColor ( . red)
60
+ Text ( " \( vmRepo. repo. stargazersCount) " )
61
+ Image ( systemName: " tuningfork " ) . foregroundColor ( . cyan)
62
+ Text ( " \( vmRepo. repo. forks) " )
63
+ Text ( " 议题 \( vmRepo. repo. openIssues) " )
64
+ Text ( " 语言 \( vmRepo. repo. language ?? " " ) " )
65
+ ButtonGoGitHubWeb ( url: vmRepo. repo. htmlUrl ?? " https://github.com " , text: " 在 GitHub 上访问 " )
66
+
67
+ }
68
+ if vmRepo. repo. description != nil {
69
+ Text ( " 简介: \( vmRepo. repo. description ?? " " ) " )
70
+ }
71
+
72
+ HStack {
73
+ Text ( " 作者: " )
74
+ AsyncImageWithPlaceholder ( size: . smallSize, url: vmRepo. repo. owner. avatarUrl)
75
+ ButtonGoGitHubWeb ( url: vmRepo. repo. owner. login, text: vmRepo. repo. owner. login, ignoreHost: true )
76
+ }
77
+ } // end VStack
78
+ Spacer ( )
79
+ }
80
+ . frame ( minWidth: SPC . detailMinWidth)
81
+ . onChange ( of: vmRepo. repo, { oldValue, newValue in
82
+ if !newValue. owner. avatarUrl. isEmpty {
83
+ dev. avatar = newValue. owner. avatarUrl
84
+ }
85
+ } )
86
+ . onChange ( of: vmRepo. commits, { oldValue, newValue in
87
+ if ( ( newValue. first? . commit. author. date. isEmpty) != nil ) {
88
+ let iso8601String = newValue. first? . commit. author. date ?? " "
89
+ let formatter = ISO8601DateFormatter ( )
90
+ dev. updateDate = formatter. date ( from: iso8601String) ?? Date . now
91
+ }
92
+ } )
93
+ . padding ( EdgeInsets ( top: 20 , leading: 10 , bottom: 0 , trailing: 10 ) )
94
+ . onAppear {
95
+ vmRepo. doing ( . inInit)
96
+ }
97
+ // end HStack
98
+
99
+ TabView ( selection: $tabSelct) {
100
+ RepoCommitsView ( commits: vmRepo. commits, repo: vmRepo. repo)
101
+ . tabItem {
102
+ Text ( " 新提交 " )
103
+ }
104
+ . onAppear {
105
+ vmRepo. doing ( . inCommit)
106
+ }
107
+ . tag ( 1 )
108
+
109
+ IssuesView ( issues: vmRepo. issues, repo: vmRepo. repo)
110
+ . tabItem {
111
+ Text ( " 议题列表 " )
112
+ }
113
+ . onAppear {
114
+ vmRepo. doing ( . inIssues)
115
+ }
116
+ . tag ( 2 )
117
+
118
+ IssueEventsView ( issueEvents: vmRepo. issueEvents, repo: vmRepo. repo)
119
+ . tabItem {
120
+ Text ( " 议题事件 " )
121
+ }
122
+ . onAppear {
123
+ vmRepo. doing ( . inIssueEvents)
124
+ }
125
+ . tag ( 3 )
126
+
127
+ ReadmeView ( content: vmRepo. readme. content. replacingOccurrences ( of: " \n " , with: " " ) )
128
+ . tabItem {
129
+ Text ( " README " )
130
+ }
131
+ . onAppear {
132
+ vmRepo. doing ( . inReadme)
133
+ }
134
+ . tag ( 4 )
135
+
136
+ } // end TabView
137
+ Spacer ( )
138
+ }
139
+
140
+ @ViewBuilder
141
+ func devEventView( ) -> some View {
29
142
HStack {
30
143
VStack ( alignment: . leading, spacing: 10 ) {
31
144
HStack {
32
145
AsyncImageWithPlaceholder ( size: . normalSize, url: vm. user. avatarUrl)
33
146
VStack ( alignment: . leading, spacing: 5 ) {
34
147
HStack {
35
148
Text ( vm. user. name ?? vm. user. login) . font ( . system( . title) )
36
- Text ( " ( \( vm. user. login) ) " )
149
+ if !vm. user. login. isEmpty {
150
+ Text ( " ( \( vm. user. login) ) " )
151
+ }
37
152
Text ( " 订阅者 \( vm. user. followers) 人,仓库 \( vm. user. publicRepos) 个 " )
38
153
}
39
154
HStack {
@@ -97,6 +212,7 @@ struct EditDeveloper: View {
97
212
vm. doing ( . inEvent)
98
213
}
99
214
. tag ( 1 )
215
+
100
216
DeveloperEventView ( events: vm. receivedEvents)
101
217
. tabItem {
102
218
Image ( systemName: " keyboard.badge.ellipsis " )
0 commit comments