IceCubes/IceCubesApp/App/Tabs/Tabs.swift

267 lines
6.4 KiB
Swift
Raw Normal View History

2022-12-27 09:25:26 +01:00
import Account
2023-03-13 13:38:28 +01:00
import DesignSystem
2022-12-27 09:25:26 +01:00
import Explore
2023-01-17 11:36:01 +01:00
import Foundation
2024-01-06 19:27:26 +01:00
import StatusKit
2022-12-27 09:25:26 +01:00
import SwiftUI
2024-05-02 11:37:38 +02:00
import AppIntents
2022-12-27 09:25:26 +01:00
@MainActor
enum Tab: Int, Identifiable, Hashable, CaseIterable, Codable {
case timeline, notifications, mentions, explore, messages, settings, other
2023-01-16 14:40:23 +01:00
case trending, federated, local
case profile
case bookmarks
case favorites
case post
case followedTags
case lists
2024-02-10 11:26:22 +01:00
case links
2023-01-17 11:36:01 +01:00
nonisolated var id: Int {
2022-12-27 09:25:26 +01:00
rawValue
}
2023-01-17 11:36:01 +01:00
2022-12-27 09:25:26 +01:00
static func loggedOutTab() -> [Tab] {
[.timeline, .settings]
}
2024-02-14 12:48:14 +01:00
static func visionOSTab() -> [Tab] {
2024-02-06 15:17:20 +01:00
[.profile, .timeline, .notifications, .mentions, .explore, .post, .settings]
2022-12-27 09:25:26 +01:00
}
2023-01-17 11:36:01 +01:00
2022-12-27 09:25:26 +01:00
@ViewBuilder
func makeContentView(selectedTab: Binding<Tab>, popToRootTab: Binding<Tab>) -> some View {
2022-12-27 09:25:26 +01:00
switch self {
case .timeline:
TimelineTab(popToRootTab: popToRootTab)
2023-01-16 14:40:23 +01:00
case .trending:
TimelineTab(popToRootTab: popToRootTab, timeline: .trending)
case .local:
TimelineTab(popToRootTab: popToRootTab, timeline: .local)
case .federated:
TimelineTab(popToRootTab: popToRootTab, timeline: .federated)
2022-12-27 09:25:26 +01:00
case .notifications:
NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: nil)
case .mentions:
NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: .mention)
2022-12-27 09:25:26 +01:00
case .explore:
ExploreTab(popToRootTab: popToRootTab)
case .messages:
MessagesTab(popToRootTab: popToRootTab)
2022-12-27 09:25:26 +01:00
case .settings:
2023-11-18 11:58:04 +01:00
SettingsTabs(popToRootTab: popToRootTab, isModal: false)
case .profile:
ProfileTab(popToRootTab: popToRootTab)
case .bookmarks:
NavigationTab {
AccountStatusesListView(mode: .bookmarks)
}
case .favorites:
NavigationTab {
AccountStatusesListView(mode: .favorites)
}
case .followedTags:
NavigationTab {
FollowedTagsListView()
}
case .lists:
NavigationTab {
ListsListView()
}
2024-02-10 11:26:22 +01:00
case .links:
NavigationTab { TrendingLinksListView(cards: []) }
case .post:
2024-02-14 12:48:14 +01:00
VStack {}
case .other:
2022-12-27 09:25:26 +01:00
EmptyView()
}
}
2023-01-17 11:36:01 +01:00
2022-12-27 09:25:26 +01:00
@ViewBuilder
var label: some View {
switch self {
case .timeline:
Label("tab.timeline", systemImage: iconName)
2023-01-16 14:40:23 +01:00
case .trending:
Label("tab.trending", systemImage: iconName)
2023-01-16 14:40:23 +01:00
case .local:
Label("tab.local", systemImage: iconName)
2023-01-16 14:40:23 +01:00
case .federated:
Label("tab.federated", systemImage: iconName)
2022-12-27 09:25:26 +01:00
case .notifications:
Label("tab.notifications", systemImage: iconName)
case .mentions:
2023-12-28 11:26:00 +01:00
Label("tab.mentions", systemImage: iconName)
2022-12-27 09:25:26 +01:00
case .explore:
Label("tab.explore", systemImage: iconName)
case .messages:
Label("tab.messages", systemImage: iconName)
2022-12-27 09:25:26 +01:00
case .settings:
Label("tab.settings", systemImage: iconName)
case .profile:
Label("tab.profile", systemImage: iconName)
case .bookmarks:
Label("accessibility.tabs.profile.picker.bookmarks", systemImage: iconName)
case .favorites:
Label("accessibility.tabs.profile.picker.favorites", systemImage: iconName)
case .post:
Label("menu.new-post", systemImage: iconName)
case .followedTags:
Label("timeline.filter.tags", systemImage: iconName)
case .lists:
Label("timeline.filter.lists", systemImage: iconName)
2024-02-10 11:26:22 +01:00
case .links:
Label("explore.section.trending.links", systemImage: iconName)
case .other:
2022-12-27 09:25:26 +01:00
EmptyView()
}
}
2023-01-17 11:36:01 +01:00
2023-01-16 14:40:23 +01:00
var iconName: String {
switch self {
case .timeline:
2023-09-16 14:15:03 +02:00
"rectangle.stack"
2023-01-16 14:40:23 +01:00
case .trending:
2023-09-16 14:15:03 +02:00
"chart.line.uptrend.xyaxis"
2023-01-16 14:40:23 +01:00
case .local:
2023-09-16 14:15:03 +02:00
"person.2"
2023-01-16 14:40:23 +01:00
case .federated:
2023-09-16 14:15:03 +02:00
"globe.americas"
2023-01-16 14:40:23 +01:00
case .notifications:
2023-09-16 14:15:03 +02:00
"bell"
case .mentions:
2023-09-16 14:15:03 +02:00
"at"
2023-01-16 14:40:23 +01:00
case .explore:
2023-09-16 14:15:03 +02:00
"magnifyingglass"
2023-01-16 14:40:23 +01:00
case .messages:
2023-09-16 14:15:03 +02:00
"tray"
2023-01-16 14:40:23 +01:00
case .settings:
2023-09-16 14:15:03 +02:00
"gear"
case .profile:
2023-09-16 14:15:03 +02:00
"person.crop.circle"
case .bookmarks:
"bookmark"
case .favorites:
"star"
case .post:
"square.and.pencil"
case .followedTags:
"tag"
case .lists:
"list.bullet"
2024-02-10 11:26:22 +01:00
case .links:
"newspaper"
case .other:
2023-09-16 14:15:03 +02:00
""
2023-01-16 14:40:23 +01:00
}
}
2022-12-27 09:25:26 +01:00
}
2023-12-28 11:26:00 +01:00
2024-03-11 08:59:29 +01:00
@MainActor
@Observable
class SidebarTabs {
struct SidedebarTab: Hashable, Codable {
let tab: Tab
var enabled: Bool
}
2024-02-14 12:48:14 +01:00
class Storage {
@AppStorage("sidebar_tabs") var tabs: [SidedebarTab] = [
.init(tab: .timeline, enabled: true),
.init(tab: .trending, enabled: true),
.init(tab: .federated, enabled: true),
.init(tab: .local, enabled: true),
.init(tab: .notifications, enabled: true),
.init(tab: .mentions, enabled: true),
.init(tab: .messages, enabled: true),
.init(tab: .explore, enabled: true),
.init(tab: .bookmarks, enabled: true),
.init(tab: .favorites, enabled: true),
.init(tab: .followedTags, enabled: true),
.init(tab: .lists, enabled: true),
2024-02-14 12:48:14 +01:00
.init(tab: .settings, enabled: true),
.init(tab: .profile, enabled: true),
]
}
2024-02-14 12:48:14 +01:00
private let storage = Storage()
public static let shared = SidebarTabs()
2024-02-14 12:48:14 +01:00
var tabs: [SidedebarTab] {
didSet {
storage.tabs = tabs
}
}
2024-02-14 12:48:14 +01:00
func isEnabled(_ tab: Tab) -> Bool {
tabs.first(where: { $0.tab.id == tab.id })?.enabled == true
}
2024-02-14 12:48:14 +01:00
private init() {
tabs = storage.tabs
}
}
2024-03-11 08:59:29 +01:00
@MainActor
2023-12-28 11:26:00 +01:00
@Observable
class iOSTabs {
enum TabEntries: String {
case first, second, third, fourth, fifth
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
class Storage {
@AppStorage(TabEntries.first.rawValue) var firstTab = Tab.timeline
@AppStorage(TabEntries.second.rawValue) var secondTab = Tab.notifications
@AppStorage(TabEntries.third.rawValue) var thirdTab = Tab.explore
@AppStorage(TabEntries.fourth.rawValue) var fourthTab = Tab.messages
@AppStorage(TabEntries.fifth.rawValue) var fifthTab = Tab.profile
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
private let storage = Storage()
public static let shared = iOSTabs()
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var tabs: [Tab] {
[firstTab, secondTab, thirdTab, fourthTab, fifthTab]
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var firstTab: Tab {
didSet {
storage.firstTab = firstTab
}
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var secondTab: Tab {
didSet {
storage.secondTab = secondTab
}
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var thirdTab: Tab {
didSet {
storage.thirdTab = thirdTab
}
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var fourthTab: Tab {
didSet {
storage.fourthTab = fourthTab
}
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
var fifthTab: Tab {
didSet {
storage.fifthTab = fifthTab
}
}
2024-02-14 12:48:14 +01:00
2023-12-28 11:26:00 +01:00
private init() {
firstTab = storage.firstTab
secondTab = storage.secondTab
thirdTab = storage.thirdTab
fourthTab = storage.fourthTab
fifthTab = storage.fifthTab
}
}