Fix status menu on Catalyst

This commit is contained in:
Thomas Ricouard 2024-01-23 06:55:12 +01:00
parent d2014d3aec
commit ba071eb4c8
1 changed files with 55 additions and 37 deletions

View File

@ -228,45 +228,14 @@ struct StatusRowContextMenu: View {
Label("account.action.mute", systemImage: "speaker.slash") Label("account.action.mute", systemImage: "speaker.slash")
} }
} }
#if targetEnvironment(macCatalyst)
accountContactMenuItems
#else
ControlGroup { ControlGroup {
Button { accountContactMenuItems
viewModel.routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .pub)
} label: {
Label("status.action.mention", systemImage: "at")
}
Button {
viewModel.routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .direct)
} label: {
Label("status.action.message", systemImage: "tray.full")
}
if viewModel.authorRelationship?.blocking == true {
Button {
Task {
do {
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
viewModel.authorRelationship = try await client.post(endpoint: Accounts.unblock(id: operationAccount.id))
} catch {
print("Error while unblocking: \(error.localizedDescription)")
}
}
} label: {
Label("account.action.unblock", systemImage: "person.crop.circle.badge.exclamationmark")
}
} else {
Button {
Task {
do {
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
viewModel.authorRelationship = try await client.post(endpoint: Accounts.block(id: operationAccount.id))
} catch {
print("Error while blocking: \(error.localizedDescription)")
}
}
} label: {
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
}
}
} }
#endif
} }
} }
Section { Section {
@ -278,6 +247,55 @@ struct StatusRowContextMenu: View {
} }
} }
} }
@ViewBuilder
private var accountContactMenuItems: some View {
Button {
#if targetEnvironment(macCatalyst) || os(visionOS)
openWindow(value: WindowDestinationEditor.mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .pub))
#else
viewModel.routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .pub)
#endif
} label: {
Label("status.action.mention", systemImage: "at")
}
Button {
#if targetEnvironment(macCatalyst) || os(visionOS)
openWindow(value: WindowDestinationEditor.mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .direct))
#else
viewModel.routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.reblog?.account ?? viewModel.status.account, visibility: .direct)
#endif
} label: {
Label("status.action.message", systemImage: "tray.full")
}
if viewModel.authorRelationship?.blocking == true {
Button {
Task {
do {
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
viewModel.authorRelationship = try await client.post(endpoint: Accounts.unblock(id: operationAccount.id))
} catch {
print("Error while unblocking: \(error.localizedDescription)")
}
}
} label: {
Label("account.action.unblock", systemImage: "person.crop.circle.badge.exclamationmark")
}
} else {
Button {
Task {
do {
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
viewModel.authorRelationship = try await client.post(endpoint: Accounts.block(id: operationAccount.id))
} catch {
print("Error while blocking: \(error.localizedDescription)")
}
}
} label: {
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
}
}
}
} }
struct ActivityView: UIViewControllerRepresentable { struct ActivityView: UIViewControllerRepresentable {