Format code
This commit is contained in:
parent
9250dc650d
commit
fcc022ea22
|
@ -8,17 +8,17 @@
|
|||
|
||||
import CoreStore
|
||||
import Foundation
|
||||
import Stinsen
|
||||
import JellyfinAPI
|
||||
import Stinsen
|
||||
|
||||
final class UserSignInViewModel: ViewModel {
|
||||
|
||||
@RouterObject
|
||||
var router: UserSignInCoordinator.Router?
|
||||
let server: SwiftfinStore.State.Server
|
||||
|
||||
@Published
|
||||
var users: [UserDto] = []
|
||||
|
||||
@Published
|
||||
var users: [UserDto] = []
|
||||
|
||||
init(server: SwiftfinStore.State.Server) {
|
||||
self.server = server
|
||||
|
@ -52,20 +52,20 @@ final class UserSignInViewModel: ViewModel {
|
|||
|
||||
self.isLoading = false
|
||||
}
|
||||
|
||||
func loadUsers() {
|
||||
// TODO: this is a hack
|
||||
JellyfinAPIAPI.basePath = server.currentURI
|
||||
UserAPI.getPublicUsers()
|
||||
.sink(receiveCompletion: { completion in
|
||||
switch completion {
|
||||
case .finished: ()
|
||||
case .failure:
|
||||
self.users = []
|
||||
}
|
||||
}, receiveValue: { response in
|
||||
self.users = response
|
||||
})
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func loadUsers() {
|
||||
// TODO: this is a hack
|
||||
JellyfinAPIAPI.basePath = server.currentURI
|
||||
UserAPI.getPublicUsers()
|
||||
.sink(receiveCompletion: { completion in
|
||||
switch completion {
|
||||
case .finished: ()
|
||||
case .failure:
|
||||
self.users = []
|
||||
}
|
||||
}, receiveValue: { response in
|
||||
self.users = response
|
||||
})
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,65 +6,64 @@
|
|||
// Copyright (c) 2022 Jellyfin & Jellyfin Contributors
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import JellyfinAPI
|
||||
import SwiftUI
|
||||
|
||||
struct UserLoginCellView: View {
|
||||
|
||||
@State
|
||||
private var expanded = false;
|
||||
|
||||
@State
|
||||
private var enteredPassword: String = ""
|
||||
|
||||
var user: UserDto
|
||||
var baseURL: String?
|
||||
var loginTapped : (String, String) -> Void
|
||||
var cancelTapped: () -> Void
|
||||
|
||||
var body: some View {
|
||||
DisclosureGroup() {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
SecureField(L10n.password, text: $enteredPassword)
|
||||
Button {
|
||||
loginTapped(user.name ?? "", enteredPassword)
|
||||
} label: {
|
||||
L10n.signIn.text
|
||||
}
|
||||
}
|
||||
.padding(.leading, -16)
|
||||
} label: {
|
||||
HStack(spacing: 4.0) {
|
||||
AsyncImage(
|
||||
url: getProfileImageUrl(),
|
||||
content: { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: 50, maxHeight: 50)
|
||||
.clipShape(Circle())
|
||||
},
|
||||
placeholder: {
|
||||
Image(systemName: "person.circle")
|
||||
.resizable()
|
||||
.font(.system(size: 40))
|
||||
.scaledToFit()
|
||||
.frame(maxWidth: 50, maxHeight: 50)
|
||||
})
|
||||
.padding(.vertical, 4.0)
|
||||
|
||||
Text(user.name ?? "")
|
||||
.padding(.leading, 4.0)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getProfileImageUrl() -> URL? {
|
||||
if let userId = user.id, let imageTag = user.primaryImageTag, let server = baseURL {
|
||||
let url = URL(string: "\(server)/Users/\(userId)/Images/Primary?width=200&tag=\(imageTag)&quality=90")
|
||||
LogManager.log.debug(url?.absoluteString ?? "")
|
||||
return url
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@State
|
||||
private var expanded = false
|
||||
|
||||
@State
|
||||
private var enteredPassword: String = ""
|
||||
|
||||
var user: UserDto
|
||||
var baseURL: String?
|
||||
var loginTapped: (String, String) -> Void
|
||||
var cancelTapped: () -> Void
|
||||
|
||||
var body: some View {
|
||||
DisclosureGroup {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
SecureField(L10n.password, text: $enteredPassword)
|
||||
Button {
|
||||
loginTapped(user.name ?? "", enteredPassword)
|
||||
} label: {
|
||||
L10n.signIn.text
|
||||
}
|
||||
}
|
||||
.padding(.leading, -16)
|
||||
} label: {
|
||||
HStack(spacing: 4.0) {
|
||||
AsyncImage(url: getProfileImageUrl(),
|
||||
content: { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: 50, maxHeight: 50)
|
||||
.clipShape(Circle())
|
||||
},
|
||||
placeholder: {
|
||||
Image(systemName: "person.circle")
|
||||
.resizable()
|
||||
.font(.system(size: 40))
|
||||
.scaledToFit()
|
||||
.frame(maxWidth: 50, maxHeight: 50)
|
||||
})
|
||||
.padding(.vertical, 4.0)
|
||||
|
||||
Text(user.name ?? "")
|
||||
.padding(.leading, 4.0)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getProfileImageUrl() -> URL? {
|
||||
if let userId = user.id, let imageTag = user.primaryImageTag, let server = baseURL {
|
||||
let url = URL(string: "\(server)/Users/\(userId)/Images/Primary?width=200&tag=\(imageTag)&quality=90")
|
||||
LogManager.log.debug(url?.absoluteString ?? "")
|
||||
return url
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,19 +19,19 @@ struct UserSignInView: View {
|
|||
private var password: String = ""
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
#if !os(tvOS)
|
||||
// DisclosureGroup not available on tvOS
|
||||
if (viewModel.users.count > 0) {
|
||||
Section(header: L10n.knownUsers.text) {
|
||||
ForEach(viewModel.users, id: \.id) { user in
|
||||
UserLoginCellView(user: user, baseURL: viewModel.server.currentURI, loginTapped: viewModel.login, cancelTapped: viewModel.cancelSignIn)
|
||||
.disabled(viewModel.isLoading)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
List {
|
||||
#if !os(tvOS)
|
||||
// DisclosureGroup not available on tvOS
|
||||
if !viewModel.users.isEmpty {
|
||||
Section(header: L10n.knownUsers.text) {
|
||||
ForEach(viewModel.users, id: \.id) { user in
|
||||
UserLoginCellView(user: user, baseURL: viewModel.server.currentURI, loginTapped: viewModel.login,
|
||||
cancelTapped: viewModel.cancelSignIn)
|
||||
.disabled(viewModel.isLoading)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Section {
|
||||
TextField(L10n.username, text: $username)
|
||||
|
@ -67,6 +67,6 @@ struct UserSignInView: View {
|
|||
}
|
||||
.navigationTitle(L10n.signIn)
|
||||
.navigationBarBackButtonHidden(viewModel.isLoading)
|
||||
.onAppear(perform: viewModel.loadUsers)
|
||||
.onAppear(perform: viewModel.loadUsers)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue