summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-02-21 01:53:31 -0800
committerFuwn <[email protected]>2025-02-21 01:53:35 -0800
commit617370e834db97c2c6ce5c5bbd3825fcad013b7f (patch)
tree8d20d45c0cb1169d8c08509e106d0d57b0d71c72
parentfeat: Development commit (diff)
downloadsora-testing-617370e834db97c2c6ce5c5bbd3825fcad013b7f.tar.xz
sora-testing-617370e834db97c2c6ce5c5bbd3825fcad013b7f.zip
feat: Development commit
-rw-r--r--Sora/Data/Booru/BooruProvider.swift9
-rw-r--r--Sora/Data/Settings/Settings.swift12
-rw-r--r--Sora/Views/Bookmarks/BookmarkListItemView.swift39
-rw-r--r--Sora/Views/Bookmarks/BookmarksView.swift69
-rw-r--r--Sora/Views/BookmarksView.swift72
-rw-r--r--Sora/Views/ContentView.swift25
-rw-r--r--Sora/Views/Settings/SettingsProviderView.swift (renamed from Sora/Views/Settings/SettingsSourceView.swift)6
-rw-r--r--Sora/Views/SettingsView.swift4
8 files changed, 154 insertions, 82 deletions
diff --git a/Sora/Data/Booru/BooruProvider.swift b/Sora/Data/Booru/BooruProvider.swift
index e742fef..3b3b126 100644
--- a/Sora/Data/Booru/BooruProvider.swift
+++ b/Sora/Data/Booru/BooruProvider.swift
@@ -1,4 +1,13 @@
enum BooruProvider: String, CaseIterable, Decodable, Encodable {
case yandere
case safebooru
+
+ func formatted() -> String {
+ switch self {
+ case .yandere:
+ return "yande.re"
+ case .safebooru:
+ return "Safebooru"
+ }
+ }
}
diff --git a/Sora/Data/Settings/Settings.swift b/Sora/Data/Settings/Settings.swift
index 3ffa114..c70f1ba 100644
--- a/Sora/Data/Settings/Settings.swift
+++ b/Sora/Data/Settings/Settings.swift
@@ -4,7 +4,7 @@ class Settings: ObservableObject {
#if DEBUG
@AppStorage("detailViewType") var detailViewType: BooruPostFileType = .sample
#else
- @AppStorage("detailViewType") var detailViewType: PostFileType = .original
+ @AppStorage("detailViewType") var detailViewType: BooruPostFileType = .original
#endif
@AppStorage("thumbnailType") var thumbnailType: BooruPostFileType = .preview
@AppStorage("searchSuggestions") var searchSuggestions: Bool = false
@@ -68,4 +68,14 @@ class Settings: ObservableObject {
bookmarks = currentBookmarks
}
+
+ func removeBookmark(withID: UUID) {
+ var currentBookmarks = bookmarks
+
+ currentBookmarks.removeAll { bookmark in
+ bookmark.id == withID
+ }
+
+ bookmarks = currentBookmarks
+ }
}
diff --git a/Sora/Views/Bookmarks/BookmarkListItemView.swift b/Sora/Views/Bookmarks/BookmarkListItemView.swift
new file mode 100644
index 0000000..6d62893
--- /dev/null
+++ b/Sora/Views/Bookmarks/BookmarkListItemView.swift
@@ -0,0 +1,39 @@
+import SwiftUI
+
+struct BookmarkListItemView: View {
+ @EnvironmentObject var settings: Settings
+ var bookmark: Bookmark
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ HStack {
+ Text(bookmark.tags.joined(separator: ", "))
+
+ #if os(macOS)
+ Spacer()
+
+ Button {
+ settings.removeBookmark(withID: bookmark.id)
+ } label: {
+ Image(systemName: "trash")
+ }
+ #endif
+ }
+
+ HStack {
+ Text(bookmark.createdAt, style: .date)
+ .font(.caption)
+ .foregroundStyle(Color.secondary)
+
+ Spacer()
+
+ Text(bookmark.provider.formatted())
+ .font(.caption)
+ .foregroundStyle(Color.secondary)
+ }
+ }
+ #if os(macOS)
+ .padding()
+ #endif
+ }
+}
diff --git a/Sora/Views/Bookmarks/BookmarksView.swift b/Sora/Views/Bookmarks/BookmarksView.swift
new file mode 100644
index 0000000..9a0ef75
--- /dev/null
+++ b/Sora/Views/Bookmarks/BookmarksView.swift
@@ -0,0 +1,69 @@
+import SwiftUI
+
+struct BookmarksView: View {
+ @EnvironmentObject var settings: Settings
+ @EnvironmentObject var manager: BooruManager
+ @Binding var selectedTab: Int
+ @State private var bookmarksSearchText: String = ""
+
+ var filteredBookmarks: [Bookmark] {
+ guard !bookmarksSearchText.isEmpty else {
+ return settings.bookmarks
+ }
+
+ return settings.bookmarks
+ .filter { $0.tags.joined(separator: " ").lowercased().contains(bookmarksSearchText.lowercased()) }
+ }
+
+ var body: some View {
+ NavigationStack {
+ VStack {
+ if settings.bookmarks.isEmpty {
+ ContentUnavailableView("No Bookmarks",
+ systemImage: "bookmark",
+ description: Text("Add a bookmark by tapping the bookmark button on a search page."))
+ } else {
+ List {
+ if filteredBookmarks.isEmpty && !bookmarksSearchText.isEmpty {
+ Text("No bookmarks match your search")
+ }
+
+ ForEach(
+ filteredBookmarks,
+ id: \.self
+ ) { bookmark in
+ Button(action: {
+ let previousProvider = settings.preferredBooru
+
+ settings.preferredBooru = bookmark.provider
+ manager.searchText = bookmark.tags.joined(separator: " ")
+ selectedTab = 0
+
+ if previousProvider == settings.preferredBooru {
+ manager.performSearch()
+ }
+ }) {
+ BookmarkListItemView(bookmark: bookmark)
+ }
+ #if os(macOS)
+ .buttonStyle(.plain)
+ #endif
+ }
+ .onDelete(perform: settings.removeBookmark)
+ }
+ #if os(macOS)
+ .listStyle(.plain)
+ #endif
+ }
+ }
+ }
+ .navigationTitle("Bookmarks")
+ .searchable(text: $bookmarksSearchText)
+ }
+}
+
+#Preview {
+ BookmarksView(selectedTab: .constant(1))
+ .environmentObject(Settings())
+ .environmentObject(BooruManager(.yandere))
+}
diff --git a/Sora/Views/BookmarksView.swift b/Sora/Views/BookmarksView.swift
deleted file mode 100644
index 7c206ac..0000000
--- a/Sora/Views/BookmarksView.swift
+++ /dev/null
@@ -1,72 +0,0 @@
-import SwiftUI
-
-struct BookmarksView: View {
- @EnvironmentObject var settings: Settings
- @EnvironmentObject var manager: BooruManager
- @Binding var selectedTab: Int
- @State private var bookmarksSearchText: String = ""
-
- var filteredBookmarks: [Bookmark] {
- guard !bookmarksSearchText.isEmpty else {
- return settings.bookmarks
- }
-
- return settings.bookmarks
- .filter { $0.tags.joined(separator: " ").lowercased().contains(bookmarksSearchText.lowercased()) }
- }
-
- var body: some View {
- NavigationStack {
- if settings.bookmarks.isEmpty {
- VStack {
- Spacer()
-
- Text("There are no bookmarks yet. Add a bookmark by tapping the bookmark button in the bottom left corner of a search page.")
- .padding()
-
- Spacer()
- }
- } else {
- List {
- if filteredBookmarks.isEmpty {
- Text("No bookmarks found.")
- }
-
- ForEach(filteredBookmarks, id: \.self) { bookmark in
- Button(action: {
- let previousProvider = settings.preferredBooru
-
- settings.preferredBooru = bookmark.provider
- manager.searchText = bookmark.tags.joined(separator: " ")
- selectedTab = 0
-
- if previousProvider == settings.preferredBooru {
- manager.performSearch()
- }
- }) {
- let badgeView = Text(bookmark.provider.rawValue.capitalized)
-
- HStack {
- Text(bookmark.tags.joined(separator: ", "))
- .foregroundStyle(.primary)
-
- Text(bookmark.createdAt.formatted())
- .foregroundColor(.secondary)
- }
- .badge(badgeView)
- }
- }
- .onDelete(perform: settings.removeBookmark)
- }
- }
- }
- .navigationTitle("Bookmarks")
- .searchable(text: $bookmarksSearchText)
- }
-}
-
-#Preview {
- BookmarksView(selectedTab: .constant(1))
- .environmentObject(Settings())
- .environmentObject(BooruManager(.yandere))
-}
diff --git a/Sora/Views/ContentView.swift b/Sora/Views/ContentView.swift
index 5878619..d6473ab 100644
--- a/Sora/Views/ContentView.swift
+++ b/Sora/Views/ContentView.swift
@@ -2,18 +2,35 @@ import SwiftUI
struct ContentView: View {
@EnvironmentObject var manager: BooruManager
+ @State private var selectedTabIndex: Int = 1
+ @State private var tabs = [
+ "Posts",
+ "Bookmarks",
+ ]
var body: some View {
#if os(macOS)
NavigationSplitView {
- PostGridView(
- manager: manager
- )
+ List(selection: $selectedTabIndex) {
+ ForEach(Array(tabs.enumerated()), id: \.offset) { index, element in
+ NavigationLink(value: index) {
+ Text(element)
+ }
+ }
+ }
+ } content: {
+ if selectedTabIndex == 1 {
+ BookmarksView(selectedTab: $selectedTabIndex)
+ } else {
+ PostGridView(
+ manager: manager
+ )
+ }
} detail: {
if let post = manager.selectedPost {
PostDetailsView(post: post)
} else {
- Text("Select a post.")
+ Text("Select a Post")
.foregroundColor(.secondary)
}
}
diff --git a/Sora/Views/Settings/SettingsSourceView.swift b/Sora/Views/Settings/SettingsProviderView.swift
index d1f8f30..0829497 100644
--- a/Sora/Views/Settings/SettingsSourceView.swift
+++ b/Sora/Views/Settings/SettingsProviderView.swift
@@ -1,12 +1,12 @@
import SwiftUI
-struct SettingsSourceView: View {
+struct SettingsProviderView: View {
@EnvironmentObject var settings: Settings
var body: some View {
- Picker("Booru", selection: $settings.preferredBooru) {
+ Picker("Provider", selection: $settings.preferredBooru) {
ForEach(BooruProvider.allCases, id: \.self) { type in
- Text(type.rawValue.capitalized).tag(type)
+ Text(type.formatted()).tag(type)
}
}
}
diff --git a/Sora/Views/SettingsView.swift b/Sora/Views/SettingsView.swift
index e1bf2a9..5a42cd1 100644
--- a/Sora/Views/SettingsView.swift
+++ b/Sora/Views/SettingsView.swift
@@ -5,8 +5,8 @@ struct SettingsView: View {
var body: some View {
Form {
- Section(header: Text("Source")) {
- SettingsSourceView()
+ Section(header: Text("Provider")) {
+ SettingsProviderView()
}
Section(header: Text("Thumbnails")) {