-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
216 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Mlem/App/Utility/Extensions/Content Models/PersonContent+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// PersonContent+Extensions.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 2024-10-31. | ||
// | ||
|
||
import MlemMiddleware | ||
|
||
extension PersonContent { | ||
var shouldHideInFeed: Bool { | ||
switch wrappedValue { | ||
case let .post(post): post.shouldHideInFeed | ||
case let .comment(comment): comment.shouldHideInFeed | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Mlem/App/Utility/Extensions/Content Models/PurgableProviding+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// PurgableProviding+Extensions.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 2024-10-27. | ||
// | ||
|
||
import Foundation | ||
import MlemMiddleware | ||
|
||
extension PurgableProviding { | ||
func showPurgeSheet() { | ||
NavigationModel.main.openSheet(.purge(self)) | ||
} | ||
|
||
func purgeAction() -> BasicAction { | ||
.init( | ||
id: "purge\(uid)", | ||
appearance: .purge(), | ||
callback: (api.canInteract && api.isAdmin) ? showPurgeSheet : nil | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// ContentPurgeEditorView.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 2024-10-26. | ||
// | ||
|
||
import MlemMiddleware | ||
import SwiftUI | ||
|
||
struct ContentPurgeEditorView: View { | ||
@Environment(AppState.self) var appState | ||
@Environment(Palette.self) var palette | ||
@Environment(\.dismiss) var dismiss | ||
|
||
let target: any PurgableProviding | ||
|
||
@State var community: (any Community)? | ||
@State var reason: String = "" | ||
@FocusState var reasonFocused: Bool | ||
@State var presentationSelection: PresentationDetent = .large | ||
|
||
init(target: any PurgableProviding) { | ||
self.target = target | ||
self._community = .init(wrappedValue: (target as? any Interactable2Providing)?.community) | ||
} | ||
|
||
var body: some View { | ||
CollapsibleSheetView(presentationSelection: $presentationSelection, canDismiss: reason.isEmpty) { | ||
NavigationStack { | ||
Form { | ||
Section { | ||
WarningView( | ||
iconName: Icons.purge, | ||
text: "Purged content is erased from the database and cannot be restored.", | ||
inList: true | ||
) | ||
} | ||
Section { | ||
TextField("Reason (Optional)", text: $reason, axis: .vertical) | ||
.focused($reasonFocused) | ||
} | ||
ReasonPickerView(reason: $reason, community: community) | ||
} | ||
.scrollDismissesKeyboard(.interactively) | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationTitle("Purge") | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
Button("Cancel") { dismiss() } | ||
} | ||
ToolbarItem(placement: .topBarTrailing) { | ||
Button("Send", systemImage: Icons.send) { | ||
Task { | ||
await send() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.onAppear { reasonFocused = true } | ||
} | ||
} | ||
|
||
func send() async { | ||
do { | ||
try await target.purge(reason: reason.isEmpty ? nil : reason) | ||
HapticManager.main.play(haptic: .success, priority: .low) | ||
dismiss() | ||
} catch { | ||
handleError(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.