Cleanup + change SignInView to be a sheet

This commit is contained in:
Shav Kinderlehrer 2024-02-21 12:20:24 -05:00
parent 53b0792595
commit ce0be87c7f
22 changed files with 94 additions and 43 deletions

View File

@ -48,6 +48,7 @@
3DBAC9E42B4C7404005F8764 /* UIScreenCurrent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DBAC9E32B4C7404005F8764 /* UIScreenCurrent.swift */; }; 3DBAC9E42B4C7404005F8764 /* UIScreenCurrent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DBAC9E32B4C7404005F8764 /* UIScreenCurrent.swift */; };
3DBAC9EA2B4C8927005F8764 /* ItemPersonIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DBAC9E92B4C8927005F8764 /* ItemPersonIconView.swift */; }; 3DBAC9EA2B4C8927005F8764 /* ItemPersonIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DBAC9E92B4C8927005F8764 /* ItemPersonIconView.swift */; };
3DC6BA2D2B2A422300416B9F /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */; }; 3DC6BA2D2B2A422300416B9F /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */; };
3DD6850C2B85A6A8002FAA1A /* BindingNot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DD6850B2B85A6A8002FAA1A /* BindingNot.swift */; };
3DDD67932B293BC40026781E /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67922B293BC40026781E /* DashboardView.swift */; }; 3DDD67932B293BC40026781E /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67922B293BC40026781E /* DashboardView.swift */; };
3DDD67962B29E28B0026781E /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67952B29E28B0026781E /* SettingsView.swift */; }; 3DDD67962B29E28B0026781E /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67952B29E28B0026781E /* SettingsView.swift */; };
3DDF35D52B7D384000423923 /* ItemSeriesEpisodesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDF35D42B7D384000423923 /* ItemSeriesEpisodesView.swift */; }; 3DDF35D52B7D384000423923 /* ItemSeriesEpisodesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDF35D42B7D384000423923 /* ItemSeriesEpisodesView.swift */; };
@ -129,6 +130,7 @@
3DBAC9E92B4C8927005F8764 /* ItemPersonIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemPersonIconView.swift; sourceTree = "<group>"; }; 3DBAC9E92B4C8927005F8764 /* ItemPersonIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemPersonIconView.swift; sourceTree = "<group>"; };
3DC0E5802B2832B9001CCE96 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 3DC0E5802B2832B9001CCE96 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3DC6BA2C2B2A422300416B9F /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = "<group>"; }; 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = "<group>"; };
3DD6850B2B85A6A8002FAA1A /* BindingNot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingNot.swift; sourceTree = "<group>"; };
3DDD67922B293BC40026781E /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; }; 3DDD67922B293BC40026781E /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; };
3DDD67952B29E28B0026781E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; }; 3DDD67952B29E28B0026781E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
3DDF35D42B7D384000423923 /* ItemSeriesEpisodesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemSeriesEpisodesView.swift; sourceTree = "<group>"; }; 3DDF35D42B7D384000423923 /* ItemSeriesEpisodesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemSeriesEpisodesView.swift; sourceTree = "<group>"; };
@ -189,23 +191,10 @@
3D1015E32B28000E00F5C29A /* AuthStateController.swift */, 3D1015E32B28000E00F5C29A /* AuthStateController.swift */,
3DF1ED3D2B282836000AD8EA /* JellyfinClientController.swift */, 3DF1ED3D2B282836000AD8EA /* JellyfinClientController.swift */,
3DC6BA2C2B2A422300416B9F /* SettingsController.swift */, 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */,
3DBAC9E32B4C7404005F8764 /* UIScreenCurrent.swift */,
); );
path = Controllers; path = Controllers;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
3D1015E02B27FE5700F5C29A /* Models */ = {
isa = PBXGroup;
children = (
3D91FDCC2B2907E800919017 /* JellyfinDateFormatter.swift */,
3D8AB2A42B36440D005BD7D0 /* BlurHashDecode.swift */,
3DAFA8E92B39039900D71AD1 /* JellyfinKitExtensions.swift */,
3DAFA8EB2B394F9F00D71AD1 /* ViewExtensions.swift */,
3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */,
);
path = Models;
sourceTree = "<group>";
};
3D13F95D2B375DAC00E91913 /* Item */ = { 3D13F95D2B375DAC00E91913 /* Item */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -274,7 +263,7 @@
3D9063C92B279A310063DD2A /* Jel */ = { 3D9063C92B279A310063DD2A /* Jel */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3D1015E02B27FE5700F5C29A /* Models */, 3DD6850A2B85A654002FAA1A /* Extensions */,
3D1015DF2B27F8EE00F5C29A /* Controllers */, 3D1015DF2B27F8EE00F5C29A /* Controllers */,
3D1015D72B27F54A00F5C29A /* Views */, 3D1015D72B27F54A00F5C29A /* Views */,
3D9063CA2B279A310063DD2A /* JelApp.swift */, 3D9063CA2B279A310063DD2A /* JelApp.swift */,
@ -341,6 +330,20 @@
path = Person; path = Person;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
3DD6850A2B85A654002FAA1A /* Extensions */ = {
isa = PBXGroup;
children = (
3DBAC9E32B4C7404005F8764 /* UIScreenCurrent.swift */,
3D91FDCC2B2907E800919017 /* JellyfinDateFormatter.swift */,
3D8AB2A42B36440D005BD7D0 /* BlurHashDecode.swift */,
3DAFA8E92B39039900D71AD1 /* JellyfinKitExtensions.swift */,
3DAFA8EB2B394F9F00D71AD1 /* ViewExtensions.swift */,
3D74AE112B7D4EB000C17F2E /* UIScreenWidthExtension.swift */,
3DD6850B2B85A6A8002FAA1A /* BindingNot.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
3DDD67902B293B780026781E /* Dashboard */ = { 3DDD67902B293B780026781E /* Dashboard */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -522,6 +525,7 @@
3DAFA8EF2B3B707B00D71AD1 /* ItemMovieView.swift in Sources */, 3DAFA8EF2B3B707B00D71AD1 /* ItemMovieView.swift in Sources */,
3D8AB2A82B366353005BD7D0 /* LibraryDetailView.swift in Sources */, 3D8AB2A82B366353005BD7D0 /* LibraryDetailView.swift in Sources */,
3DDD67932B293BC40026781E /* DashboardView.swift in Sources */, 3DDD67932B293BC40026781E /* DashboardView.swift in Sources */,
3DD6850C2B85A6A8002FAA1A /* BindingNot.swift in Sources */,
3D13F9612B37637500E91913 /* ItemMediaView.swift in Sources */, 3D13F9612B37637500E91913 /* ItemMediaView.swift in Sources */,
3D2552492B7A8B3100192879 /* ItemSeriesSeasonsView.swift in Sources */, 3D2552492B7A8B3100192879 /* ItemSeriesSeasonsView.swift in Sources */,
3DFE7AF72B5260FF005461FE /* ItemPersonView.swift in Sources */, 3DFE7AF72B5260FF005461FE /* ItemPersonView.swift in Sources */,

View File

@ -14,6 +14,8 @@ class AuthStateController: ObservableObject {
@Published var userId: String? @Published var userId: String?
@Published var username: String? @Published var username: String?
@Published var loaded: Bool = false
private let defaults = UserDefaults.standard private let defaults = UserDefaults.standard
static let shared = AuthStateController() static let shared = AuthStateController()
@ -40,6 +42,8 @@ class AuthStateController: ObservableObject {
if let oldUsername = defaults.string(forKey: "AuthState_username") { if let oldUsername = defaults.string(forKey: "AuthState_username") {
self.username = oldUsername self.username = oldUsername
} }
self.loaded = true
} }
func save() { func save() {

View File

@ -0,0 +1,18 @@
//
// BindingNot.swift
// Jel
//
// Created by zerocool on 2/20/24.
//
import Foundation
import SwiftUI
extension Binding where Value == Bool {
var not: Binding<Value> {
Binding<Value>(
get: { !self.wrappedValue },
set: { self.wrappedValue = !$0 }
)
}
}

View File

@ -9,24 +9,41 @@ import SwiftUI
import PulseUI import PulseUI
struct ContentView: View { struct ContentView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var settingsController: SettingsController = SettingsController.shared
@StateObject var authState: AuthStateController = AuthStateController.shared @StateObject var authState: AuthStateController = AuthStateController.shared
@State var showingConsoleSheet: Bool = false @State var isSignedIn: Bool = true
var body: some View { var body: some View {
VStack { VStack {
if !authState.loggedIn { if isSignedIn {
SignInView()
} else {
NavigationStack { NavigationStack {
DashboardView() DashboardView()
} }
} else {
VStack {
Text("You are not currently signed into a Jellyfin instance.")
.padding()
Button {
// toggle logged in so that it invalidates isSignedIn
authState.loggedIn = true
authState.loggedIn = false
} label: {
Text("Sign in")
} }
} }
} }
} }
.sheet(isPresented: $isSignedIn.not) {
SignInView()
.interactiveDismissDisabled()
}
.onChange(of: authState.loggedIn, {
isSignedIn = authState.loggedIn
})
.onChange(of: authState.loaded, {
isSignedIn = authState.loggedIn
})
}
}
//#Preview { //#Preview {
// ContentView() // ContentView()

View File

@ -11,7 +11,7 @@ import JellyfinKit
struct DashboardLibraryView: View { struct DashboardLibraryView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var libraries: [BaseItemDto] = [] @State var libraries: [BaseItemDto] = []
@State var loading: Bool = true @State var loading: Bool = true

View File

@ -10,6 +10,8 @@ import JellyfinKit
struct DashboardView: View { struct DashboardView: View {
@State var showingSettingsSheet: Bool = false @State var showingSettingsSheet: Bool = false
@ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var refresh: Bool = true
var body: some View { var body: some View {
ScrollView { ScrollView {
@ -37,6 +39,9 @@ struct DashboardView: View {
.sheet(isPresented: $showingSettingsSheet) { .sheet(isPresented: $showingSettingsSheet) {
SettingsView(showingSettingsView: $showingSettingsSheet) SettingsView(showingSettingsView: $showingSettingsSheet)
} }
.onChange(of: authState.loggedIn, {
refresh = !authState.loggedIn
})
} }
} }

View File

@ -11,7 +11,7 @@ import JellyfinKit
struct ItemGenresView: View { struct ItemGenresView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
var item: BaseItemDto var item: BaseItemDto
@State var libraryItems: [BaseItemDto]? = [] @State var libraryItems: [BaseItemDto]? = []

View File

@ -9,7 +9,7 @@ import SwiftUI
import JellyfinKit import JellyfinKit
struct ItemPersonDetailView: View { struct ItemPersonDetailView: View {
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
var person: BaseItemPerson var person: BaseItemPerson

View File

@ -25,7 +25,7 @@ struct ItemPersonIconPlaceholderView: View {
} }
struct ItemPersonIconView: View { struct ItemPersonIconView: View {
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
var person: BaseItemPerson var person: BaseItemPerson

View File

@ -10,7 +10,7 @@ import JellyfinKit
struct ItemSeriesEpisodesView: View { struct ItemSeriesEpisodesView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
var item: BaseItemDto var item: BaseItemDto

View File

@ -12,7 +12,7 @@ struct ItemSeriesSeasonsView: View {
var item: BaseItemDto var item: BaseItemDto
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var seriesItems: [BaseItemDto] = [] @State var seriesItems: [BaseItemDto] = []

View File

@ -10,7 +10,7 @@ import JellyfinKit
struct LibraryDetailView: View { struct LibraryDetailView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var library: BaseItemDto @State var library: BaseItemDto
@State var items: [BaseItemDto]? = [] @State var items: [BaseItemDto]? = []

View File

@ -11,9 +11,9 @@ import PulseUI
struct SettingsView: View { struct SettingsView: View {
@Binding var showingSettingsView: Bool @Binding var showingSettingsView: Bool
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@ObservedObject var settingsController: SettingsController = SettingsController.shared @ObservedObject var settingsController: SettingsController = SettingsController.shared
var body: some View { var body: some View {
NavigationStack { NavigationStack {
Form { Form {
@ -35,7 +35,11 @@ struct SettingsView: View {
Button(role: .destructive) { Button(role: .destructive) {
authState.loggedIn = false authState.loggedIn = false
authState.authToken = nil
authState.save() authState.save()
showingSettingsView.toggle()
settingsController.save()
} label: { } label: {
Text("Sign out") Text("Sign out")
} }

View File

@ -12,7 +12,7 @@ struct AddServerView: View {
@ObservedObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@Binding var serverUrlIsValid: Bool @Binding var serverUrlIsValid: Bool
@State var serverUrlString: String = "http://" @State var serverUrlString: String = ""
@State var urlHasError: Bool = false @State var urlHasError: Bool = false
@State var currentErrorMessage: String = "" @State var currentErrorMessage: String = ""
@State var isLoading: Bool = false @State var isLoading: Bool = false
@ -25,7 +25,7 @@ struct AddServerView: View {
.font(.title) .font(.title)
HStack { HStack {
TextField(text: $serverUrlString) { TextField(text: $serverUrlString) {
Text("http://jellyfin.example.com") Text(verbatim: "https://jellyfin.example.com")
} }
.keyboardType(.URL) .keyboardType(.URL)
.textContentType(.URL) .textContentType(.URL)
@ -102,7 +102,7 @@ struct AddServerView: View {
} }
#Preview { //#Preview {
AddServerView(serverUrlIsValid: .constant(false)) // AddServerView(serverUrlIsValid: .constant(false))
//
} //}

View File

@ -10,7 +10,7 @@ import SwiftUI
struct SignInToServerView: View { struct SignInToServerView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var username: String = "" @State var username: String = ""
@State var password: String = "" @State var password: String = ""

View File

@ -11,9 +11,8 @@ import PulseUI
struct SignInView: View { struct SignInView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @ObservedObject var authState: AuthStateController = AuthStateController.shared
@State var serverUrlIsValid: Bool = false @State var serverUrlIsValid: Bool = false
@State var showingConsoleSheet: Bool = false
var body: some View { var body: some View {
NavigationStack { NavigationStack {
@ -40,6 +39,6 @@ struct SignInView: View {
} }
} }
#Preview { //#Preview {
SignInView() // SignInView()
} //}