Skip to content

Commit

Permalink
Show basic user info
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Sep 18, 2024
1 parent e0863e4 commit 00ff4a6
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 69 deletions.
16 changes: 16 additions & 0 deletions Fyreplace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
4D13AF752C492F4500845FDB /* Config.sh in Resources */ = {isa = PBXBuildFile; fileRef = 4D13AF742C492F4500845FDB /* Config.sh */; };
4D13AF7B2C4E8F4200845FDB /* EnvironmentPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13AF7A2C4E8F4200845FDB /* EnvironmentPicker.swift */; };
4D13AF812C4E907200845FDB /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13AF802C4E907200845FDB /* Environment.swift */; };
4D30DA5F2C986B6C00499450 /* Avatar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D30DA5E2C986B6C00499450 /* Avatar.swift */; };
4D30DA612C98706C00499450 /* Placeholders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D30DA602C98706C00499450 /* Placeholders.swift */; };
4D39A4C82BF516B7003FA52E /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 4D39A4C72BF516B7003FA52E /* Localizable.xcstrings */; };
4D4AF71C2C7CE72900621FF3 /* Tokens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4AF71B2C7CE72900621FF3 /* Tokens.swift */; };
4D4D394A2C086DA2007196D2 /* PublishedScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4D39492C086DA2007196D2 /* PublishedScreen.swift */; };
Expand Down Expand Up @@ -101,6 +103,8 @@
4D13AF742C492F4500845FDB /* Config.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = Config.sh; sourceTree = "<group>"; };
4D13AF7A2C4E8F4200845FDB /* EnvironmentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentPicker.swift; sourceTree = "<group>"; };
4D13AF802C4E907200845FDB /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
4D30DA5E2C986B6C00499450 /* Avatar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Avatar.swift; sourceTree = "<group>"; };
4D30DA602C98706C00499450 /* Placeholders.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Placeholders.swift; sourceTree = "<group>"; };
4D39A4C72BF516B7003FA52E /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
4D4AF71B2C7CE72900621FF3 /* Tokens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tokens.swift; sourceTree = "<group>"; };
4D4D39492C086DA2007196D2 /* PublishedScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishedScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,6 +216,14 @@
path = Data;
sourceTree = "<group>";
};
4D30DA5C2C986B6000499450 /* Components */ = {
isa = PBXGroup;
children = (
4D30DA5E2C986B6C00499450 /* Avatar.swift */,
);
path = Components;
sourceTree = "<group>";
};
4D39A4C62BF51693003FA52E /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -359,6 +371,7 @@
4D54C95E2BF27C78001DE071 /* Views */ = {
isa = PBXGroup;
children = (
4D30DA5C2C986B6000499450 /* Components */,
4D9B3B3B2C34B11D00A8F7AD /* Forms */,
4D5251E82C10532100018CD2 /* Navigation */,
4D4D394B2C086DD3007196D2 /* Screens */,
Expand Down Expand Up @@ -411,6 +424,7 @@
isa = PBXGroup;
children = (
4DA7BFBA2C5FDEC1005CC4FF /* FakeClient.swift */,
4D30DA602C98706C00499450 /* Placeholders.swift */,
);
path = Fakes;
sourceTree = "<group>";
Expand Down Expand Up @@ -625,6 +639,7 @@
4D4AF71C2C7CE72900621FF3 /* Tokens.swift in Sources */,
4D54C9712BF4EA15001DE071 /* SettingsScreen.swift in Sources */,
4D13AF7B2C4E8F4200845FDB /* EnvironmentPicker.swift in Sources */,
4D30DA5F2C986B6C00499450 /* Avatar.swift in Sources */,
4DC5B1CF2C6FA2BE00B75A07 /* MainViewProtocol.swift in Sources */,
4D9B3B422C36E23A00A8F7AD /* Array+RawRepresentable.swift in Sources */,
4D4D394A2C086DA2007196D2 /* PublishedScreen.swift in Sources */,
Expand Down Expand Up @@ -664,6 +679,7 @@
4D060BBF2C907FA4008C32D1 /* NavigationProtocol.swift in Sources */,
4D5251F52C10A9F100018CD2 /* DynamicNavigation.swift in Sources */,
4D9DC5032C11BF2500BA0507 /* Config.swift in Sources */,
4D30DA612C98706C00499450 /* Placeholders.swift in Sources */,
4D54C92C2BF2608A001DE071 /* FyreplaceApp.swift in Sources */,
4D5251F32C109FAC00018CD2 /* Label+Destination.swift in Sources */,
);
Expand Down
6 changes: 6 additions & 0 deletions Fyreplace/Events/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ extension Event {
typealias failure = FailureEvent
}

struct AuthorizationIssueEvent: UnfortunateEvent {}

extension Event {
typealias authorizationIssue = AuthorizationIssueEvent
}

struct NavigationShortcutEvent: Event {
let destination: Destination

Expand Down
7 changes: 5 additions & 2 deletions Fyreplace/Fakes/FakeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ extension FakeClient {
banned: false,
blocked: false,
tint: .init(r: 0x7F, g: 0x7F, b: 0x7F)
))))
)
)
)
)
}
}

Expand All @@ -327,7 +330,7 @@ extension FakeClient {
func getCurrentUser(_: Operations.getCurrentUser.Input) async throws
-> Operations.getCurrentUser.Output
{
fatalError("Not implemented")
return .ok(.init(body: .json(.placeholder)))
}

func getUser(_: Operations.getUser.Input) async throws
Expand Down
13 changes: 13 additions & 0 deletions Fyreplace/Fakes/Placeholders.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extension Components.Schemas.User {
static let placeholder = Self(
id: .randomUuid,
dateCreated: .now,
username: "random_user",
rank: .CITIZEN,
avatar: "",
bio: "Hello there",
banned: false,
blocked: false,
tint: .init(r: 0x7F, g: 0x7F, b: 0x7F)
)
}
60 changes: 60 additions & 0 deletions Fyreplace/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@
}
}
},
"Error.Unauthorized.Text" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "It looks like your session has expired."
}
}
}
},
"Error.Unauthorized.Title" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You have been disconnected"
}
}
}
},
"Error.Unknown" : {
"localizations" : {
"en" : {
Expand All @@ -214,6 +234,16 @@
}
}
},
"Loading" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "…"
}
}
}
},
"Login.Error.NotFound.Message" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -574,6 +604,26 @@
}
}
},
"Settings.DateJoined" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Joined on"
}
}
}
},
"Settings.Header" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Profile"
}
}
}
},
"Settings.Logout" : {
"localizations" : {
"en" : {
Expand All @@ -583,6 +633,16 @@
}
}
}
},
"Settings.Username" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Username"
}
}
}
}
},
"version" : "1.0"
Expand Down
41 changes: 41 additions & 0 deletions Fyreplace/Views/Components/Avatar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import SwiftUI

struct Avatar: View {
let user: Components.Schemas.User?

private var tint: Color {
if let user = user {
.init(
red: Double(user.tint.r) / 255,
green: Double(user.tint.g) / 255,
blue: Double(user.tint.b) / 255
)
} else {
.gray
}
}

var body: some View {
ZStack {
if let avatar = user?.avatar, !avatar.isEmpty {
AsyncImage(url: .init(string: avatar)) {
$0.resizable().scaledToFill()
} placeholder: {
ProgressView()
}
} else {
Image(systemName: "person.crop.circle.fill")
.resizable()
.scaledToFit()
.foregroundStyle(tint)
}
}
.clipShape(.circle)
}
}

#Preview {
Avatar(user: .placeholder)
.frame(width: 100, height: 100)
.padding()
}
18 changes: 7 additions & 11 deletions Fyreplace/Views/Forms/DynamicForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ struct DynamicForm<Content>: View where Content: View {

var body: some View {
#if os(macOS)
Form {
content()
}
.formStyle(.grouped)
.frame(minWidth: 360, maxWidth: 600)
.fixedSize()
.padding()
Form(content: content)
.formStyle(.grouped)
.frame(minWidth: 360, maxWidth: 600)
.fixedSize()
.padding()
#else
HStack {
Form {
content()
}
.frame(maxWidth: UIDevice.current.userInterfaceIdiom == .pad ? 600 : nil)
Form(content: content)
.frame(maxWidth: UIDevice.current.userInterfaceIdiom == .pad ? 600 : nil)
}
.frame(maxWidth: .infinity)
.background(Color(UIColor.systemGroupedBackground))
Expand Down
19 changes: 12 additions & 7 deletions Fyreplace/Views/Forms/LogoHeader.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import SwiftUI

struct LogoHeader: View {
let text: LocalizedStringKey
struct LogoHeader<ImageContent, TextContent>: View where ImageContent: View, TextContent: View {
let namespace: Namespace.ID

@ViewBuilder
let imageContent: () -> ImageContent

@ViewBuilder
let textContent: () -> TextContent

var body: some View {
VStack {
HStack {
Spacer()
Image("Logo", label: Text("Logo"))
.resizable()
imageContent()
#if os(macOS)
.frame(width: 50, height: 50)
.frame(width: 60, height: 60)
#else
.frame(width: 80, height: 80)
#endif
Expand All @@ -20,14 +24,15 @@ struct LogoHeader: View {
#if os(macOS)
.padding(.bottom)
#else
.padding(.vertical, 40)
.padding(.top, 40)
.padding(.bottom, 20)
#endif

HStack {
#if os(macOS)
Spacer()
#endif
Text(text)
textContent()
.fixedSize(horizontal: false, vertical: true)
#if os(macOS)
.font(.headline)
Expand Down
15 changes: 7 additions & 8 deletions Fyreplace/Views/Forms/SubmitOrCancel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ struct SubmitOrCancel: View {

HStack {
#if os(macOS)
cancel.controlSize(.large)
cancel
Spacer()
submit.controlSize(.large)
submit
#else
Spacer()
submit
.toolbar {
if canCancel {
ToolbarItem {
cancel
}
submit.toolbar {
if canCancel {
ToolbarItem {
cancel
}
}
}
Spacer()
#endif
}
Expand Down
5 changes: 5 additions & 0 deletions Fyreplace/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ struct MainView: View, MainViewProtocol {
)
.onReceive(eventBus.events.compactMap { ($0 as? ErrorEvent)?.error }, perform: addError)
.onReceive(eventBus.events.compactMap { ($0 as? FailureEvent) }, perform: addFailure)
.onReceive(eventBus.events.filter { $0 is AuthorizationIssueEvent }) { _ in
token = ""
eventBus.send(
.failure(title: "Error.Unauthorized.Title", text: "Error.Unauthorized.Text"))
}
#if os(macOS)
.task { await keepRefreshingToken() }
#endif
Expand Down
Loading

0 comments on commit 00ff4a6

Please sign in to comment.