summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-03-15 20:37:05 -0700
committerFuwn <[email protected]>2025-03-15 20:37:05 -0700
commit8eae995c5bf475b2e40a807dbdf8927dbd993222 (patch)
tree9d89f0e2c3f5f856429312cebd1cde9bb107cc55
parentfeat: Development commit (diff)
downloadsora-testing-8eae995c5bf475b2e40a807dbdf8927dbd993222.tar.xz
sora-testing-8eae995c5bf475b2e40a807dbdf8927dbd993222.zip
feat: Development commit
-rw-r--r--Sora/Views/PlatformSpecificToolbarItem.swift21
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift93
2 files changed, 46 insertions, 68 deletions
diff --git a/Sora/Views/PlatformSpecificToolbarItem.swift b/Sora/Views/PlatformSpecificToolbarItem.swift
new file mode 100644
index 0000000..7c2fb86
--- /dev/null
+++ b/Sora/Views/PlatformSpecificToolbarItem.swift
@@ -0,0 +1,21 @@
+import SwiftUI
+
+struct PlatformSpecificToolbarItem<Content: View>: ToolbarContent {
+ let content: () -> Content
+
+ init(@ViewBuilder content: @escaping () -> Content) {
+ self.content = content
+ }
+
+ var body: some ToolbarContent {
+ #if os(macOS)
+ ToolbarItem {
+ content()
+ }
+ #else
+ ToolbarItem(placement: .bottomBar) {
+ content()
+ }
+ #endif
+ }
+}
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index ebf262b..21605e6 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -63,38 +63,14 @@ struct PostGridView: View {
}
#endif
- #if os(macOS)
- ToolbarItem {
- Button(action: { Task { manager.loadNextPage() } }) {
- Label(
- "Manually Load Next Page",
- systemImage: "arrow.down.to.line"
- )
- }
- .disabled(manager.isLoading)
- }
- #else
+ #if !os(macOS)
ToolbarItem(placement: .bottomBar) {
Button(action: { Task { isSearchHistoryPresented.toggle() } }) {
Label("Search History", systemImage: "clock.arrow.circlepath")
}
}
- ToolbarItem(placement: .bottomBar) {
- Button(action: { Task { manager.loadNextPage() } }) {
- Label(
- "Manually Load Next Page",
- systemImage: "arrow.down.to.line"
- )
- }
- .disabled(manager.isLoading)
- }
-
- if manager.isLoading {
- ToolbarItem {
- ProgressView()
- }
- }
+ if manager.isLoading { ToolbarItem { ProgressView() } }
#if DEBUG
if manager.historyIndex < manager.searchHistory.count {
@@ -105,52 +81,33 @@ struct PostGridView: View {
#endif
#endif
- if !manager.tags.isEmpty {
- #if os(macOS)
- ToolbarItem { PostGridBookmarkButtonView() }
- #else
- ToolbarItem(placement: .bottomBar) { PostGridBookmarkButtonView() }
- #endif
+ PlatformSpecificToolbarItem {
+ Button(action: { Task { manager.loadNextPage() } }) {
+ Label(
+ "Manually Load Next Page",
+ systemImage: "arrow.down.to.line"
+ )
+ }
+ .disabled(manager.isLoading)
}
- if manager.historyIndex > 0 {
- #if os(macOS)
- ToolbarItem {
- Button(action: {
- manager.goBackInHistory()
- }) {
- Label("Previous Search", systemImage: "chevron.left")
- }
- }
- #else
- ToolbarItem(placement: .bottomBar) {
- Button(action: {
- manager.goBackInHistory()
- }) {
- Label("Previous Search", systemImage: "chevron.left")
- }
- }
- #endif
+ PlatformSpecificToolbarItem {
+ PostGridBookmarkButtonView()
+ .disabled(manager.tags.isEmpty)
}
- if manager.historyIndex < manager.searchHistory.count - 1 {
- #if os(macOS)
- ToolbarItem {
- Button(action: {
- manager.goForwardInHistory()
- }) {
- Label("Next Search", systemImage: "chevron.right")
- }
- }
- #else
- ToolbarItem(placement: .bottomBar) {
- Button(action: {
- manager.goForwardInHistory()
- }) {
- Label("Next Search", systemImage: "chevron.right")
- }
- }
- #endif
+ PlatformSpecificToolbarItem {
+ Button(action: { manager.goBackInHistory() }) {
+ Label("Previous Search", systemImage: "chevron.left")
+ }
+ .disabled(!(manager.historyIndex > 0))
+ }
+
+ PlatformSpecificToolbarItem {
+ Button(action: { manager.goForwardInHistory() }) {
+ Label("Next Search", systemImage: "chevron.right")
+ }
+ .disabled(!(manager.historyIndex < manager.searchHistory.count - 1))
}
}
.navigationTitle("Posts")