mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-11 16:45:27 +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 DesignSystem
|
||||||
import Env
|
import Env
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import Account
|
||||||
|
import Network
|
||||||
|
import Models
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
struct AboutView: View {
|
struct AboutView: View {
|
||||||
@Environment(RouterPath.self) private var routerPath
|
@Environment(RouterPath.self) private var routerPath
|
||||||
@Environment(Theme.self) private var theme
|
@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
|
let versionNumber: String
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -40,7 +47,6 @@ struct AboutView: View {
|
||||||
.cornerRadius(4)
|
.cornerRadius(4)
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
||||||
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp/blob/main/PRIVACY.MD")!) {
|
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp/blob/main/PRIVACY.MD")!) {
|
||||||
Label("settings.support.privacy-policy", systemImage: "lock")
|
Label("settings.support.privacy-policy", systemImage: "lock")
|
||||||
}
|
}
|
||||||
|
@ -53,6 +59,9 @@ struct AboutView: View {
|
||||||
}
|
}
|
||||||
.listRowBackground(theme.primaryBackgroundColor)
|
.listRowBackground(theme.primaryBackgroundColor)
|
||||||
|
|
||||||
|
|
||||||
|
followAccountsSection
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
Text("""
|
Text("""
|
||||||
• [EmojiText](https://github.com/divadretlaw/EmojiText)
|
• [EmojiText](https://github.com/divadretlaw/EmojiText)
|
||||||
|
@ -88,6 +97,9 @@ struct AboutView: View {
|
||||||
}
|
}
|
||||||
.listRowBackground(theme.primaryBackgroundColor)
|
.listRowBackground(theme.primaryBackgroundColor)
|
||||||
}
|
}
|
||||||
|
.task {
|
||||||
|
await fetchAccounts()
|
||||||
|
}
|
||||||
.listStyle(.insetGrouped)
|
.listStyle(.insetGrouped)
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
.background(theme.secondaryBackgroundColor)
|
.background(theme.secondaryBackgroundColor)
|
||||||
|
@ -97,6 +109,46 @@ struct AboutView: View {
|
||||||
routerPath.handle(url: url)
|
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 {
|
struct AboutView_Previews: PreviewProvider {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Models
|
||||||
|
|
||||||
public enum Accounts: Endpoint {
|
public enum Accounts: Endpoint {
|
||||||
case accounts(id: String)
|
case accounts(id: String)
|
||||||
|
case lookup(name: String)
|
||||||
case favorites(sinceId: String?)
|
case favorites(sinceId: String?)
|
||||||
case bookmarks(sinceId: String?)
|
case bookmarks(sinceId: String?)
|
||||||
case followedTags
|
case followedTags
|
||||||
|
@ -34,6 +35,8 @@ public enum Accounts: Endpoint {
|
||||||
switch self {
|
switch self {
|
||||||
case let .accounts(id):
|
case let .accounts(id):
|
||||||
"accounts/\(id)"
|
"accounts/\(id)"
|
||||||
|
case .lookup:
|
||||||
|
"accounts/lookup"
|
||||||
case .favorites:
|
case .favorites:
|
||||||
"favourites"
|
"favourites"
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
|
@ -81,6 +84,10 @@ public enum Accounts: Endpoint {
|
||||||
|
|
||||||
public func queryItems() -> [URLQueryItem]? {
|
public func queryItems() -> [URLQueryItem]? {
|
||||||
switch self {
|
switch self {
|
||||||
|
case let .lookup(name):
|
||||||
|
return [
|
||||||
|
.init(name: "acct", value: name),
|
||||||
|
]
|
||||||
case let .statuses(_, sinceId, tag, onlyMedia, excludeReplies, pinned):
|
case let .statuses(_, sinceId, tag, onlyMedia, excludeReplies, pinned):
|
||||||
var params: [URLQueryItem] = []
|
var params: [URLQueryItem] = []
|
||||||
if let tag {
|
if let tag {
|
||||||
|
|
Loading…
Reference in a new issue