mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-02 09:59:31 +00:00
0b5e764556
* Automatically remove spaces in server names If a server name includes a space (which can happen if the string is pasted / autocompleted), this space is removed, which results in the app not crashing. Fixes #1599 Signed-off-by: Paul Schuetz <pa.schuetz@web.de> * Format --------- Signed-off-by: Paul Schuetz <pa.schuetz@web.de> Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
66 lines
1.7 KiB
Swift
66 lines
1.7 KiB
Swift
import DesignSystem
|
|
import Models
|
|
import SwiftData
|
|
import SwiftUI
|
|
|
|
struct DraftsListView: View {
|
|
@AppStorage("draft_posts") public var legacyDraftPosts: [String] = []
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
@Environment(\.modelContext) private var context
|
|
|
|
@Environment(Theme.self) private var theme
|
|
|
|
@Query(sort: \Draft.creationDate, order: .reverse) var drafts: [Draft]
|
|
|
|
@Binding var selectedDraft: Draft?
|
|
|
|
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])
|
|
}
|
|
}
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
Button("action.cancel", action: { dismiss() })
|
|
}
|
|
}
|
|
.scrollContentBackground(.hidden)
|
|
.background(theme.secondaryBackgroundColor)
|
|
.navigationTitle("status.editor.drafts.navigation-title")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.onAppear {
|
|
migrateUserPreferencesDraft()
|
|
}
|
|
}
|
|
}
|
|
|
|
func migrateUserPreferencesDraft() {
|
|
for draft in legacyDraftPosts {
|
|
let newDraft = Draft(content: draft)
|
|
context.insert(newDraft)
|
|
}
|
|
legacyDraftPosts = []
|
|
}
|
|
}
|