mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-11 08:35:26 +00:00
Add follow section in about
This commit is contained in:
parent
382ebd77e6
commit
da6c5ed76c
2 changed files with 60 additions and 1 deletions
|
@ -1,12 +1,19 @@
|
|||
import DesignSystem
|
||||
import Env
|
||||
import SwiftUI
|
||||
import Account
|
||||
import Network
|
||||
import Models
|
||||
|
||||
@MainActor
|
||||
struct AboutView: View {
|
||||
@Environment(RouterPath.self) private var routerPath
|
||||
@Environment(Theme.self) private var theme
|
||||
@Environment(Client.self) private var client
|
||||
|
||||
@State private var dimillianAccount: AccountsListRowViewModel?
|
||||
@State private var iceCubesAccount: AccountsListRowViewModel?
|
||||
|
||||
let versionNumber: String
|
||||
|
||||
init() {
|
||||
|
@ -40,7 +47,6 @@ struct AboutView: View {
|
|||
.cornerRadius(4)
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp/blob/main/PRIVACY.MD")!) {
|
||||
Label("settings.support.privacy-policy", systemImage: "lock")
|
||||
}
|
||||
|
@ -53,6 +59,9 @@ struct AboutView: View {
|
|||
}
|
||||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
|
||||
|
||||
followAccountsSection
|
||||
|
||||
Section {
|
||||
Text("""
|
||||
• [EmojiText](https://github.com/divadretlaw/EmojiText)
|
||||
|
@ -88,6 +97,9 @@ struct AboutView: View {
|
|||
}
|
||||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
}
|
||||
.task {
|
||||
await fetchAccounts()
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.secondaryBackgroundColor)
|
||||
|
@ -97,6 +109,46 @@ struct AboutView: View {
|
|||
routerPath.handle(url: url)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ViewBuilder
|
||||
private var followAccountsSection: some View {
|
||||
if let iceCubesAccount, let dimillianAccount {
|
||||
Section {
|
||||
AccountsListRow(viewModel: iceCubesAccount)
|
||||
AccountsListRow(viewModel: dimillianAccount)
|
||||
}
|
||||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
} else {
|
||||
Section {
|
||||
ProgressView()
|
||||
}
|
||||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchAccounts() async {
|
||||
await withThrowingTaskGroup(of: Void.self) { group in
|
||||
group.addTask {
|
||||
let viewModel = try await fetchAccountViewModel(account: "dimillian@mastodon.social")
|
||||
await MainActor.run {
|
||||
self.dimillianAccount = viewModel
|
||||
}
|
||||
}
|
||||
group.addTask {
|
||||
let viewModel = try await fetchAccountViewModel(account: "icecubesapp@mastodon.online")
|
||||
await MainActor.run {
|
||||
self.iceCubesAccount = viewModel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchAccountViewModel(account: String) async throws -> AccountsListRowViewModel {
|
||||
let dimillianAccount: Account = try await client.get(endpoint: Accounts.lookup(name: account))
|
||||
let rel: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [dimillianAccount.id]))
|
||||
return .init(account: dimillianAccount, relationShip: rel.first)
|
||||
}
|
||||
}
|
||||
|
||||
struct AboutView_Previews: PreviewProvider {
|
||||
|
|
|
@ -3,6 +3,7 @@ import Models
|
|||
|
||||
public enum Accounts: Endpoint {
|
||||
case accounts(id: String)
|
||||
case lookup(name: String)
|
||||
case favorites(sinceId: String?)
|
||||
case bookmarks(sinceId: String?)
|
||||
case followedTags
|
||||
|
@ -34,6 +35,8 @@ public enum Accounts: Endpoint {
|
|||
switch self {
|
||||
case let .accounts(id):
|
||||
"accounts/\(id)"
|
||||
case .lookup:
|
||||
"accounts/lookup"
|
||||
case .favorites:
|
||||
"favourites"
|
||||
case .bookmarks:
|
||||
|
@ -81,6 +84,10 @@ public enum Accounts: Endpoint {
|
|||
|
||||
public func queryItems() -> [URLQueryItem]? {
|
||||
switch self {
|
||||
case let .lookup(name):
|
||||
return [
|
||||
.init(name: "acct", value: name),
|
||||
]
|
||||
case let .statuses(_, sinceId, tag, onlyMedia, excludeReplies, pinned):
|
||||
var params: [URLQueryItem] = []
|
||||
if let tag {
|
||||
|
|
Loading…
Reference in a new issue