mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-06-05 13:28:50 +00:00
Fix notifications tab + prepare multi account
This commit is contained in:
parent
2b733e6b10
commit
d393c4b90f
5 changed files with 11 additions and 15 deletions
|
@ -38,9 +38,9 @@ struct IceCubesApp: App {
|
||||||
tab.makeContentView(popToRootTab: $popToRootTab)
|
tab.makeContentView(popToRootTab: $popToRootTab)
|
||||||
.tabItem {
|
.tabItem {
|
||||||
tab.label
|
tab.label
|
||||||
.badge(tab == .notifications ? watcher.unreadNotificationsCount : 0)
|
|
||||||
}
|
}
|
||||||
.tag(tab)
|
.tag(tab)
|
||||||
|
.badge(tab == .notifications ? watcher.unreadNotificationsCount : 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tint(theme.tintColor)
|
.tint(theme.tintColor)
|
||||||
|
|
|
@ -9,12 +9,12 @@ import DesignSystem
|
||||||
struct SettingsTabs: View {
|
struct SettingsTabs: View {
|
||||||
@Environment(\.openURL) private var openURL
|
@Environment(\.openURL) private var openURL
|
||||||
@EnvironmentObject private var client: Client
|
@EnvironmentObject private var client: Client
|
||||||
|
@EnvironmentObject private var currentAccount: CurrentAccount
|
||||||
@EnvironmentObject private var currentInstance: CurrentInstance
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
||||||
@EnvironmentObject private var appAccountsManager: AppAccountsManager
|
@EnvironmentObject private var appAccountsManager: AppAccountsManager
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
|
|
||||||
@State private var signInInProgress = false
|
@State private var signInInProgress = false
|
||||||
@State private var accountData: Account?
|
|
||||||
@State private var signInServer = IceCubesApp.defaultServer
|
@State private var signInServer = IceCubesApp.defaultServer
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -36,7 +36,7 @@ struct SettingsTabs: View {
|
||||||
.task {
|
.task {
|
||||||
if appAccountsManager.currentAccount.oauthToken != nil {
|
if appAccountsManager.currentAccount.oauthToken != nil {
|
||||||
signInInProgress = true
|
signInInProgress = true
|
||||||
await refreshAccountInfo()
|
await currentAccount.fetchCurrentAccount()
|
||||||
await currentInstance.fetchCurrentInstance()
|
await currentInstance.fetchCurrentInstance()
|
||||||
signInInProgress = false
|
signInInProgress = false
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ struct SettingsTabs: View {
|
||||||
|
|
||||||
private var accountSection: some View {
|
private var accountSection: some View {
|
||||||
Section("Account") {
|
Section("Account") {
|
||||||
if let accountData {
|
if let accountData = currentAccount.account {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Text(appAccountsManager.currentAccount.server)
|
Text(appAccountsManager.currentAccount.server)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
@ -133,7 +133,6 @@ struct SettingsTabs: View {
|
||||||
|
|
||||||
private var signOutButton: some View {
|
private var signOutButton: some View {
|
||||||
Button {
|
Button {
|
||||||
accountData = nil
|
|
||||||
appAccountsManager.delete(account: appAccountsManager.currentAccount)
|
appAccountsManager.delete(account: appAccountsManager.currentAccount)
|
||||||
} label: {
|
} label: {
|
||||||
Text("Sign out").foregroundColor(.red)
|
Text("Sign out").foregroundColor(.red)
|
||||||
|
@ -155,15 +154,11 @@ struct SettingsTabs: View {
|
||||||
do {
|
do {
|
||||||
let oauthToken = try await client.continueOauthFlow(url: url)
|
let oauthToken = try await client.continueOauthFlow(url: url)
|
||||||
appAccountsManager.add(account: AppAccount(server: client.server, oauthToken: oauthToken))
|
appAccountsManager.add(account: AppAccount(server: client.server, oauthToken: oauthToken))
|
||||||
await refreshAccountInfo()
|
await currentAccount.fetchCurrentAccount()
|
||||||
await currentInstance.fetchCurrentInstance()
|
await currentInstance.fetchCurrentInstance()
|
||||||
signInInProgress = false
|
signInInProgress = false
|
||||||
} catch {
|
} catch {
|
||||||
signInInProgress = false
|
signInInProgress = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func refreshAccountInfo() async {
|
|
||||||
accountData = try? await client.get(endpoint: Accounts.verifyCredentials)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,7 @@ struct TimelineTab: View {
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
routeurPath.client = client
|
routeurPath.client = client
|
||||||
if !client.isAuth {
|
timeline = client.isAuth ? .home : .pub
|
||||||
timeline = .pub
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.environmentObject(routeurPath)
|
.environmentObject(routeurPath)
|
||||||
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
||||||
|
|
|
@ -20,7 +20,10 @@ public class CurrentAccount: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func fetchCurrentAccount() async {
|
public func fetchCurrentAccount() async {
|
||||||
guard let client = client, client.isAuth else { return }
|
guard let client = client, client.isAuth else {
|
||||||
|
account = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
Task {
|
Task {
|
||||||
account = try? await client.get(endpoint: Accounts.verifyCredentials)
|
account = try? await client.get(endpoint: Accounts.verifyCredentials)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public struct TimelineView: View {
|
||||||
}
|
}
|
||||||
.padding(.top, DS.Constants.layoutPadding)
|
.padding(.top, DS.Constants.layoutPadding)
|
||||||
}
|
}
|
||||||
if viewModel.timeline == .home {
|
if viewModel.pendingStatusesEnabled {
|
||||||
makePendingNewPostsView(proxy: proxy)
|
makePendingNewPostsView(proxy: proxy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue