Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add developer menu to post model context menu and ellipsis menu. #927

Merged
merged 4 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Mlem/Models/Content/Post/PostModel+MenuFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,40 @@ extension PostModel {
}
}

#if DEBUG
functions.append(
buildDeveloperMenu(
editorTracker: editorTracker,
postTracker: postTracker
)
)
#endif

return functions
}
// swiftlint:enable function_body_length

#if DEBUG
private func buildDeveloperMenu(
editorTracker: EditorTracker,
postTracker: StandardPostTracker?
) -> MenuFunction {
MenuFunction.childMenu(
titleKey: "Developer Menu",
children: [
.standardMenuFunction(
text: "Toggle Read State",
imageName: "book.and.wrench",
enabled: true,
callback: {
Task {
let newState = !self.read
await self.markRead(newState)
}
}
)
]
)
}
#endif
}
6 changes: 6 additions & 0 deletions Mlem/Models/Menu Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ enum MenuFunction: Identifiable {
return shareImageFunction.id
case let .navigation(navigationMenuFunction):
return navigationMenuFunction.id
case .childMenu:
return UUID().uuidString
}
}

case standard(StandardMenuFunction)
case shareUrl(ShareMenuFunction)
case shareImage(ShareImageFunction)
case navigation(NavigationMenuFunction)
/// - Parameter titleKey: User-facing title label for menu.
/// - Parameter children: Menu items for this child menu.
/// - Note: Destructive confirmation is not supported at this time.
case childMenu(titleKey: String, children: [MenuFunction])
}

enum MenuFunctionRole {
Expand Down
6 changes: 6 additions & 0 deletions Mlem/Views/Shared/Components/Components/Menu Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ struct MenuButton: View {
NavigationLink(navigationMenuFunction.destination) {
Label(navigationMenuFunction.text, systemImage: navigationMenuFunction.imageName)
}
case let .childMenu(titleKey, children):
Menu(titleKey) {
ForEach(children) { child in
MenuButton(menuFunction: child, confirmDestructive: nil)
}
}
}
}
}
Loading