2022-12-31 08:10:27 +00:00
|
|
|
import SwiftUI
|
|
|
|
import DesignSystem
|
|
|
|
import PhotosUI
|
|
|
|
import Models
|
|
|
|
import Env
|
|
|
|
|
|
|
|
struct StatusEditorAccessoryView: View {
|
2023-01-11 11:44:34 +00:00
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
|
|
|
|
@EnvironmentObject private var preferences: UserPreferences
|
2023-01-11 06:33:18 +00:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2022-12-31 08:10:27 +00:00
|
|
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
|
|
|
|
|
|
|
@FocusState<Bool>.Binding var isSpoilerTextFocused: Bool
|
|
|
|
@ObservedObject var viewModel: StatusEditorViewModel
|
2023-01-11 11:44:34 +00:00
|
|
|
@State private var isDrafsSheetDisplayed: Bool = false
|
2022-12-31 08:10:27 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
Divider()
|
|
|
|
HStack(alignment: .center, spacing: 16) {
|
|
|
|
PhotosPicker(selection: $viewModel.selectedMedias,
|
|
|
|
matching: .images) {
|
|
|
|
Image(systemName: "photo.fill.on.rectangle.fill")
|
|
|
|
}
|
2023-01-13 06:30:15 +00:00
|
|
|
.disabled(viewModel.showPoll)
|
2022-12-31 08:10:27 +00:00
|
|
|
|
|
|
|
Button {
|
|
|
|
viewModel.insertStatusText(text: " @")
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "at")
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
viewModel.insertStatusText(text: " #")
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "number")
|
|
|
|
}
|
2023-01-13 06:30:15 +00:00
|
|
|
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
viewModel.showPoll.toggle()
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "chart.bar")
|
|
|
|
}
|
|
|
|
.disabled(viewModel.shouldDisablePollButton)
|
2022-12-31 08:10:27 +00:00
|
|
|
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
viewModel.spoilerOn.toggle()
|
|
|
|
}
|
|
|
|
isSpoilerTextFocused.toggle()
|
|
|
|
} label: {
|
|
|
|
Image(systemName: viewModel.spoilerOn ? "exclamationmark.triangle.fill": "exclamationmark.triangle")
|
|
|
|
}
|
2023-01-11 11:44:34 +00:00
|
|
|
|
|
|
|
Button {
|
|
|
|
isDrafsSheetDisplayed = true
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "archivebox")
|
|
|
|
}
|
2022-12-31 08:10:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
characterCountView
|
|
|
|
}
|
|
|
|
.frame(height: 20)
|
2023-01-03 06:41:29 +00:00
|
|
|
.padding(.horizontal, .layoutPadding)
|
2022-12-31 08:10:27 +00:00
|
|
|
.padding(.vertical, 12)
|
|
|
|
.background(.ultraThinMaterial)
|
|
|
|
}
|
2023-01-11 11:44:34 +00:00
|
|
|
.sheet(isPresented: $isDrafsSheetDisplayed) {
|
|
|
|
draftsSheetView
|
|
|
|
}
|
2022-12-31 08:10:27 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 11:44:34 +00:00
|
|
|
private var draftsSheetView: some View {
|
|
|
|
NavigationStack {
|
|
|
|
List {
|
|
|
|
ForEach(preferences.draftsPosts, id: \.self) { draft in
|
|
|
|
Text(draft)
|
|
|
|
.lineLimit(3)
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
|
|
|
.onTapGesture {
|
|
|
|
viewModel.insertStatusText(text: draft)
|
|
|
|
isDrafsSheetDisplayed = false
|
2023-01-11 06:33:18 +00:00
|
|
|
}
|
2023-01-11 11:44:34 +00:00
|
|
|
}
|
|
|
|
.onDelete { indexes in
|
|
|
|
if let index = indexes.first {
|
|
|
|
preferences.draftsPosts.remove(at: index)
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2022-12-31 08:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 11:44:34 +00:00
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
Button("Cancel", action: { dismiss() })
|
|
|
|
}
|
|
|
|
}
|
2023-01-11 06:33:18 +00:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-01-11 11:44:34 +00:00
|
|
|
.navigationTitle("Drafts")
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2022-12-31 08:10:27 +00:00
|
|
|
}
|
2023-01-11 11:44:34 +00:00
|
|
|
.presentationDetents([.medium])
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private var characterCountView: some View {
|
|
|
|
Text("\((currentInstance.instance?.configuration.statuses.maxCharacters ?? 500) - viewModel.statusText.string.utf16.count)")
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
.font(.callout)
|
2022-12-31 08:10:27 +00:00
|
|
|
}
|
|
|
|
}
|