Skip to content

Commit

Permalink
Let API shrink images
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Oct 8, 2024
1 parent 7e0673e commit 23a8487
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Fyreplace/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "This file is too heavy; please select a file under 1M."
"value" : "Uploaded files can only go up to 10M."
}
}
}
Expand Down Expand Up @@ -709,7 +709,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "This file you have selected is not supported."
"value" : "The type of file you have selected is not supported."
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Fyreplace/Views/Components/EditableAvatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ struct EditableAvatar: View {
private var avatarItem: PhotosPickerItem?

var body: some View {
let opacity = showEditOverlay ? 1.0 : 0.0
let blurred = showEditOverlay
Button {
showPhotosPicker = true
} label: {
Avatar(user: user, blurred: blurred)
Avatar(user: user, blurred: showEditOverlay)
.overlay {
Image(systemName: "pencil")
.resizable()
Expand All @@ -35,7 +33,7 @@ struct EditableAvatar: View {
.padding()
.background(.black.opacity(0.5))
.foregroundStyle(.white)
.opacity(opacity)
.opacity(showEditOverlay ? 1.0 : 0.0)
.clipShape(.circle)
}
}
Expand Down
19 changes: 14 additions & 5 deletions Fyreplace/Views/Screens/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct SettingsScreen: View, SettingsScreenProtocol {
@State
var currentUser: Components.Schemas.User?

@State
var isLoadingAvatar = false

@Environment(\.config)
private var config

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

HStack {
EditableAvatar(
user: currentUser,
avatarSelected: updateAvatar,
avatarRemoved: removeAvatar
)
ZStack {
if isLoadingAvatar {
ProgressView()
} else {
EditableAvatar(
user: currentUser,
avatarSelected: updateAvatar,
avatarRemoved: removeAvatar
)
}
}
.frame(width: .logoSize, height: .logoSize)

VStack(alignment: .leading, spacing: 4) {
Expand Down
9 changes: 9 additions & 0 deletions Fyreplace/Views/Screens/SettingsScreenProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ protocol SettingsScreenProtocol: ViewProtocol {

var token: String { get nonmutating set }
var currentUser: Components.Schemas.User? { get nonmutating set }
var isLoadingAvatar: Bool { get nonmutating set }
}

@MainActor
Expand Down Expand Up @@ -34,6 +35,8 @@ extension SettingsScreenProtocol {
}

func updateAvatar(with data: Data) async {
isLoadingAvatar = true

await call {
let response = try await api.setCurrentUserAvatar(body: .binary(.init(data)))

Expand Down Expand Up @@ -65,9 +68,13 @@ extension SettingsScreenProtocol {
return .error()
}
}

isLoadingAvatar = false
}

func removeAvatar() async {
isLoadingAvatar = true

await call {
let response = try await api.deleteCurrentUserAvatar()

Expand All @@ -83,6 +90,8 @@ extension SettingsScreenProtocol {
return .error()
}
}

isLoadingAvatar = false
}

func logout() {
Expand Down
1 change: 1 addition & 0 deletions FyreplaceTests/Screens/SettingsScreenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct SettingsScreenTests {
class FakeScreen: FakeScreenBase, SettingsScreenProtocol {
var token = ""
var currentUser: Components.Schemas.User?
var isLoadingAvatar = false
}

@Test("Screen retrieves current user")
Expand Down

0 comments on commit 23a8487

Please sign in to comment.