Various optimizations to speed things up

This commit is contained in:
Thomas Ricouard 2023-01-30 19:14:43 +01:00
parent 536f0977a0
commit 24504e3bc2
16 changed files with 30 additions and 18 deletions

View file

@ -116,7 +116,7 @@ struct IceCubesApp: App {
} }
} }
if proxy.frame(in: .global).width > (.maxColumnWidth + .secondaryColumnWidth), if proxy.frame(in: .global).width > (.maxColumnWidth + .secondaryColumnWidth),
currentAccount.account?.id != nil appAccountsManager.currentClient.isAuth
{ {
Divider().edgesIgnoringSafeArea(.all) Divider().edgesIgnoringSafeArea(.all)
NotificationsTab(popToRootTab: $popToRootTab, lockedType: nil) NotificationsTab(popToRootTab: $popToRootTab, lockedType: nil)

View file

@ -30,7 +30,7 @@ struct MessagesTab: View {
} }
} }
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(currentAccount.account?.id) .id(client.id)
} }
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in .onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
if popToRootTab == .messages { if popToRootTab == .messages {

View file

@ -9,6 +9,7 @@ import Timeline
struct NotificationsTab: View { struct NotificationsTab: View {
@Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool @Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool
@Environment(\.scenePhase) private var scenePhase
@EnvironmentObject private var theme: Theme @EnvironmentObject private var theme: Theme
@EnvironmentObject private var client: Client @EnvironmentObject private var client: Client
@ -38,7 +39,7 @@ struct NotificationsTab: View {
} }
} }
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(currentAccount.account?.id) .id(client.id)
} }
.onAppear { .onAppear {
routerPath.client = client routerPath.client = client
@ -52,6 +53,17 @@ struct NotificationsTab: View {
routerPath.path = [] routerPath.path = []
} }
} }
.onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase {
case .active:
if isSecondaryColumn {
watcher.unreadNotificationsCount = 0
userPreferences.pushNotificationsCount = 0
}
default:
break
}
})
.onChange(of: currentAccount.account?.id) { _ in .onChange(of: currentAccount.account?.id) { _ in
routerPath.path = [] routerPath.path = []
} }

View file

@ -9,6 +9,7 @@ import Shimmer
import SwiftUI import SwiftUI
struct ProfileTab: View { struct ProfileTab: View {
@EnvironmentObject private var appAccount: AppAccountsManager
@EnvironmentObject private var theme: Theme @EnvironmentObject private var theme: Theme
@EnvironmentObject private var client: Client @EnvironmentObject private var client: Client
@EnvironmentObject private var currentAccount: CurrentAccount @EnvironmentObject private var currentAccount: CurrentAccount
@ -22,11 +23,10 @@ struct ProfileTab: View {
.withAppRouter() .withAppRouter()
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet) .withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(currentAccount.account?.id) .id(client.id)
} else { } else {
AccountDetailView(account: .placeholder()) AccountDetailView(account: .placeholder())
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
} }
} }
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in .onChange(of: $popToRootTab.wrappedValue) { popToRootTab in

View file

@ -37,7 +37,7 @@ struct TimelineTab: View {
toolbarView toolbarView
} }
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(currentAccount.account?.id) .id(client.id)
} }
.onAppear { .onAppear {
routerPath.client = client routerPath.client = client
@ -144,7 +144,7 @@ struct TimelineTab: View {
if UIDevice.current.userInterfaceIdiom != .pad { if UIDevice.current.userInterfaceIdiom != .pad {
ToolbarItem(placement: .navigationBarLeading) { ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routerPath: routerPath) AppAccountsSelectorView(routerPath: routerPath)
.id(currentAccount.account?.id) .id(client.id)
} }
} }
statusEditorToolbarItem(routerPath: routerPath, statusEditorToolbarItem(routerPath: routerPath,

View file

@ -143,7 +143,6 @@ public struct AccountDetailView: View {
scrollViewProxy: proxy, scrollViewProxy: proxy,
scrollOffset: $scrollOffset) scrollOffset: $scrollOffset)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
case let .data(account): case let .data(account):
AccountDetailHeaderView(viewModel: viewModel, AccountDetailHeaderView(viewModel: viewModel,
account: account, account: account,

View file

@ -55,7 +55,7 @@ public struct AppAccountsSelectorView: View {
@ViewBuilder @ViewBuilder
private var labelView: some View { private var labelView: some View {
Group { Group {
if let avatar = currentAccount.account?.avatar { if let avatar = currentAccount.account?.avatar, !currentAccount.isLoadingAccount {
AvatarView(url: avatar, size: avatarSize) AvatarView(url: avatar, size: avatarSize)
} else { } else {
ProgressView() ProgressView()

View file

@ -99,7 +99,6 @@ public struct ConversationDetailView: View {
ForEach(Status.placeholders()) { message in ForEach(Status.placeholders()) { message in
ConversationMessageView(message: message, conversation: viewModel.conversation) ConversationMessageView(message: message, conversation: viewModel.conversation)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
.padding(.vertical, 4) .padding(.vertical, 4)
} }
} }

View file

@ -135,7 +135,6 @@ struct ConversationMessageView: View {
RoundedRectangle(cornerRadius: 8) RoundedRectangle(cornerRadius: 8)
.fill(Color.gray) .fill(Color.gray)
.frame(height: 200) .frame(height: 200)
.shimmering()
} }
} }
.frame(height: 200) .frame(height: 200)

View file

@ -32,7 +32,6 @@ public struct ConversationsListView: View {
ConversationsListRow(conversation: conversation, viewModel: viewModel) ConversationsListRow(conversation: conversation, viewModel: viewModel)
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
} else { } else {
ConversationsListRow(conversation: conversation, viewModel: viewModel) ConversationsListRow(conversation: conversation, viewModel: viewModel)
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)

View file

@ -9,6 +9,7 @@ public class CurrentAccount: ObservableObject {
@Published public private(set) var tags: [Tag] = [] @Published public private(set) var tags: [Tag] = []
@Published public private(set) var followRequests: [Account] = [] @Published public private(set) var followRequests: [Account] = []
@Published public private(set) var isUpdating: Bool = false @Published public private(set) var isUpdating: Bool = false
@Published public private(set) var isLoadingAccount: Bool = false
private var client: Client? private var client: Client?
@ -26,8 +27,8 @@ public class CurrentAccount: ObservableObject {
private func fetchUserData() async { private func fetchUserData() async {
await withTaskGroup(of: Void.self) { group in await withTaskGroup(of: Void.self) { group in
group.addTask { await self.fetchConnections() }
group.addTask { await self.fetchCurrentAccount() } group.addTask { await self.fetchCurrentAccount() }
group.addTask { await self.fetchConnections() }
group.addTask { await self.fetchLists() } group.addTask { await self.fetchLists() }
group.addTask { await self.fetchFollowedTags() } group.addTask { await self.fetchFollowedTags() }
group.addTask { await self.fetchFollowerRequests() } group.addTask { await self.fetchFollowerRequests() }
@ -47,7 +48,9 @@ public class CurrentAccount: ObservableObject {
account = nil account = nil
return return
} }
isLoadingAccount = true
account = try? await client.get(endpoint: Accounts.verifyCredentials) account = try? await client.get(endpoint: Accounts.verifyCredentials)
isLoadingAccount = false
} }
public func fetchLists() async { public func fetchLists() async {

View file

@ -84,7 +84,6 @@ public struct ExploreView: View {
StatusRowView(viewModel: .init(status: status, isCompact: false)) StatusRowView(viewModel: .init(status: status, isCompact: false))
.padding(.vertical, 8) .padding(.vertical, 8)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
} }
} }

View file

@ -2,7 +2,7 @@ import Foundation
import Models import Models
import SwiftUI import SwiftUI
public class Client: ObservableObject, Equatable { public class Client: ObservableObject, Equatable, Identifiable {
public static func == (lhs: Client, rhs: Client) -> Bool { public static func == (lhs: Client, rhs: Client) -> Bool {
lhs.isAuth == rhs.isAuth && lhs.isAuth == rhs.isAuth &&
lhs.server == rhs.server && lhs.server == rhs.server &&
@ -18,6 +18,10 @@ public class Client: ObservableObject, Equatable {
case invalidRedirectURL case invalidRedirectURL
} }
public var id: String {
"\(isAuth)\(server)\(oauthToken?.accessToken ?? "")"
}
public var server: String public var server: String
public let version: Version public let version: Version
public private(set) var connections: Set<String> public private(set) var connections: Set<String>

View file

@ -87,7 +87,7 @@ public struct NotificationsListView: View {
bottom: 12, bottom: 12,
trailing: .layoutPadding)) trailing: .layoutPadding))
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
.shimmering() .redacted(reason: .placeholder)
} }
case let .display(notifications, nextPageState): case let .display(notifications, nextPageState):

View file

@ -35,7 +35,6 @@ public struct StatusDetailView: View {
StatusRowView(viewModel: .init(status: status, isCompact: false)) StatusRowView(viewModel: .init(status: status, isCompact: false))
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.shimmering()
Divider() Divider()
.padding(.vertical, .dividerPadding) .padding(.vertical, .dividerPadding)
} }

View file

@ -20,7 +20,6 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
StatusRowView(viewModel: .init(status: status, isCompact: false)) StatusRowView(viewModel: .init(status: status, isCompact: false))
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
.shimmering()
Divider() Divider()
.padding(.vertical, .dividerPadding) .padding(.vertical, .dividerPadding)
} }