Skip to content

Commit e04c8d8

Browse files
authored
fix flag button. (#79)
1 parent 8d92439 commit e04c8d8

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

Shared/Models/Stores/ItemStore.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ extension ItemView {
1111
@Published var item: (any Item)?
1212
@Published var loadingItemId: Int?
1313
@Published var actionPerformed: Action = .none
14-
@Published var showFlagDialog: Bool = .init()
15-
1614

1715
/// Stores ids of loaded comments, including both root and child comments.
1816
@Published var loadedCommentIds: Set<Int> = .init()

Shared/Views/Components/CommentTile.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ extension ItemView {
1313
let onLoadMore: () -> Void
1414
let onShowHNSheet: () -> Void
1515
let onShowReplySheet: () -> Void
16-
16+
let onFlag: () -> Void
17+
1718
init(comment: Comment,
1819
itemStore: ItemStore,
1920
onShowHNSheet: @escaping () -> Void,
2021
onShowReplySheet: @escaping () -> Void,
21-
onLoadMore: @escaping () -> Void) {
22+
onLoadMore: @escaping () -> Void,
23+
onFlag: @escaping () -> Void) {
2224
self.level = comment.level ?? 0
2325
self.comment = comment
2426
self.onShowHNSheet = onShowHNSheet
2527
self.onShowReplySheet = onShowReplySheet
2628
self.onLoadMore = onLoadMore
29+
self.onFlag = onFlag
2730
self.itemStore = itemStore
2831
}
2932

@@ -50,13 +53,6 @@ extension ItemView {
5053

5154
return AnyView(wrappedView)
5255
}
53-
.confirmationDialog("Are you sure?", isPresented: $itemStore.showFlagDialog) {
54-
Button("Flag", role: .destructive) {
55-
onFlagTap()
56-
}
57-
} message: {
58-
Text("Flag the post by \(comment.by.orEmpty)?")
59-
}
6056
}
6157
}
6258

@@ -132,7 +128,12 @@ extension ItemView {
132128
}
133129
.disabled(!auth.loggedIn)
134130
Divider()
135-
FlagButton(id: comment.id, showFlagDialog: $itemStore.showFlagDialog)
131+
Button {
132+
onFlag()
133+
} label: {
134+
Label("Flag", systemImage: "flag")
135+
}
136+
.disabled(!auth.loggedIn)
136137
Divider()
137138
ShareMenu(item: comment)
138139
CopyButton(text: comment.text.orEmpty, actionPerformed: $itemStore.actionPerformed)

Shared/Views/ItemView.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ struct ItemView: View {
99
@State private var showUrlSheet: Bool = .init()
1010
@State private var showReplySheet: Bool = .init()
1111
@State private var showFlagDialog: Bool = .init()
12+
@State private var flaggingItem: (any Item)?
1213
static private var handledUrl: URL? = nil
1314
static private var hnSheetTarget: (any Item)? = nil
1415
static private var replySheetTarget: (any Item)? = nil
15-
16+
1617
let settings: Settings = .shared
1718

1819
let level: Int
@@ -67,10 +68,10 @@ struct ItemView: View {
6768
}
6869
.confirmationDialog("Are you sure?", isPresented: $showFlagDialog) {
6970
Button("Flag", role: .destructive) {
70-
onFlagTap()
71+
flag()
7172
}
7273
} message: {
73-
Text("Flag the post by \(item.by.orEmpty)?")
74+
Text("Flag the post by \(flaggingItem?.by.orEmpty ?? item.by.orEmpty)?")
7475
}
7576
.task {
7677
if itemStore.item == nil {
@@ -168,6 +169,9 @@ struct ItemView: View {
168169
Task {
169170
await itemStore.loadKids(of: comment)
170171
}
172+
} onFlag: {
173+
flaggingItem = comment
174+
showFlagDialog = true
171175
}
172176
.padding(.trailing, 4)
173177
}
@@ -287,9 +291,10 @@ struct ItemView: View {
287291
}
288292
}
289293

290-
private func onFlagTap() {
294+
private func flag() {
295+
let id = flaggingItem?.id ?? item.id
291296
Task {
292-
let res = await auth.flag(item.id)
297+
let res = await auth.flag(id)
293298

294299
if res {
295300
itemStore.actionPerformed = .flag

ZCombinator.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@
10871087
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
10881088
CODE_SIGN_ENTITLEMENTS = "ZCombinator (iOS).entitlements";
10891089
CODE_SIGN_STYLE = Automatic;
1090-
CURRENT_PROJECT_VERSION = 4;
1090+
CURRENT_PROJECT_VERSION = 5;
10911091
DEVELOPMENT_TEAM = QMWX3X2NF7;
10921092
ENABLE_PREVIEWS = YES;
10931093
GENERATE_INFOPLIST_FILE = YES;
@@ -1125,7 +1125,7 @@
11251125
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
11261126
CODE_SIGN_ENTITLEMENTS = "ZCombinator (iOS).entitlements";
11271127
CODE_SIGN_STYLE = Automatic;
1128-
CURRENT_PROJECT_VERSION = 4;
1128+
CURRENT_PROJECT_VERSION = 5;
11291129
DEVELOPMENT_TEAM = QMWX3X2NF7;
11301130
ENABLE_PREVIEWS = YES;
11311131
GENERATE_INFOPLIST_FILE = YES;

0 commit comments

Comments
 (0)