Skip to content

Commit f1177db

Browse files
committed
feat: Comment list supports user badge display (MOD/OP)
1 parent 2fe0725 commit f1177db

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed

V2exOS.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
0DA8383A2A9DD3E900C8DA47 /* SwiftUIIntrospect in Frameworks */ = {isa = PBXBuildFile; productRef = 0DA838392A9DD3E900C8DA47 /* SwiftUIIntrospect */; };
7575
0DD2A4DD2987C57B0018C2CF /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DD2A4DC2987C57B0018C2CF /* Constants.swift */; };
7676
0DD2A4DE2987C57B0018C2CF /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DD2A4DC2987C57B0018C2CF /* Constants.swift */; };
77+
0DEFFCB22A9EDB5100A1585B /* CommentUserTagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEFFCB12A9EDB5100A1585B /* CommentUserTagView.swift */; };
78+
0DEFFCB32A9EDB5100A1585B /* CommentUserTagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEFFCB12A9EDB5100A1585B /* CommentUserTagView.swift */; };
79+
0DEFFCB42A9EDB5100A1585B /* CommentUserTagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEFFCB12A9EDB5100A1585B /* CommentUserTagView.swift */; };
7780
0DF3300E28A55DEA00AEF312 /* InboxListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DF3300D28A55DEA00AEF312 /* InboxListView.swift */; };
7881
0DF3301028A56A3600AEF312 /* StringExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DF3300F28A56A3600AEF312 /* StringExt.swift */; };
7982
/* End PBXBuildFile section */
@@ -116,6 +119,7 @@
116119
0DA7FA7929879BD300374B3A /* TopicListCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopicListCellView.swift; sourceTree = "<group>"; };
117120
0DA7FA7C29879D3300374B3A /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
118121
0DD2A4DC2987C57B0018C2CF /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
122+
0DEFFCB12A9EDB5100A1585B /* CommentUserTagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentUserTagView.swift; sourceTree = "<group>"; };
119123
0DF3300D28A55DEA00AEF312 /* InboxListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxListView.swift; sourceTree = "<group>"; };
120124
0DF3300F28A56A3600AEF312 /* StringExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExt.swift; sourceTree = "<group>"; };
121125
/* End PBXFileReference section */
@@ -320,6 +324,7 @@
320324
children = (
321325
0D033B41288D15CF00129C9B /* TopicDetailView.swift */,
322326
0D8A2E6E2896AB49001B2769 /* CommentListView.swift */,
327+
0DEFFCB12A9EDB5100A1585B /* CommentUserTagView.swift */,
323328
);
324329
path = TopicDetail;
325330
sourceTree = "<group>";
@@ -504,6 +509,7 @@
504509
0D34DF8F2942FED1000A0096 /* AppearanceConfig.swift in Sources */,
505510
0D033B26288CD64500129C9B /* V2exOSApp.swift in Sources */,
506511
0D139DE228E7E06C00E4CF88 /* UserName.swift in Sources */,
512+
0DEFFCB22A9EDB5100A1585B /* CommentUserTagView.swift in Sources */,
507513
0D033B3E288D0FF700129C9B /* SidebarView.swift in Sources */,
508514
0DF3300E28A55DEA00AEF312 /* InboxListView.swift in Sources */,
509515
0D40378E28E6E4F500B1A341 /* ProxyHelper.swift in Sources */,
@@ -530,6 +536,7 @@
530536
0D5555FC2997C1C500A8B9FD /* CurrentUserStore.swift in Sources */,
531537
0D2334F129969A6B00DF4B73 /* PreviewData.swift in Sources */,
532538
0D2334D12996944500DF4B73 /* V2exOSiOSApp.swift in Sources */,
539+
0DEFFCB42A9EDB5100A1585B /* CommentUserTagView.swift in Sources */,
533540
0D2334EC299699B000DF4B73 /* AppearanceConfig.swift in Sources */,
534541
0D7EF06F299736C800E77A0C /* NodeListView.swift in Sources */,
535542
0D2334E42996997000DF4B73 /* TopicListCellView.swift in Sources */,
@@ -547,6 +554,7 @@
547554
0DA7FA862987A76B00374B3A /* UserName.swift in Sources */,
548555
0DA7FA67298799B300374B3A /* V2exOSTVApp.swift in Sources */,
549556
0DA7FA822987A6DB00374B3A /* CommentListView.swift in Sources */,
557+
0DEFFCB32A9EDB5100A1585B /* CommentUserTagView.swift in Sources */,
550558
0D5555FA2997B6B100A8B9FD /* ViewExt.swift in Sources */,
551559
0DA7FA7B29879CA500374B3A /* TimeFormat.swift in Sources */,
552560
0DA7FA872987A8C800374B3A /* TopicDetailView.swift in Sources */,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0.880",
9+
"green" : "0.651",
10+
"red" : "0.444"
11+
}
12+
},
13+
"idiom" : "universal"
14+
}
15+
],
16+
"info" : {
17+
"author" : "xcode",
18+
"version" : 1
19+
}
20+
}

V2exOS/Utils/ViewExt.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import SwiftUI
99
import SwiftUIIntrospect
1010

1111
extension View {
12+
13+
/// Applies the given transform if the given condition evaluates to `true`.
14+
/// - Parameters:
15+
/// - condition: The condition to evaluate.
16+
/// - transform: The transform to apply to the source `View`.
17+
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`.
18+
@ViewBuilder func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
19+
if condition() {
20+
transform(self)
21+
} else {
22+
self
23+
}
24+
}
25+
1226
/// Perform an action when the view is first appear
1327
func onFirstAppear(perform: @escaping () -> Void) -> some View {
1428
modifier(OnFirstAppear(perform: perform))

V2exOS/Views/TopicDetail/CommentListView.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct CommentListView: View {
1515

1616
var commentCount: Int?
1717
var commentList: [V2Comment]?
18+
var topic: V2Topic
1819

1920
var body: some View {
2021
VStack(alignment: .leading) {
@@ -56,6 +57,14 @@ struct CommentListView: View {
5657
if let username = comment.member.username {
5758
UserName(username)
5859
}
60+
61+
if comment.member.id == 1 {
62+
CommentUserTagView(.mod)
63+
}
64+
65+
if comment.member.id == topic.member?.id {
66+
CommentUserTagView(.op)
67+
}
5968

6069
Text(Date(timeIntervalSince1970: TimeInterval(comment.created)).fromNow())
6170

@@ -90,7 +99,7 @@ struct CommentListView_Previews: PreviewProvider {
9099
PreviewData.comment,
91100
PreviewData.comment
92101
]
93-
CommentListView(commentList: commentList)
102+
CommentListView(commentList: commentList, topic: V2Topic(id: 1))
94103
.previewLayout(.fixed(width: 400, height: 200))
95104
}
96105
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// CommentUserTagView.swift
3+
// V2exOS
4+
//
5+
// Created by isaced on 2023/8/30.
6+
//
7+
8+
import SwiftUI
9+
10+
enum CommentUserTagType {
11+
case op
12+
case mod
13+
}
14+
15+
struct CommentUserTagView: View {
16+
var type: CommentUserTagType
17+
18+
init(_ type: CommentUserTagType) {
19+
self.type = type
20+
}
21+
22+
let CornerRadius = 4.0
23+
24+
var body: some View {
25+
Text(type == .mod ? "MOD" : "OP")
26+
.padding(.vertical, 1)
27+
.padding(.horizontal, 6)
28+
.if(type == .op) { v in
29+
v.background(Color("UserTagModBackgroundColor").opacity(0.2))
30+
.foregroundColor(Color("UserTagModBackgroundColor"))
31+
.overlay( /// apply a rounded border
32+
RoundedRectangle(cornerRadius: CornerRadius)
33+
.stroke(.blue, lineWidth: 1)
34+
)
35+
36+
}
37+
.if(type == .mod) { v in
38+
v.background(Color("UserTagModBackgroundColor"))
39+
.foregroundColor(.white)
40+
}
41+
.cornerRadius(CornerRadius)
42+
}
43+
}
44+
45+
struct CommentUserTagView_Previews: PreviewProvider {
46+
static var previews: some View {
47+
CommentUserTagView(.mod)
48+
}
49+
}

V2exOS/Views/TopicDetail/TopicDetailView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ struct TopicDetailView: View {
7777
#endif
7878
Spacer()
7979

80-
CommentListView(commentCount: topic.replies, commentList: commentList)
80+
CommentListView(commentCount: topic.replies, commentList: commentList, topic: topic)
81+
.font(.system(size: settingsConfig.fontSize - 2))
8182

8283
if isCommentLoading {
8384
HStack {

0 commit comments

Comments
 (0)