forked from jellyfin/Swiftfin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserProfileButton.swift
64 lines (52 loc) · 1.6 KB
/
UserProfileButton.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// 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 (c) 2024 Jellyfin & Jellyfin Contributors
//
import Factory
import JellyfinAPI
import SwiftUI
struct UserProfileButton: View {
@Injected(Container.userSession)
private var userSession
@FocusState
private var isFocused: Bool
let user: UserDto
private var action: () -> Void
init(user: UserDto) {
self.user = user
self.action = {}
}
init(user: UserState) {
self.init(user: .init(id: user.id, name: user.username))
}
var body: some View {
VStack(alignment: .center) {
Button {
action()
} label: {
ZStack {
Color.clear
ImageView(user.profileImageSource(client: userSession.client, maxWidth: 250, maxHeight: 250))
.failure {
Image(systemName: "person.fill")
.resizable()
.edgePadding()
}
}
.aspectRatio(1, contentMode: .fill)
}
.buttonStyle(.card)
.focused($isFocused)
Text(user.name ?? .emptyDash)
.foregroundColor(isFocused ? .primary : .secondary)
}
}
}
extension UserProfileButton {
func onSelect(_ action: @escaping () -> Void) -> Self {
copy(modifying: \.action, with: action)
}
}