-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0863e4
commit 00ff4a6
Showing
14 changed files
with
293 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.