Skip to content

Commit 23a8487

Browse files
Let API shrink images
1 parent 7e0673e commit 23a8487

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

Fyreplace/Resources/Localizable.xcstrings

+2-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@
669669
"en" : {
670670
"stringUnit" : {
671671
"state" : "translated",
672-
"value" : "This file is too heavy; please select a file under 1M."
672+
"value" : "Uploaded files can only go up to 10M."
673673
}
674674
}
675675
}
@@ -709,7 +709,7 @@
709709
"en" : {
710710
"stringUnit" : {
711711
"state" : "translated",
712-
"value" : "This file you have selected is not supported."
712+
"value" : "The type of file you have selected is not supported."
713713
}
714714
}
715715
}

Fyreplace/Views/Components/EditableAvatar.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ struct EditableAvatar: View {
2121
private var avatarItem: PhotosPickerItem?
2222

2323
var body: some View {
24-
let opacity = showEditOverlay ? 1.0 : 0.0
25-
let blurred = showEditOverlay
2624
Button {
2725
showPhotosPicker = true
2826
} label: {
29-
Avatar(user: user, blurred: blurred)
27+
Avatar(user: user, blurred: showEditOverlay)
3028
.overlay {
3129
Image(systemName: "pencil")
3230
.resizable()
@@ -35,7 +33,7 @@ struct EditableAvatar: View {
3533
.padding()
3634
.background(.black.opacity(0.5))
3735
.foregroundStyle(.white)
38-
.opacity(opacity)
36+
.opacity(showEditOverlay ? 1.0 : 0.0)
3937
.clipShape(.circle)
4038
}
4139
}

Fyreplace/Views/Screens/SettingsScreen.swift

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct SettingsScreen: View, SettingsScreenProtocol {
1414
@State
1515
var currentUser: Components.Schemas.User?
1616

17+
@State
18+
var isLoadingAvatar = false
19+
1720
@Environment(\.config)
1821
private var config
1922

@@ -32,11 +35,17 @@ struct SettingsScreen: View, SettingsScreenProtocol {
3235
let logoutButton = Button("Settings.Logout", role: .destructive, action: logout)
3336

3437
HStack {
35-
EditableAvatar(
36-
user: currentUser,
37-
avatarSelected: updateAvatar,
38-
avatarRemoved: removeAvatar
39-
)
38+
ZStack {
39+
if isLoadingAvatar {
40+
ProgressView()
41+
} else {
42+
EditableAvatar(
43+
user: currentUser,
44+
avatarSelected: updateAvatar,
45+
avatarRemoved: removeAvatar
46+
)
47+
}
48+
}
4049
.frame(width: .logoSize, height: .logoSize)
4150

4251
VStack(alignment: .leading, spacing: 4) {

Fyreplace/Views/Screens/SettingsScreenProtocol.swift

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ protocol SettingsScreenProtocol: ViewProtocol {
77

88
var token: String { get nonmutating set }
99
var currentUser: Components.Schemas.User? { get nonmutating set }
10+
var isLoadingAvatar: Bool { get nonmutating set }
1011
}
1112

1213
@MainActor
@@ -34,6 +35,8 @@ extension SettingsScreenProtocol {
3435
}
3536

3637
func updateAvatar(with data: Data) async {
38+
isLoadingAvatar = true
39+
3740
await call {
3841
let response = try await api.setCurrentUserAvatar(body: .binary(.init(data)))
3942

@@ -65,9 +68,13 @@ extension SettingsScreenProtocol {
6568
return .error()
6669
}
6770
}
71+
72+
isLoadingAvatar = false
6873
}
6974

7075
func removeAvatar() async {
76+
isLoadingAvatar = true
77+
7178
await call {
7279
let response = try await api.deleteCurrentUserAvatar()
7380

@@ -83,6 +90,8 @@ extension SettingsScreenProtocol {
8390
return .error()
8491
}
8592
}
93+
94+
isLoadingAvatar = false
8695
}
8796

8897
func logout() {

FyreplaceTests/Screens/SettingsScreenTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct SettingsScreenTests {
99
class FakeScreen: FakeScreenBase, SettingsScreenProtocol {
1010
var token = ""
1111
var currentUser: Components.Schemas.User?
12+
var isLoadingAvatar = false
1213
}
1314

1415
@Test("Screen retrieves current user")

0 commit comments

Comments
 (0)