-
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
eb408d7
commit f250378
Showing
13 changed files
with
219 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
extension Components.Schemas.User { | ||
static let maxBioSize = 3000 | ||
} | ||
|
||
extension Components.Schemas.Email: Identifiable { | ||
} |
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,20 @@ | ||
import SwiftUI | ||
|
||
struct DynamicList<Content>: View where Content: View { | ||
@ViewBuilder | ||
let content: () -> Content | ||
|
||
var body: some View { | ||
#if os(macOS) | ||
DynamicForm { | ||
List { | ||
content() | ||
} | ||
} | ||
#else | ||
List { | ||
content() | ||
} | ||
#endif | ||
} | ||
} |
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 EmailsScreen: View, EmailsScreenProtocol { | ||
@EnvironmentObject | ||
var eventBus: EventBus | ||
|
||
@Environment(\.api) | ||
var api: any APIProtocol | ||
|
||
@State | ||
var emails: [Components.Schemas.Email] = [] | ||
|
||
var body: some View { | ||
DynamicList { | ||
ForEach(emails) { email in | ||
LabeledContent { | ||
} label: { | ||
Text(verbatim: email.email) | ||
|
||
if email.main { | ||
Text("Emails.Main") | ||
} else { | ||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
.navigationTitle(Destination.emails.titleKey) | ||
.onAppear { | ||
Task { | ||
await loadEmails() | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
NavigationStack { | ||
EmailsScreen() | ||
} | ||
} |
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,43 @@ | ||
@MainActor | ||
protocol EmailsScreenProtocol: APIViewProtocol { | ||
var emails: [Components.Schemas.Email] { get nonmutating set } | ||
} | ||
|
||
@MainActor | ||
extension EmailsScreenProtocol { | ||
func loadEmails() async { | ||
emails.removeAll() | ||
var page: Int32 = 0 | ||
|
||
while await loadEmails(at: page) { | ||
page += 1 | ||
} | ||
} | ||
|
||
func loadEmails(at page: Int32) async -> Bool { | ||
var hasMore = false | ||
|
||
await call { | ||
let response = try await api.listEmails(query: .init(page: page)) | ||
|
||
switch response { | ||
case let .ok(ok): | ||
switch ok.body { | ||
case let .json(json): | ||
hasMore = !json.isEmpty | ||
emails.append(contentsOf: json) | ||
} | ||
|
||
return nil | ||
|
||
case .unauthorized: | ||
return .authorizationIssue() | ||
|
||
case .forbidden, .default: | ||
return .error() | ||
} | ||
} | ||
|
||
return hasMore | ||
} | ||
} |
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.