IceCubesApp/IceCubesApp/App/Tabs/Tabs.swift

116 lines
3.1 KiB
Swift
Raw Normal View History

2022-12-27 08:25:26 +00:00
import Account
2023-03-13 12:38:28 +00:00
import DesignSystem
2022-12-27 08:25:26 +00:00
import Explore
2023-01-17 10:36:01 +00:00
import Foundation
import Status
2022-12-27 08:25:26 +00:00
import SwiftUI
@MainActor
enum Tab: Int, Identifiable, Hashable {
case timeline, notifications, mentions, explore, messages, settings, other
2023-01-16 13:40:23 +00:00
case trending, federated, local
case profile
2023-01-17 10:36:01 +00:00
nonisolated var id: Int {
2022-12-27 08:25:26 +00:00
rawValue
}
2023-01-17 10:36:01 +00:00
2022-12-27 08:25:26 +00:00
static func loggedOutTab() -> [Tab] {
[.timeline, .settings]
}
2023-01-17 10:36:01 +00:00
2022-12-27 08:25:26 +00:00
static func loggedInTabs() -> [Tab] {
2023-12-18 15:51:02 +00:00
if UIDevice.current.userInterfaceIdiom == .pad ||
2023-12-19 08:48:12 +00:00
UIDevice.current.userInterfaceIdiom == .mac {
2023-12-18 07:22:59 +00:00
[.timeline, .trending, .federated, .local, .notifications, .mentions, .explore, .messages, .settings]
2023-12-19 08:48:12 +00:00
} else if UIDevice.current.userInterfaceIdiom == .vision {
[.profile, .timeline, .trending, .federated, .local, .notifications, .mentions, .explore, .messages, .settings]
2023-01-16 13:40:23 +00:00
} else {
2023-12-18 07:22:59 +00:00
[.timeline, .notifications, .explore, .messages, .profile]
2023-01-16 13:40:23 +00:00
}
2022-12-27 08:25:26 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-27 08:25:26 +00:00
@ViewBuilder
func makeContentView(popToRootTab: Binding<Tab>) -> some View {
switch self {
case .timeline:
TimelineTab(popToRootTab: popToRootTab)
2023-01-16 13:40:23 +00: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 08:25:26 +00:00
case .notifications:
2023-01-29 16:59:04 +00:00
NotificationsTab(popToRootTab: popToRootTab, lockedType: nil)
case .mentions:
2023-01-29 16:59:04 +00:00
NotificationsTab(popToRootTab: popToRootTab, lockedType: .mention)
2022-12-27 08:25:26 +00:00
case .explore:
ExploreTab(popToRootTab: popToRootTab)
case .messages:
MessagesTab(popToRootTab: popToRootTab)
2022-12-27 08:25:26 +00:00
case .settings:
2023-11-18 10:58:04 +00:00
SettingsTabs(popToRootTab: popToRootTab, isModal: false)
case .profile:
ProfileTab(popToRootTab: popToRootTab)
case .other:
2022-12-27 08:25:26 +00:00
EmptyView()
}
}
2023-01-17 10:36:01 +00:00
2022-12-27 08:25:26 +00:00
@ViewBuilder
var label: some View {
switch self {
case .timeline:
Label("tab.timeline", systemImage: iconName)
2023-01-16 13:40:23 +00:00
case .trending:
Label("tab.trending", systemImage: iconName)
2023-01-16 13:40:23 +00:00
case .local:
Label("tab.local", systemImage: iconName)
2023-01-16 13:40:23 +00:00
case .federated:
Label("tab.federated", systemImage: iconName)
2022-12-27 08:25:26 +00:00
case .notifications:
Label("tab.notifications", systemImage: iconName)
case .mentions:
Label("tab.notifications", systemImage: iconName)
2022-12-27 08:25:26 +00:00
case .explore:
Label("tab.explore", systemImage: iconName)
case .messages:
Label("tab.messages", systemImage: iconName)
2022-12-27 08:25:26 +00:00
case .settings:
Label("tab.settings", systemImage: iconName)
case .profile:
Label("tab.profile", systemImage: iconName)
case .other:
2022-12-27 08:25:26 +00:00
EmptyView()
}
}
2023-01-17 10:36:01 +00:00
2023-01-16 13:40:23 +00:00
var iconName: String {
switch self {
case .timeline:
2023-09-16 12:15:03 +00:00
"rectangle.stack"
2023-01-16 13:40:23 +00:00
case .trending:
2023-09-16 12:15:03 +00:00
"chart.line.uptrend.xyaxis"
2023-01-16 13:40:23 +00:00
case .local:
2023-09-16 12:15:03 +00:00
"person.2"
2023-01-16 13:40:23 +00:00
case .federated:
2023-09-16 12:15:03 +00:00
"globe.americas"
2023-01-16 13:40:23 +00:00
case .notifications:
2023-09-16 12:15:03 +00:00
"bell"
case .mentions:
2023-09-16 12:15:03 +00:00
"at"
2023-01-16 13:40:23 +00:00
case .explore:
2023-09-16 12:15:03 +00:00
"magnifyingglass"
2023-01-16 13:40:23 +00:00
case .messages:
2023-09-16 12:15:03 +00:00
"tray"
2023-01-16 13:40:23 +00:00
case .settings:
2023-09-16 12:15:03 +00:00
"gear"
case .profile:
2023-09-16 12:15:03 +00:00
"person.crop.circle"
case .other:
2023-09-16 12:15:03 +00:00
""
2023-01-16 13:40:23 +00:00
}
}
2022-12-27 08:25:26 +00:00
}