mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add picker to toolbar for moving non-local posts
This commit is contained in:
parent
1397009a8a
commit
9b7fab4370
@ -4,9 +4,29 @@ struct ActivePostToolbarView: View {
|
||||
@EnvironmentObject var model: WriteFreelyModel
|
||||
@ObservedObject var activePost: WFAPost
|
||||
|
||||
@State private var selectedCollection: WFACollection?
|
||||
|
||||
@FetchRequest(
|
||||
entity: WFACollection.entity(),
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \WFACollection.title, ascending: true)]
|
||||
) var collections: FetchedResults<WFACollection>
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 16) {
|
||||
HStack {
|
||||
if model.account.isLoggedIn && activePost.status != PostStatus.local.rawValue {
|
||||
Section(header: Text("Move To:")) {
|
||||
Picker(selection: $selectedCollection, label: Text("Move To…"), content: {
|
||||
Text("\(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")")
|
||||
.tag(nil as WFACollection?)
|
||||
Divider()
|
||||
ForEach(collections) { collection in
|
||||
Text("\(collection.title)").tag(collection as WFACollection?)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
PostEditorStatusToolbarView(post: activePost)
|
||||
.layoutPriority(1)
|
||||
HStack(spacing: 4) {
|
||||
Button(action: {}, label: { Image(systemName: "square.and.arrow.up") })
|
||||
.disabled(activePost.status == PostStatus.local.rawValue)
|
||||
@ -14,6 +34,19 @@ struct ActivePostToolbarView: View {
|
||||
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)
|
||||
}
|
||||
}
|
||||
.onAppear(perform: {
|
||||
self.selectedCollection = collections.first { $0.alias == activePost.collectionAlias }
|
||||
})
|
||||
.onChange(of: selectedCollection, perform: { [selectedCollection] newCollection in
|
||||
if activePost.collectionAlias == newCollection?.alias {
|
||||
return
|
||||
} else {
|
||||
withAnimation {
|
||||
activePost.collectionAlias = newCollection?.alias
|
||||
model.move(post: activePost, from: selectedCollection, to: newCollection)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private func publishPost(_ post: WFAPost) {
|
||||
|
Loading…
Reference in New Issue
Block a user