From da6c5ed76c465616bdc145c9dd90594e25ca4916 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Fri, 8 Dec 2023 08:04:35 +0100 Subject: [PATCH] Add follow section in about --- IceCubesApp/App/Tabs/Settings/AboutView.swift | 54 ++++++++++++++++++- .../Sources/Network/Endpoint/Accounts.swift | 7 +++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/IceCubesApp/App/Tabs/Settings/AboutView.swift b/IceCubesApp/App/Tabs/Settings/AboutView.swift index 6d6e9730..eb58e110 100644 --- a/IceCubesApp/App/Tabs/Settings/AboutView.swift +++ b/IceCubesApp/App/Tabs/Settings/AboutView.swift @@ -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 { diff --git a/Packages/Network/Sources/Network/Endpoint/Accounts.swift b/Packages/Network/Sources/Network/Endpoint/Accounts.swift index 62b206c1..76d56ab2 100644 --- a/Packages/Network/Sources/Network/Endpoint/Accounts.swift +++ b/Packages/Network/Sources/Network/Endpoint/Accounts.swift @@ -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 {