Move context buttons to top of the profile screen.
This commit is contained in:
parent
4358ed6a38
commit
793e97f7b0
|
@ -192,6 +192,7 @@ struct MainView: View {
|
|||
|
||||
@ToolbarContentBuilder
|
||||
private func getTrailingToolbar() -> some ToolbarContent {
|
||||
if viewMode == .local || viewMode == .home || viewMode == .federated {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
self.sheet = .compose
|
||||
|
@ -199,7 +200,7 @@ struct MainView: View {
|
|||
Image(systemName: "square.and.pencil")
|
||||
.tint(.mainTextColor)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue