1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Model/NavigationState.swift

85 lines
2.1 KiB
Swift
Raw Normal View History

2021-07-12 02:22:49 +05:30
import Foundation
import SwiftUI
final class NavigationState: ObservableObject {
2021-08-30 03:06:18 +05:30
enum TabSelection: Hashable {
case subscriptions, popular, trending, playlists, channel(String), playlist(String), search
}
2021-07-12 02:22:49 +05:30
@Published var tabSelection: TabSelection = .subscriptions
@Published var showingChannel = false
@Published var channel: Channel?
@Published var showingVideoDetails = false
2021-07-19 04:02:46 +05:30
@Published var showingVideo = false
2021-07-12 02:22:49 +05:30
@Published var video: Video?
2021-07-19 04:02:46 +05:30
@Published var returnToDetails = false
2021-08-30 03:06:18 +05:30
@Published var presentingPlaylistForm = false
@Published var editedPlaylist: Playlist!
@Published var presentingUnsubscribeAlert = false
@Published var channelToUnsubscribe: Channel!
2021-07-12 02:22:49 +05:30
func openChannel(_ channel: Channel) {
2021-07-19 04:02:46 +05:30
returnToDetails = false
2021-07-12 02:22:49 +05:30
self.channel = channel
showingChannel = true
}
func closeChannel() {
showingChannel = false
channel = nil
}
func openVideoDetails(_ video: Video) {
self.video = video
showingVideoDetails = true
}
func closeVideoDetails() {
showingVideoDetails = false
video = nil
}
2021-07-19 04:02:46 +05:30
func playVideo(_ video: Video) {
self.video = video
showingVideo = true
}
func showVideoDetailsIfNeeded() {
showingVideoDetails = returnToDetails
returnToDetails = false
}
2021-07-12 02:22:49 +05:30
var tabSelectionOptionalBinding: Binding<TabSelection?> {
Binding<TabSelection?>(
get: {
self.tabSelection
},
set: {
self.tabSelection = $0 ?? .subscriptions
}
)
}
2021-08-30 03:06:18 +05:30
func presentEditPlaylistForm(_ playlist: Playlist?) {
editedPlaylist = playlist
presentingPlaylistForm = editedPlaylist != nil
}
func presentNewPlaylistForm() {
editedPlaylist = nil
presentingPlaylistForm = true
}
func presentUnsubscribeAlert(_ channel: Channel?) {
channelToUnsubscribe = channel
presentingUnsubscribeAlert = channelToUnsubscribe != nil
}
2021-07-12 02:22:49 +05:30
}
2021-08-30 03:06:18 +05:30
typealias TabSelection = NavigationState.TabSelection