2023-09-22 07:31:35 +00:00
|
|
|
import DesignSystem
|
2023-09-22 10:49:25 +00:00
|
|
|
import Models
|
2023-10-01 07:37:09 +00:00
|
|
|
import SwiftData
|
|
|
|
import SwiftUI
|
2023-09-22 07:31:35 +00:00
|
|
|
|
2024-01-06 17:43:26 +00:00
|
|
|
extension StatusEditor {
|
|
|
|
struct DraftsListView: View {
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@Environment(\.modelContext) private var context
|
2023-10-01 07:37:09 +00:00
|
|
|
|
2024-01-06 17:43:26 +00:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-10-01 07:37:09 +00:00
|
|
|
|
2024-01-06 17:43:26 +00:00
|
|
|
@Query(sort: \Draft.creationDate, order: .reverse) var drafts: [Draft]
|
2023-10-01 07:37:09 +00:00
|
|
|
|
2024-01-06 17:43:26 +00:00
|
|
|
@Binding var selectedDraft: Draft?
|
2023-10-01 07:37:09 +00:00
|
|
|
|
2024-01-06 17:43:26 +00:00
|
|
|
var body: some View {
|
|
|
|
NavigationStack {
|
|
|
|
List {
|
|
|
|
ForEach(drafts) { draft in
|
|
|
|
Button {
|
|
|
|
selectedDraft = draft
|
|
|
|
dismiss()
|
|
|
|
} label: {
|
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
|
Text(draft.content)
|
|
|
|
.font(.body)
|
|
|
|
.lineLimit(3)
|
|
|
|
.foregroundStyle(theme.labelColor)
|
|
|
|
Text(draft.creationDate, style: .relative)
|
|
|
|
.font(.footnote)
|
|
|
|
.foregroundStyle(.gray)
|
|
|
|
}
|
|
|
|
}.listRowBackground(theme.primaryBackgroundColor)
|
|
|
|
}
|
|
|
|
.onDelete { indexes in
|
|
|
|
if let index = indexes.first {
|
|
|
|
context.delete(drafts[index])
|
2023-09-22 07:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-06 17:43:26 +00:00
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
Button("action.cancel", action: { dismiss() })
|
|
|
|
}
|
2023-09-22 07:31:35 +00:00
|
|
|
}
|
2024-01-06 17:43:26 +00:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
|
|
|
.navigationTitle("status.editor.drafts.navigation-title")
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2023-09-22 07:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-06 17:43:26 +00:00
|
|
|
|
2023-09-22 07:31:35 +00:00
|
|
|
}
|