iOS client for Grain grain.social
ios photography atproto
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: drop redundant avatar tab image assignment

The onChange(of: auth.avatarImage) handler at MainTabView already
assigns avatarTabImage whenever the avatar transitions to non-nil,
making the post-avatarFetch assignment block redundant in the common
case where the avatar was nil at launch.

authored by

Hima Aramona and committed by
Chad Miller
9b4d1750 f98f8c66

+38 -33
+38 -33
Grain/Views/MainTabView.swift
··· 16 16 @Environment(\.scenePhase) private var scenePhase 17 17 @State private var selectedTab: AppTab = .feed 18 18 @State private var commentPresenter = StoryCommentPresenter() 19 - @State private var client = XRPCClient(baseURL: AuthManager.serverURL) 19 + @State private var client: XRPCClient? 20 20 @State private var showCreate = false 21 21 @State private var avatarTabImage: UIImage? 22 22 @State private var feedRefreshID = UUID() ··· 47 47 var body: some View { 48 48 let _ = launchSignposter.emitEvent("MainTabViewBodyBegin") 49 49 let _ = Self.badgeAppearanceConfigured 50 - let _ = launchSignposter.emitEvent("TabViewBodyBegin") 51 - TabView(selection: $selectedTab) { 52 - Tab("Feed", systemImage: "photo.on.rectangle", value: AppTab.feed) { 53 - FeedView(client: client, pendingDeepLink: $pendingDeepLink, showCreate: $showCreate) 54 - .id(feedRefreshID) 55 - } 50 + Group { 51 + if let client { 52 + let _ = launchSignposter.emitEvent("TabViewBodyBegin") 53 + TabView(selection: $selectedTab) { 54 + Tab("Feed", systemImage: "photo.on.rectangle", value: AppTab.feed) { 55 + FeedView(client: client, pendingDeepLink: $pendingDeepLink, showCreate: $showCreate) 56 + .id(feedRefreshID) 57 + } 56 58 57 - Tab("Search", systemImage: "magnifyingglass", value: AppTab.search) { 58 - SearchView(client: client) 59 - } 59 + Tab("Search", systemImage: "magnifyingglass", value: AppTab.search) { 60 + SearchView(client: client) 61 + } 60 62 61 - Tab("Notifications", systemImage: "bell", value: AppTab.notifications) { 62 - NotificationsView(client: client, viewModel: notificationsVM) 63 - } 64 - .badge(notificationsVM.unseenCount) 63 + Tab("Notifications", systemImage: "bell", value: AppTab.notifications) { 64 + NotificationsView(client: client, viewModel: notificationsVM) 65 + } 66 + .badge(notificationsVM.unseenCount) 65 67 66 - Tab(value: AppTab.profile) { 67 - if let did = auth.userDID { 68 - ProfileView(client: client, did: did, isRoot: true) 69 - } 70 - } label: { 71 - if let img = avatarTabImage { 72 - Label { 73 - Text("Profile") 74 - } icon: { 75 - Image(uiImage: img) 76 - .renderingMode(.original) 68 + Tab(value: AppTab.profile) { 69 + if let did = auth.userDID { 70 + ProfileView(client: client, did: did, isRoot: true) 71 + } 72 + } label: { 73 + if let img = avatarTabImage { 74 + Label { 75 + Text("Profile") 76 + } icon: { 77 + Image(uiImage: img) 78 + .renderingMode(.original) 79 + } 80 + } else { 81 + Label("Profile", systemImage: "person") 82 + } 77 83 } 78 - } else { 79 - Label("Profile", systemImage: "person") 80 84 } 85 + .tint(Color("AccentColor")) 86 + .environment(commentPresenter) 87 + } else { 88 + Color.clear 81 89 } 82 90 } 83 - .tint(Color("AccentColor")) 84 - .environment(commentPresenter) 85 91 .task { 86 92 let taskSpid = launchSignposter.makeSignpostID() 87 93 let taskState = launchSignposter.beginInterval("MainTabLaunch", id: taskSpid) ··· 118 124 await avatarFetch 119 125 launchSignposter.endInterval("AvatarFetch", avatarState) 120 126 launchLogger.debug("[AvatarFetch] end") 121 - if let uiImage = auth.avatarImage { 122 - avatarTabImage = circularAvatar(uiImage, size: 26) 123 - } 124 127 125 128 await notifFetch 126 129 launchSignposter.endInterval("NotificationsFetch", notifState) ··· 148 151 Task { 149 152 try? await auth.refreshIfNeeded() 150 153 await notificationsVM.fetchUnseenCount(auth: auth.authContext()) 151 - await labelDefsCache.loadIfNeeded(client: client, auth: auth.authContext()) 154 + if let client { 155 + await labelDefsCache.loadIfNeeded(client: client, auth: auth.authContext()) 156 + } 152 157 } 153 158 } else if scenePhase == .background { 154 159 Task {