IceCubesApp/Packages/Status/Sources/Status/Editor/Drafts/DraftsListView.swift
Paul Schuetz 0b5e764556
Automatically remove spaces in server names (#1600)
* 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>
2023-10-01 09:37:09 +02:00

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 = []
}
}