Skip to content

Commit

Permalink
feat: hide my replies and my posts
Browse files Browse the repository at this point in the history
  • Loading branch information
fsy2001 committed Dec 1, 2024
1 parent b8e6bcf commit 7c860f7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
2 changes: 2 additions & 0 deletions DanXiUI/Forum/Model/ForumSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class ForumSettings: ObservableObject {
@AppStorage("sensitive-content") public var foldedContent = SensitiveContentSetting.fold
@AppStorage("blocked-tags") public var blockedTags: [String] = []
@AppStorage("blocked-holes") public var blockedHoles: [Int] = []
@AppStorage("hidden-my-holes") public var hiddenMyHoles: [Int] = []
@AppStorage("hidden-my-replies") public var hiddenMyReplies: [Int] = []
@AppStorage("screenshot-alert") public var screenshotAlert = true
@AppStorage("show-activity") public var showBanners = true
@AppStorage("in-app-browser") var inAppBrowser = true
Expand Down
23 changes: 20 additions & 3 deletions DanXiUI/Forum/Pages/MyPostPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@ import ViewUtils
import DanXiKit

struct MyPostPage: View {
@ObservedObject private var settings = ForumSettings.shared

var body: some View {
ForumList {
AsyncCollection { (presentations: [HolePresentation]) in
let holes = try await ForumAPI.listMyHoles(startTime: presentations.last?.hole.timeUpdated)
return holes.map { HolePresentation(hole: $0) }
} content: { presentation in
Section {
HoleView(presentation: presentation)
.listRowInsets(EdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12))
if !settings.hiddenMyHoles.contains(presentation.hole.id) {
Section {
HoleView(presentation: presentation)
.listRowInsets(EdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12))
}
.swipeActions {
Button {
withAnimation {
settings.hiddenMyHoles.append(presentation.hole.id)
}
} label: {
Label {
Text("Hide", bundle: .module)
} icon: {
Image(systemName: "eye.slash")
}
}
}
}
}
}
Expand Down
35 changes: 26 additions & 9 deletions DanXiUI/Forum/Pages/MyReplyPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ import ViewUtils
import DanXiKit

struct MyReplyPage: View {
@ObservedObject private var settings = ForumSettings.shared

var body: some View {
ForumList {
AsyncCollection { floors in
try await ForumAPI.listMyFloors(offset: floors.count)
} content: { floor in
Section {
FoldedView(expand: !floor.deleted) {
Text("Deleted Floor", bundle: .module)
.foregroundStyle(.secondary)
.tint(.primary)
} content: {
DetailLink(value: HoleLoader(floor)) {
SimpleFloorView(floor: floor)
if !settings.hiddenMyReplies.contains(floor.id) {
Section {
FoldedView(expand: !floor.deleted) {
Text("Deleted Floor", bundle: .module)
.foregroundStyle(.secondary)
.tint(.primary)
} content: {
DetailLink(value: HoleLoader(floor)) {
SimpleFloorView(floor: floor)
}
}
.listRowInsets(EdgeInsets(top: 10, leading: 12, bottom: 10, trailing: 12))
.swipeActions {
Button {
withAnimation {
settings.hiddenMyReplies.append(floor.id)
}
} label: {
Label {
Text("Hide", bundle: .module)
} icon: {
Image(systemName: "eye.slash")
}
}
}
}
.listRowInsets(EdgeInsets(top: 10, leading: 12, bottom: 10, trailing: 12))
}
}
}
Expand Down
29 changes: 26 additions & 3 deletions DanXiUI/General/ForumSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,36 @@ fileprivate struct BlockedContent: View {
}
}
}

if settings.blockedHoles.isEmpty {
Text("You haven't blocked any holes. You can a block hole by pressing and holding it and select \"Block Hole\" in the menu.", bundle: .module)
}
} header: {
Text("Blocked Holes", bundle: .module)
}

if settings.blockedHoles.isEmpty {
Section(String(localized: "You haven't blocked any holes. You can a block hole by pressing and holding it and select \"Block Hole\" in the menu.", bundle: .module)) {}
.textCase(.none)
if settings.hiddenMyHoles.isEmpty {
Section {
Button {
settings.hiddenMyHoles = []
} label: {
Text("Restore Hidden Posts", bundle: .module)
}
} footer: {
Text("If you have hidden your posts in \"My Posts\" Page, you may restore them.", bundle: .module)
}
}

if !settings.hiddenMyReplies.isEmpty {
Section {
Button {
settings.hiddenMyReplies = []
} label: {
Text("Restore Hidden Replies", bundle: .module)
}
} footer: {
Text("If you have hidden your replies in \"My Reply\" Page, you may restore them.", bundle: .module)
}
}
}
.navigationTitle(String(localized: "Blocked Content", bundle: .module))
Expand Down

0 comments on commit 7c860f7

Please sign in to comment.