Skip to content

Commit 98dc833

Browse files
committed
minor changes
1 parent 809aa94 commit 98dc833

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
V2exOS.xcodeproj/project.xcworkspace/xcuserdata/
2+
V2exOS.xcodeproj/xcuserdata/*.xcuserdatad/
3+
.python-version

V2exOS/Views/TopicDetail/TopicDetailView.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ struct TopicDetailView: View {
1717

1818
@State var commentList: [V2Comment]?
1919
@State var page = 0
20-
@State var commenEnd = false
20+
@State var commentEnd = false
2121
@State var isCommentLoading = false
2222

23-
func hasCommen() -> Bool {
24-
return currentUser.user != nil && (commenEnd || commentList?.count ?? 0 < topic.replies ?? 0)
23+
func hasMoreComments() -> Bool {
24+
return currentUser.user != nil && (commentEnd || commentList?.count ?? 0 < topic.replies ?? 0)
2525
}
2626

2727
var body: some View {
@@ -64,12 +64,16 @@ struct TopicDetailView: View {
6464

6565
CommentListView(commentCount: topic.replies, commentList: commentList)
6666

67-
if hasCommen() {
67+
if hasMoreComments() {
6868
Spacer()
69-
ProgressView()
70-
.onAppear {
71-
loadComments(page: page + 1)
72-
}
69+
HStack {
70+
Spacer()
71+
ProgressView()
72+
.onAppear {
73+
loadComments(page: page + 1)
74+
}
75+
Spacer()
76+
}
7377
}
7478
}
7579
.foregroundColor(Color(NSColor.labelColor))
@@ -92,20 +96,20 @@ struct TopicDetailView: View {
9296
commentList = res?.result
9397
}else{
9498
if let list = res?.result {
95-
if !hasCommen() {
99+
if !hasMoreComments() {
96100
isCommentLoading = false
97101
return
98102
}
99103

100104
commentList?.append(contentsOf: list)
101105
// 到底了
102106
if list.count == 0 {
103-
commenEnd = true
107+
commentEnd = true
104108
}
105109
}
106110
}
107111
} catch {
108-
commenEnd = true
112+
commentEnd = true
109113
print(error)
110114
}
111115

V2exOS/Views/TopicList/TopicListCellView.swift

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,49 @@ import V2exAPI
1010
import Kingfisher
1111

1212
struct TopicListCellView: View {
13+
@State var isMemberLoading = false
1314

1415
@Environment(\.colorScheme) var colorScheme
1516

1617
let topic : V2Topic
18+
@State var member : V2Member?
19+
20+
init(topic: V2Topic) {
21+
self.topic = topic
22+
self.isMemberLoading = topic.member == nil
23+
}
1724

1825
var body: some View {
1926
NavigationLink {
2027
TopicDetailView(topic: topic)
2128
} label: {
2229

2330
HStack {
24-
if let avatarUrl = topic.member?.avatarLarge {
25-
KFImage.url(URL(string: avatarUrl))
26-
.resizable()
27-
.fade(duration: 0.25)
28-
.scaledToFit()
29-
.frame(width: 48, height: 48)
30-
.mask(RoundedRectangle(cornerRadius: 8))
31+
32+
if !isMemberLoading {
33+
let user = topic.member ?? member
34+
if let avatarUrl = user?.avatarLarge {
35+
KFImage.url(URL(string: avatarUrl))
36+
.resizable()
37+
.fade(duration: 0.25)
38+
.scaledToFit()
39+
.frame(width: 48, height: 48)
40+
.mask(RoundedRectangle(cornerRadius: 8))
41+
}
3142
}
43+
3244
VStack(alignment: .leading, spacing: 6) {
3345

3446
Text(topic.title ?? "")
3547
.lineLimit(2)
3648

3749
HStack() {
38-
if let username = topic.member?.username {
50+
51+
if let username = topic.member?.username ?? topic.lastReplyBy {
3952
UserName(username)
40-
4153
Text("")
4254
}
4355

44-
4556
if let lastModified = topic.lastModified {
4657
Text(Date.init(timeIntervalSince1970: TimeInterval(lastModified)).fromNow())
4758
}
@@ -60,6 +71,12 @@ struct TopicListCellView: View {
6071

6172
}
6273
.foregroundColor(Color(NSColor.labelColor))
74+
.task {
75+
if let name = topic.lastReplyBy {
76+
member = try? await v2ex.memberShow(username: name)
77+
isMemberLoading = member == nil
78+
}
79+
}
6380
}
6481
}
6582
}

V2exOS/Views/TopicList/TopicListView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Kingfisher
1212
struct TopicListView: View {
1313

1414
var nodeName: String
15-
// var node: V2Node?
1615

1716
@State var isLoading = true
1817
@State var topics: [V2Topic]?
@@ -33,12 +32,16 @@ struct TopicListView: View {
3332
}
3433

3534
if topics.count > 0 && nodeName != "ALL" && nodeName != "HOT" {
36-
ProgressView()
37-
.onAppear {
38-
Task {
39-
await self.loadData(page: self.page + 1)
35+
HStack {
36+
Spacer()
37+
ProgressView()
38+
.onAppear {
39+
Task {
40+
await self.loadData(page: self.page + 1)
41+
}
4042
}
41-
}
43+
Spacer()
44+
}
4245
}
4346
}
4447

0 commit comments

Comments
 (0)