From 793e97f7b0adf3f1bcea934e01fe244288c9bc71 Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Mon, 23 Jan 2023 09:10:58 +0100 Subject: [PATCH] Move context buttons to top of the profile screen. --- Vernissage/Views/MainView.swift | 15 +- Vernissage/Views/UserProfileView.swift | 137 ++++++++++++++++++ .../UserProfile/UserProfileHeader.swift | 122 ---------------- 3 files changed, 145 insertions(+), 129 deletions(-) diff --git a/Vernissage/Views/MainView.swift b/Vernissage/Views/MainView.swift index c8b9655..4b89bc1 100644 --- a/Vernissage/Views/MainView.swift +++ b/Vernissage/Views/MainView.swift @@ -192,14 +192,15 @@ struct MainView: View { @ToolbarContentBuilder private func getTrailingToolbar() -> some ToolbarContent { - ToolbarItem(placement: .navigationBarTrailing) { - Button { - self.sheet = .compose - } label: { - Image(systemName: "square.and.pencil") - .tint(.mainTextColor) + if viewMode == .local || viewMode == .home || viewMode == .federated { + ToolbarItem(placement: .navigationBarTrailing) { + Button { + self.sheet = .compose + } label: { + Image(systemName: "square.and.pencil") + .tint(.mainTextColor) + } } - } } diff --git a/Vernissage/Views/UserProfileView.swift b/Vernissage/Views/UserProfileView.swift index 1c361aa..3a9951b 100644 --- a/Vernissage/Views/UserProfileView.swift +++ b/Vernissage/Views/UserProfileView.swift @@ -31,6 +31,15 @@ struct UserProfileView: View { } } .navigationBarTitle(self.accountDisplayName ?? self.accountUserName) + .toolbar { + if let account = self.account { + if self.applicationState.accountData?.id != account.id { + self.getTrailingAccountToolbar(account: account) + } else { + self.getTrailingProfileToolbar(account: account) + } + } + } .task { do { try await self.loadData() @@ -52,4 +61,132 @@ struct UserProfileView: View { self.firstLoadFinished = true (self.relationship, self.account) = try await (relationshipTask, accountTask) } + + @ToolbarContentBuilder + private func getTrailingAccountToolbar(account: Account) -> some ToolbarContent { + ToolbarItem(placement: .navigationBarTrailing) { + Menu (content: { + if let accountUrl = account.url { + Link(destination: accountUrl) { + Label("Open in browser", systemImage: "safari") + } + + ShareLink(item: accountUrl) { + Label("Share", systemImage: "square.and.arrow.up") + } + + Divider() + } + + Button { + Task { + await onMuteAccount(account: account) + } + } label: { + if self.relationship?.muting == true { + Label("Unute", systemImage: "message.and.waveform.fill") + } else { + Label("Mute", systemImage: "message.and.waveform") + } + } + + Button { + Task { + await onBlockAccount(account: account) + } + } label: { + if self.relationship?.blocking == true { + Label("Unblock", systemImage: "hand.raised.fill") + } else { + Label("Block", systemImage: "hand.raised") + } + } + + }, label: { + Image(systemName: "gear") + .tint(.mainTextColor) + }) + .tint(.accentColor) + } + } + + + @ToolbarContentBuilder + private func getTrailingProfileToolbar(account: Account) -> some ToolbarContent { + ToolbarItem(placement: .navigationBarTrailing) { + Menu (content: { + if let accountUrl = account.url { + Link(destination: accountUrl) { + Label("Open in browser", systemImage: "safari") + } + + ShareLink(item: accountUrl) { + Label("Share", systemImage: "square.and.arrow.up") + } + + Divider() + } + + NavigationLink(destination: StatusesView(accountId: applicationState.accountData?.id ?? String.empty(), listType: .favourites) + .environmentObject(applicationState) + ) { + Label("Favourites", systemImage: "hand.thumbsup") + } + + NavigationLink(destination: StatusesView(accountId: applicationState.accountData?.id ?? String.empty(), listType: .bookmarks) + .environmentObject(applicationState) + ) { + Label("Bookmarks", systemImage: "bookmark") + } + }, label: { + Image(systemName: "gear") + .tint(.mainTextColor) + }) + .tint(.accentColor) + } + } + + private func onMuteAccount(account: Account) async { + do { + if self.relationship?.muting == true { + if let relationship = try await AccountService.shared.unmute( + forAccountId: account.id, + andContext: self.applicationState.accountData + ) { + self.relationship = relationship + } + } else { + if let relationship = try await AccountService.shared.mute( + forAccountId: account.id, + andContext: self.applicationState.accountData + ) { + self.relationship = relationship + } + } + } catch { + ErrorService.shared.handle(error, message: "Muting/unmuting action failed.", showToastr: true) + } + } + + private func onBlockAccount(account: Account) async { + do { + if self.relationship?.blocking == true { + if let relationship = try await AccountService.shared.unblock( + forAccountId: account.id, + andContext: self.applicationState.accountData + ) { + self.relationship = relationship + } + } else { + if let relationship = try await AccountService.shared.block( + forAccountId: account.id, + andContext: self.applicationState.accountData + ) { + self.relationship = relationship + } + } + } catch { + ErrorService.shared.handle(error, message: "Block/unblock action failed.", showToastr: true) + } + } } diff --git a/Vernissage/Widgets/UserProfile/UserProfileHeader.swift b/Vernissage/Widgets/UserProfile/UserProfileHeader.swift index 3b7e428..285e79c 100644 --- a/Vernissage/Widgets/UserProfile/UserProfileHeader.swift +++ b/Vernissage/Widgets/UserProfile/UserProfileHeader.swift @@ -71,8 +71,6 @@ struct UserProfileHeader: View { if self.applicationState.accountData?.id != self.account.id { self.otherAccountActionButtons() - } else { - self.profileAccountActionButtons() } } @@ -102,82 +100,6 @@ struct UserProfileHeader: View { } .buttonStyle(.borderedProminent) .tint(relationship?.following == true ? .dangerColor : .accentColor) - - Menu (content: { - if let accountUrl = account.url { - Link(destination: accountUrl) { - Label("Open in browser", systemImage: "safari") - } - - ShareLink(item: accountUrl) { - Label("Share", systemImage: "square.and.arrow.up") - } - - Divider() - } - - Button { - Task { - await onMuteAccount() - } - } label: { - if self.relationship?.muting == true { - Label("Unute", systemImage: "message.and.waveform.fill") - } else { - Label("Mute", systemImage: "message.and.waveform") - } - } - - Button { - Task { - await onBlockAccount() - } - } label: { - if self.relationship?.blocking == true { - Label("Unblock", systemImage: "hand.raised.fill") - } else { - Label("Block", systemImage: "hand.raised") - } - } - - }, label: { - Image(systemName: "gear") - }) - .buttonStyle(.borderedProminent) - .tint(.accentColor) - } - - @ViewBuilder - private func profileAccountActionButtons() -> some View { - Menu (content: { - if let accountUrl = account.url { - Link(destination: accountUrl) { - Label("Open in browser", systemImage: "safari") - } - - ShareLink(item: accountUrl) { - Label("Share", systemImage: "square.and.arrow.up") - } - - Divider() - } - - NavigationLink(destination: StatusesView(accountId: applicationState.accountData?.id ?? String.empty(), listType: .favourites) - .environmentObject(applicationState) - ) { - Label("Favourites", systemImage: "hand.thumbsup") - } - - NavigationLink(destination: StatusesView(accountId: applicationState.accountData?.id ?? String.empty(), listType: .bookmarks) - .environmentObject(applicationState) - ) { - Label("Bookmarks", systemImage: "bookmark") - } - }, label: { - Image(systemName: "gear") - }) - .buttonStyle(.borderedProminent) - .tint(.accentColor) } private func onRelationshipButtonTap() async { @@ -201,49 +123,5 @@ struct UserProfileHeader: View { ErrorService.shared.handle(error, message: "Relationship action failed.", showToastr: true) } } - - private func onMuteAccount() async { - do { - if self.relationship?.muting == true { - if let relationship = try await AccountService.shared.unmute( - forAccountId: self.account.id, - andContext: self.applicationState.accountData - ) { - self.relationship = relationship - } - } else { - if let relationship = try await AccountService.shared.mute( - forAccountId: self.account.id, - andContext: self.applicationState.accountData - ) { - self.relationship = relationship - } - } - } catch { - ErrorService.shared.handle(error, message: "Muting/unmuting action failed.", showToastr: true) - } - } - - private func onBlockAccount() async { - do { - if self.relationship?.blocking == true { - if let relationship = try await AccountService.shared.unblock( - forAccountId: self.account.id, - andContext: self.applicationState.accountData - ) { - self.relationship = relationship - } - } else { - if let relationship = try await AccountService.shared.block( - forAccountId: self.account.id, - andContext: self.applicationState.accountData - ) { - self.relationship = relationship - } - } - } catch { - ErrorService.shared.handle(error, message: "Block/unblock action failed.", showToastr: true) - } - } }