summaryrefslogtreecommitdiff
path: root/Sora/Views/ContentView.swift
blob: 85294eee275a96989b623c3600bf1dd0ebfd61b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import SwiftUI

struct ContentView: View {
  @Binding var selectedTab: Int
  @State private var tabs = [
    "Posts",
    "Search History",
    "Bookmarks",
  ]
  @Binding var selectedPost: (post: BooruPost?, manager: BooruManager?)

  var body: some View {
    #if os(macOS)
      NavigationSplitView {
        List(selection: $selectedTab) {
          ForEach(Array(tabs.enumerated()), id: \.offset) { index, element in
            NavigationLink(value: index) { Text(element) }
          }
        }
      } content: {
        switch selectedTab {
        case 1:
          PostGridSearchHistoryView(
            selectedTab: $selectedTab,
            isPresented: .constant(false),
            manager: selectedPost.manager ?? .init()
          )

        case 2:
          BookmarksView(selectedTab: $selectedTab, manager: selectedPost.manager ?? .init())

        case 3:
          SettingsView()

        default:
          PostGridTabSwitcherView(selectedTab: $selectedTab, selectedPost: $selectedPost)
        }
      } detail: {
        if selectedPost.post != nil && selectedPost.manager != nil {
          PostDetailsView(selectedPost: $selectedPost)
        } else {
          Text("Select a Post")
            .foregroundColor(.secondary)
        }
      }
      #if DEBUG
        .onAppear { tabs.append("Settings") }
      #endif
    #else
      NavigationStack {
        PostGridTabSwitcherView(selectedTab: $selectedTab, selectedPost: $selectedPost)
          .navigationDestination(
            isPresented: Binding(
              get: { selectedPost.post != nil },
              set: { if !$0 { selectedPost = (post: nil, manager: nil) } }
            )
          ) {
            if let post = selectedPost.post, let manager = selectedPost.manager {
              PostDetailsView(selectedPost: $selectedPost)
            }
          }
      }
    #endif
  }
}