IceCubesApp/Packages/Status/Sources/Status/Row/StatusRowContextMenu.swift

135 lines
4.4 KiB
Swift
Raw Normal View History

2023-01-17 10:36:01 +00:00
import Env
2023-01-04 17:37:58 +00:00
import Foundation
import SwiftUI
struct StatusRowContextMenu: View {
@EnvironmentObject private var preferences: UserPreferences
2023-01-04 17:37:58 +00:00
@EnvironmentObject private var account: CurrentAccount
@EnvironmentObject private var currentInstance: CurrentInstance
@EnvironmentObject private var routerPath: RouterPath
2023-01-17 10:36:01 +00:00
2023-01-04 17:37:58 +00:00
@ObservedObject var viewModel: StatusRowViewModel
2023-01-17 10:36:01 +00:00
2023-01-04 17:37:58 +00:00
var body: some View {
if !viewModel.isRemote {
Button { Task {
if viewModel.isFavorited {
await viewModel.unFavorite()
} else {
await viewModel.favorite()
}
} } label: {
Label(viewModel.isFavorited ? "status.action.unfavorite" : "status.action.favorite", systemImage: "star")
2023-01-04 17:37:58 +00:00
}
Button { Task {
if viewModel.isReblogged {
await viewModel.unReblog()
} else {
await viewModel.reblog()
}
} } label: {
Label(viewModel.isReblogged ? "status.action.unboost" : "status.action.boost", systemImage: "arrow.left.arrow.right.circle")
2023-01-04 17:37:58 +00:00
}
2023-01-09 18:26:56 +00:00
Button { Task {
if viewModel.isBookmarked {
await viewModel.unbookmark()
} else {
await viewModel.bookmark()
}
} } label: {
Label(viewModel.isBookmarked ? "status.action.unbookmark" : "status.action.bookmark",
2023-01-09 18:26:56 +00:00
systemImage: "bookmark")
}
Button {
routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.status)
} label: {
Label("status.action.reply", systemImage: "arrowshape.turn.up.left")
}
2023-01-04 17:37:58 +00:00
}
2023-01-17 10:36:01 +00:00
if viewModel.status.visibility == .pub, !viewModel.isRemote {
2023-01-04 17:37:58 +00:00
Button {
routerPath.presentedSheet = .quoteStatusEditor(status: viewModel.status)
2023-01-04 17:37:58 +00:00
} label: {
Label("status.action.quote", systemImage: "quote.bubble")
2023-01-04 17:37:58 +00:00
}
}
2023-01-17 10:36:01 +00:00
2023-01-07 17:01:06 +00:00
Divider()
2023-01-17 10:36:01 +00:00
if let url = viewModel.status.reblog?.url ?? viewModel.status.url {
2023-01-17 10:36:01 +00:00
ShareLink(item: url) {
Label("status.action.share", systemImage: "square.and.arrow.up")
2023-01-17 10:36:01 +00:00
}
}
2023-01-17 10:36:01 +00:00
if let url = URL(string: viewModel.status.reblog?.url ?? viewModel.status.url ?? "") {
2023-02-01 06:09:41 +00:00
Button { UIApplication.shared.open(url) } label: {
Label("status.action.view-in-browser", systemImage: "safari")
2023-01-04 17:37:58 +00:00
}
}
2023-01-17 10:36:01 +00:00
Button {
2023-02-06 17:41:12 +00:00
UIPasteboard.general.string = viewModel.status.reblog?.content.asRawText ?? viewModel.status.content.asRawText
} label: {
Label("status.action.copy-text", systemImage: "doc.on.doc")
}
if let lang = preferences.serverPreferences?.postLanguage ?? Locale.current.language.languageCode?.identifier
{
Button {
Task {
await viewModel.translate(userLang: lang)
}
} label: {
if let statusLang = viewModel.status.language,
let languageName = Locale.current.localizedString(forLanguageCode: statusLang) {
Label("status.action.translate-from-\(languageName)", systemImage: "captions.bubble")
} else {
Label("status.action.translate", systemImage: "captions.bubble")
}
}
}
2023-01-04 17:37:58 +00:00
if account.account?.id == viewModel.status.account.id {
Section("status.action.section.your-post") {
2023-01-04 17:37:58 +00:00
Button {
Task {
if viewModel.isPinned {
await viewModel.unPin()
} else {
await viewModel.pin()
}
}
} label: {
Label(viewModel.isPinned ? "status.action.unpin" : "status.action.pin", systemImage: viewModel.isPinned ? "pin.fill" : "pin")
2023-01-04 17:37:58 +00:00
}
if currentInstance.isEditSupported {
Button {
routerPath.presentedSheet = .editStatusEditor(status: viewModel.status)
} label: {
Label("status.action.edit", systemImage: "pencil")
}
2023-01-04 17:37:58 +00:00
}
Button(role: .destructive,
action: { viewModel.showDeleteAlert = true },
label: { Label("status.action.delete", systemImage: "trash") }
)
2023-01-04 17:37:58 +00:00
}
} else if !viewModel.isRemote {
2023-01-04 17:37:58 +00:00
Section(viewModel.status.account.acct) {
Button {
routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.account, visibility: .pub)
2023-01-04 17:37:58 +00:00
} label: {
Label("status.action.mention", systemImage: "at")
2023-01-04 17:37:58 +00:00
}
Button {
routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.account, visibility: .direct)
2023-01-04 17:37:58 +00:00
} label: {
Label("status.action.message", systemImage: "tray.full")
2023-01-04 17:37:58 +00:00
}
}
}
}
}