Allow switching URIs and see details from UserListView
This commit is contained in:
parent
eb901da824
commit
55dc1ec7e4
|
@ -240,6 +240,8 @@
|
||||||
E11B1B6C2718CD68006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
E11B1B6C2718CD68006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
||||||
E11B1B6D2718CD68006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
E11B1B6D2718CD68006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
||||||
E11B1B6E2718CDBA006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
E11B1B6E2718CDBA006DA3E8 /* JellyfinAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */; };
|
||||||
|
E11D224227378428003F9CB3 /* ServerDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11D224127378428003F9CB3 /* ServerDetailCoordinator.swift */; };
|
||||||
|
E11D224327378428003F9CB3 /* ServerDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11D224127378428003F9CB3 /* ServerDetailCoordinator.swift */; };
|
||||||
E12186DE2718F1C50010884C /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = E12186DD2718F1C50010884C /* Defaults */; };
|
E12186DE2718F1C50010884C /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = E12186DD2718F1C50010884C /* Defaults */; };
|
||||||
E1218C9A271A26BA00EA0737 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = E1218C99271A26BA00EA0737 /* Nuke */; };
|
E1218C9A271A26BA00EA0737 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = E1218C99271A26BA00EA0737 /* Nuke */; };
|
||||||
E1218C9C271A26C400EA0737 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = E1218C9B271A26C400EA0737 /* Nuke */; };
|
E1218C9C271A26C400EA0737 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = E1218C9B271A26C400EA0737 /* Nuke */; };
|
||||||
|
@ -553,6 +555,7 @@
|
||||||
DE5004F745B19E28744A7DE7 /* Pods-JellyfinPlayer tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JellyfinPlayer tvOS.debug.xcconfig"; path = "Target Support Files/Pods-JellyfinPlayer tvOS/Pods-JellyfinPlayer tvOS.debug.xcconfig"; sourceTree = "<group>"; };
|
DE5004F745B19E28744A7DE7 /* Pods-JellyfinPlayer tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JellyfinPlayer tvOS.debug.xcconfig"; path = "Target Support Files/Pods-JellyfinPlayer tvOS/Pods-JellyfinPlayer tvOS.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
E100720626BDABC100CE3E31 /* MediaPlayButtonRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPlayButtonRowView.swift; sourceTree = "<group>"; };
|
E100720626BDABC100CE3E31 /* MediaPlayButtonRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPlayButtonRowView.swift; sourceTree = "<group>"; };
|
||||||
E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPIError.swift; sourceTree = "<group>"; };
|
E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPIError.swift; sourceTree = "<group>"; };
|
||||||
|
E11D224127378428003F9CB3 /* ServerDetailCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerDetailCoordinator.swift; sourceTree = "<group>"; };
|
||||||
E1267D3D271A1F46003C492E /* PreferenceUIHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceUIHostingController.swift; sourceTree = "<group>"; };
|
E1267D3D271A1F46003C492E /* PreferenceUIHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceUIHostingController.swift; sourceTree = "<group>"; };
|
||||||
E131691626C583BC0074BFEE /* LogConstructor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogConstructor.swift; sourceTree = "<group>"; };
|
E131691626C583BC0074BFEE /* LogConstructor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogConstructor.swift; sourceTree = "<group>"; };
|
||||||
E13DD3BC27163C63009D4DAF /* EmailHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailHelper.swift; sourceTree = "<group>"; };
|
E13DD3BC27163C63009D4DAF /* EmailHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailHelper.swift; sourceTree = "<group>"; };
|
||||||
|
@ -1073,19 +1076,20 @@
|
||||||
62C29E9D26D0FE5900C1D2E7 /* Coordinators */ = {
|
62C29E9D26D0FE5900C1D2E7 /* Coordinators */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
62C29EA226D1030F00C1D2E7 /* ConnectToServerCoodinator.swift */,
|
|
||||||
E1D4BF892719D3D000A11E64 /* BasicAppSettingsCoordinator.swift */,
|
E1D4BF892719D3D000A11E64 /* BasicAppSettingsCoordinator.swift */,
|
||||||
|
62C29EA226D1030F00C1D2E7 /* ConnectToServerCoodinator.swift */,
|
||||||
6220D0B926D6092100B8E046 /* FilterCoordinator.swift */,
|
6220D0B926D6092100B8E046 /* FilterCoordinator.swift */,
|
||||||
62C29EA526D1036A00C1D2E7 /* HomeCoordinator.swift */,
|
62C29EA526D1036A00C1D2E7 /* HomeCoordinator.swift */,
|
||||||
E193D5412719404B00900D82 /* MainCoordinator */,
|
|
||||||
6220D0BF26D61C5000B8E046 /* ItemCoordinator.swift */,
|
6220D0BF26D61C5000B8E046 /* ItemCoordinator.swift */,
|
||||||
6220D0B326D5ED8000B8E046 /* LibraryCoordinator.swift */,
|
6220D0B326D5ED8000B8E046 /* LibraryCoordinator.swift */,
|
||||||
62C29EA726D103D500C1D2E7 /* LibraryListCoordinator.swift */,
|
62C29EA726D103D500C1D2E7 /* LibraryListCoordinator.swift */,
|
||||||
|
E193D5412719404B00900D82 /* MainCoordinator */,
|
||||||
C40CD921271F8CD8000FB198 /* MoviesLibrariesCoordinator.swift */,
|
C40CD921271F8CD8000FB198 /* MoviesLibrariesCoordinator.swift */,
|
||||||
C4BE0762271FC0BB003F4AD1 /* TVLibrariesCoordinator.swift */,
|
|
||||||
6220D0B626D5EE1100B8E046 /* SearchCoordinator.swift */,
|
6220D0B626D5EE1100B8E046 /* SearchCoordinator.swift */,
|
||||||
|
E11D224127378428003F9CB3 /* ServerDetailCoordinator.swift */,
|
||||||
E13DD3E827177ED6009D4DAF /* ServerListCoordinator.swift */,
|
E13DD3E827177ED6009D4DAF /* ServerListCoordinator.swift */,
|
||||||
6220D0B026D5EC9900B8E046 /* SettingsCoordinator.swift */,
|
6220D0B026D5EC9900B8E046 /* SettingsCoordinator.swift */,
|
||||||
|
C4BE0762271FC0BB003F4AD1 /* TVLibrariesCoordinator.swift */,
|
||||||
E13DD4012717EE79009D4DAF /* UserListCoordinator.swift */,
|
E13DD4012717EE79009D4DAF /* UserListCoordinator.swift */,
|
||||||
E13DD3F127179378009D4DAF /* UserSignInCoordinator.swift */,
|
E13DD3F127179378009D4DAF /* UserSignInCoordinator.swift */,
|
||||||
6220D0C526D62D8700B8E046 /* VideoPlayerCoordinator.swift */,
|
6220D0C526D62D8700B8E046 /* VideoPlayerCoordinator.swift */,
|
||||||
|
@ -1683,6 +1687,7 @@
|
||||||
53116A17268B919A003024C9 /* SeriesItemView.swift in Sources */,
|
53116A17268B919A003024C9 /* SeriesItemView.swift in Sources */,
|
||||||
E13DD3F027178F87009D4DAF /* SwiftfinNotificationCenter.swift in Sources */,
|
E13DD3F027178F87009D4DAF /* SwiftfinNotificationCenter.swift in Sources */,
|
||||||
531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */,
|
531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */,
|
||||||
|
E11D224327378428003F9CB3 /* ServerDetailCoordinator.swift in Sources */,
|
||||||
E1D4BF8B2719D3D000A11E64 /* BasicAppSettingsCoordinator.swift in Sources */,
|
E1D4BF8B2719D3D000A11E64 /* BasicAppSettingsCoordinator.swift in Sources */,
|
||||||
E13DD3FA2717E961009D4DAF /* UserListViewModel.swift in Sources */,
|
E13DD3FA2717E961009D4DAF /* UserListViewModel.swift in Sources */,
|
||||||
C40CD926271F8D1E000FB198 /* MovieLibrariesViewModel.swift in Sources */,
|
C40CD926271F8D1E000FB198 /* MovieLibrariesViewModel.swift in Sources */,
|
||||||
|
@ -1835,6 +1840,7 @@
|
||||||
625CB56F2678C23300530A6E /* HomeView.swift in Sources */,
|
625CB56F2678C23300530A6E /* HomeView.swift in Sources */,
|
||||||
E173DA5226D04AAF00CC4EB7 /* ColorExtension.swift in Sources */,
|
E173DA5226D04AAF00CC4EB7 /* ColorExtension.swift in Sources */,
|
||||||
53892770263C25230035E14B /* NextUpView.swift in Sources */,
|
53892770263C25230035E14B /* NextUpView.swift in Sources */,
|
||||||
|
E11D224227378428003F9CB3 /* ServerDetailCoordinator.swift in Sources */,
|
||||||
C4BE0766271FC109003F4AD1 /* TVLibrariesViewModel.swift in Sources */,
|
C4BE0766271FC109003F4AD1 /* TVLibrariesViewModel.swift in Sources */,
|
||||||
62ECA01826FA685A00E8EBB7 /* DeepLink.swift in Sources */,
|
62ECA01826FA685A00E8EBB7 /* DeepLink.swift in Sources */,
|
||||||
535BAEA5264A151C005FA86D /* VideoPlayer.swift in Sources */,
|
535BAEA5264A151C005FA86D /* VideoPlayer.swift in Sources */,
|
||||||
|
|
|
@ -63,12 +63,12 @@ network.</string>
|
||||||
<true/>
|
<true/>
|
||||||
<key>UILaunchScreen</key>
|
<key>UILaunchScreen</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>UIImageRespectsSafeAreaInsets</key>
|
|
||||||
<true/>
|
|
||||||
<key>UIImageName</key>
|
|
||||||
<string>swiftfin-logo</string>
|
|
||||||
<key>UIColorName</key>
|
<key>UIColorName</key>
|
||||||
<string>LaunchScreenBackground</string>
|
<string>LaunchScreenBackground</string>
|
||||||
|
<key>UIImageName</key>
|
||||||
|
<string>swiftfin-logo</string>
|
||||||
|
<key>UIImageRespectsSafeAreaInsets</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
<key>UIRequiredDeviceCapabilities</key>
|
<key>UIRequiredDeviceCapabilities</key>
|
||||||
<array>
|
<array>
|
||||||
|
|
|
@ -11,7 +11,13 @@ import SwiftUI
|
||||||
|
|
||||||
struct ServerDetailView: View {
|
struct ServerDetailView: View {
|
||||||
|
|
||||||
@ObservedObject var viewModel = ServerDetailViewModel()
|
@ObservedObject var viewModel: ServerDetailViewModel
|
||||||
|
@State var currentServerURI: String
|
||||||
|
|
||||||
|
init(viewModel: ServerDetailViewModel) {
|
||||||
|
self.viewModel = viewModel
|
||||||
|
self.currentServerURI = viewModel.server.currentURI
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
|
@ -19,44 +25,33 @@ struct ServerDetailView: View {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Name")
|
Text("Name")
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(SessionManager.main.currentLogin.server.name)
|
Text(viewModel.server.name)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
Picker("URI", selection: $currentServerURI) {
|
||||||
Text("URI")
|
ForEach(viewModel.server.uris.sorted(), id: \.self) { uri in
|
||||||
Spacer()
|
Text(uri).tag(uri)
|
||||||
Text(SessionManager.main.currentLogin.server.currentURI)
|
.foregroundColor(.secondary)
|
||||||
.foregroundColor(.secondary)
|
}.onChange(of: currentServerURI) { newValue in
|
||||||
|
viewModel.setServerCurrentURI(uri: newValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("Version")
|
Text("Version")
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(SessionManager.main.currentLogin.server.version)
|
Text(viewModel.server.version)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("Operating System")
|
Text("Operating System")
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(SessionManager.main.currentLogin.server.os)
|
Text(viewModel.server.os)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(action: {
|
|
||||||
viewModel.refreshServerLibrary()
|
|
||||||
}, label: {
|
|
||||||
HStack {
|
|
||||||
Text("Refresh Library")
|
|
||||||
.font(.callout)
|
|
||||||
Spacer()
|
|
||||||
if viewModel.isLoading {
|
|
||||||
ProgressView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).disabled(viewModel.isLoading)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,10 +90,14 @@ struct UserListView: View {
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var toolbarContent: some View {
|
private var toolbarContent: some View {
|
||||||
if viewModel.users.isEmpty {
|
HStack {
|
||||||
EmptyView()
|
Button {
|
||||||
} else {
|
userListRouter.route(to: \.serverDetail, viewModel.server)
|
||||||
HStack {
|
} label: {
|
||||||
|
Image(systemName: "info.circle.fill")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !viewModel.users.isEmpty {
|
||||||
Button {
|
Button {
|
||||||
userListRouter.route(to: \.userSignIn, viewModel.server)
|
userListRouter.route(to: \.userSignIn, viewModel.server)
|
||||||
} label: {
|
} label: {
|
||||||
|
|
|
@ -44,6 +44,7 @@ final class MainCoordinator: NavigationCoordinatable {
|
||||||
nc.addObserver(self, selector: #selector(didLogIn), name: SwiftfinNotificationCenter.Keys.didSignIn, object: nil)
|
nc.addObserver(self, selector: #selector(didLogIn), name: SwiftfinNotificationCenter.Keys.didSignIn, object: nil)
|
||||||
nc.addObserver(self, selector: #selector(didLogOut), name: SwiftfinNotificationCenter.Keys.didSignOut, object: nil)
|
nc.addObserver(self, selector: #selector(didLogOut), name: SwiftfinNotificationCenter.Keys.didSignOut, object: nil)
|
||||||
nc.addObserver(self, selector: #selector(processDeepLink), name: SwiftfinNotificationCenter.Keys.processDeepLink, object: nil)
|
nc.addObserver(self, selector: #selector(processDeepLink), name: SwiftfinNotificationCenter.Keys.processDeepLink, object: nil)
|
||||||
|
nc.addObserver(self, selector: #selector(didChangeServerCurrentURI), name: SwiftfinNotificationCenter.Keys.didChangeServerCurrentURI, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func didLogIn() {
|
@objc func didLogIn() {
|
||||||
|
@ -68,6 +69,15 @@ final class MainCoordinator: NavigationCoordinatable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func didChangeServerCurrentURI(_ notification: Notification) {
|
||||||
|
guard let newCurrentServerState = notification.object as? SwiftfinStore.State.Server else { fatalError("Need to have new current login state server") }
|
||||||
|
guard SessionManager.main.currentLogin != nil else { return }
|
||||||
|
if newCurrentServerState.id == SessionManager.main.currentLogin.server.id {
|
||||||
|
SessionManager.main.loginUser(server: newCurrentServerState, user: SessionManager.main.currentLogin.user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makeMainTab() -> MainTabCoordinator {
|
func makeMainTab() -> MainTabCoordinator {
|
||||||
MainTabCoordinator()
|
MainTabCoordinator()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
//
|
||||||
|
/*
|
||||||
|
* SwiftFin is subject to the terms of the Mozilla Public
|
||||||
|
* License, v2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Copyright 2021 Aiden Vigue & Jellyfin Contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Stinsen
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
final class ServerDetailCoordinator: NavigationCoordinatable {
|
||||||
|
|
||||||
|
let stack = NavigationStack(initial: \ServerDetailCoordinator.start)
|
||||||
|
|
||||||
|
@Root var start = makeStart
|
||||||
|
|
||||||
|
let viewModel: ServerDetailViewModel
|
||||||
|
|
||||||
|
init(viewModel: ServerDetailViewModel) {
|
||||||
|
self.viewModel = viewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder func makeStart() -> some View {
|
||||||
|
ServerDetailView(viewModel: viewModel)
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,8 @@ final class SettingsCoordinator: NavigationCoordinatable {
|
||||||
@Route(.push) var serverDetail = makeServerDetail
|
@Route(.push) var serverDetail = makeServerDetail
|
||||||
|
|
||||||
@ViewBuilder func makeServerDetail() -> some View {
|
@ViewBuilder func makeServerDetail() -> some View {
|
||||||
ServerDetailView()
|
let viewModel = ServerDetailViewModel(server: SessionManager.main.currentLogin.server)
|
||||||
|
ServerDetailView(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder func makeStart() -> some View {
|
@ViewBuilder func makeStart() -> some View {
|
||||||
|
|
|
@ -17,6 +17,7 @@ final class UserListCoordinator: NavigationCoordinatable {
|
||||||
|
|
||||||
@Root var start = makeStart
|
@Root var start = makeStart
|
||||||
@Route(.push) var userSignIn = makeUserSignIn
|
@Route(.push) var userSignIn = makeUserSignIn
|
||||||
|
@Route(.push) var serverDetail = makeServerDetail
|
||||||
|
|
||||||
let viewModel: UserListViewModel
|
let viewModel: UserListViewModel
|
||||||
|
|
||||||
|
@ -28,6 +29,10 @@ final class UserListCoordinator: NavigationCoordinatable {
|
||||||
return UserSignInCoordinator(viewModel: .init(server: server))
|
return UserSignInCoordinator(viewModel: .init(server: server))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeServerDetail(server: SwiftfinStore.State.Server) -> ServerDetailCoordinator {
|
||||||
|
return ServerDetailCoordinator(viewModel: .init(server: server))
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder func makeStart() -> some View {
|
@ViewBuilder func makeStart() -> some View {
|
||||||
UserListView(viewModel: viewModel)
|
UserListView(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,6 @@ enum SwiftfinNotificationCenter {
|
||||||
static let didSignOut = Notification.Name("didSignOut")
|
static let didSignOut = Notification.Name("didSignOut")
|
||||||
static let processDeepLink = Notification.Name("processDeepLink")
|
static let processDeepLink = Notification.Name("processDeepLink")
|
||||||
static let didPurge = Notification.Name("didPurge")
|
static let didPurge = Notification.Name("didPurge")
|
||||||
|
static let didChangeServerCurrentURI = Notification.Name("didChangeCurrentLoginURI")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,37 @@ final class HomeViewModel: ViewModel {
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
|
// Nov. 6, 2021
|
||||||
|
// This is a workaround since Stinsen doesn't have the ability to rebuild a root at the time of writing.
|
||||||
|
// See ServerDetailViewModel.swift for feature request issue
|
||||||
|
let nc = SwiftfinNotificationCenter.main
|
||||||
|
nc.addObserver(self, selector: #selector(didSignIn), name: SwiftfinNotificationCenter.Keys.didSignIn, object: nil)
|
||||||
|
nc.addObserver(self, selector: #selector(didSignOut), name: SwiftfinNotificationCenter.Keys.didSignOut, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func didSignIn() {
|
||||||
|
for cancellable in cancellables {
|
||||||
|
cancellable.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
librariesShowRecentlyAddedIDs = []
|
||||||
|
libraries = []
|
||||||
|
resumeItems = []
|
||||||
|
nextUpItems = []
|
||||||
|
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func didSignOut() {
|
||||||
|
for cancellable in cancellables {
|
||||||
|
cancellable.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
cancellables.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
func refresh() {
|
func refresh() {
|
||||||
LogManager.shared.log.debug("Refresh called.")
|
LogManager.shared.log.debug("Refresh called.")
|
||||||
UserViewsAPI.getUserViews(userId: SessionManager.main.currentLogin.user.id)
|
UserViewsAPI.getUserViews(userId: SessionManager.main.currentLogin.user.id)
|
||||||
.trackActivity(loading)
|
.trackActivity(loading)
|
||||||
|
|
|
@ -11,15 +11,23 @@ import Foundation
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
|
|
||||||
class ServerDetailViewModel: ViewModel {
|
class ServerDetailViewModel: ViewModel {
|
||||||
|
|
||||||
func refreshServerLibrary() {
|
@Published var server: SwiftfinStore.State.Server
|
||||||
LibraryAPI.refreshLibrary()
|
|
||||||
.trackActivity(loading)
|
init(server: SwiftfinStore.State.Server) {
|
||||||
.sink(receiveCompletion: { completion in
|
self.server = server
|
||||||
self.handleAPIRequestError(completion: completion)
|
}
|
||||||
}, receiveValue: {
|
|
||||||
LogManager.shared.log.debug("Refreshed server library successfully")
|
func setServerCurrentURI(uri: String) {
|
||||||
})
|
SessionManager.main.setServerCurrentURI(server: server, uri: uri)
|
||||||
|
.sink { c in
|
||||||
|
print(c)
|
||||||
|
} receiveValue: { newServerState in
|
||||||
|
self.server = newServerState
|
||||||
|
|
||||||
|
let nc = SwiftfinNotificationCenter.main
|
||||||
|
nc.post(name: SwiftfinNotificationCenter.Keys.didChangeServerCurrentURI, object: newServerState)
|
||||||
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,20 @@ class UserListViewModel: ViewModel {
|
||||||
|
|
||||||
@Published var users: [SwiftfinStore.State.User] = []
|
@Published var users: [SwiftfinStore.State.User] = []
|
||||||
|
|
||||||
let server: SwiftfinStore.State.Server
|
var server: SwiftfinStore.State.Server
|
||||||
|
|
||||||
init(server: SwiftfinStore.State.Server) {
|
init(server: SwiftfinStore.State.Server) {
|
||||||
self.server = server
|
self.server = server
|
||||||
|
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
let nc = SwiftfinNotificationCenter.main
|
||||||
|
nc.addObserver(self, selector: #selector(didChangeCurrentLoginURI), name: SwiftfinNotificationCenter.Keys.didChangeServerCurrentURI, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func didChangeCurrentLoginURI(_ notification: Notification) {
|
||||||
|
guard let newServerState = notification.object as? SwiftfinStore.State.Server else { fatalError("Need to have new state server") }
|
||||||
|
self.server = newServerState
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUsers() {
|
func fetchUsers() {
|
||||||
|
@ -33,4 +43,5 @@ class UserListViewModel: ViewModel {
|
||||||
SessionManager.main.delete(user: user)
|
SessionManager.main.delete(user: user)
|
||||||
fetchUsers()
|
fetchUsers()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue