@@ -2,12 +2,21 @@ import SwiftUI
22
33struct PostEditorView : View {
44 @EnvironmentObject var model : WriteFreelyModel
5+ @Environment ( \. managedObjectContext) var moc
56 @Environment ( \. horizontalSizeClass) var horizontalSizeClass
67 @Environment ( \. presentationMode) var presentationMode
8+
79 @ObservedObject var post : WFAPost
810 @State private var updatingTitleFromServer : Bool = false
911 @State private var updatingBodyFromServer : Bool = false
1012
13+ @State private var selectedCollection : WFACollection ?
14+
15+ @FetchRequest (
16+ entity: WFACollection . entity ( ) ,
17+ sortDescriptors: [ NSSortDescriptor ( keyPath: \WFACollection . title, ascending: true ) ]
18+ ) var collections : FetchedResults < WFACollection >
19+
1120 var body : some View {
1221 VStack {
1322 if post. hasNewerRemoteCopy {
@@ -143,25 +152,80 @@ struct PostEditorView: View {
143152 ToolbarItem ( placement: . principal) {
144153 PostEditorStatusToolbarView ( post: post)
145154 }
146- ToolbarItemGroup ( placement: . navigationBarTrailing) {
147- Button ( action: {
148- if model. account. isLoggedIn {
149- publishPost ( )
155+ ToolbarItem ( placement: . primaryAction) {
156+ Menu ( content: {
157+ if post. status == PostStatus . local. rawValue {
158+ Menu ( content: {
159+ Label ( " Publish to… " , systemImage: " paperplane " )
160+ Button ( action: {
161+ if model. account. isLoggedIn {
162+ post. collectionAlias = nil
163+ publishPost ( )
164+ } else {
165+ self . model. isPresentingSettingsView = true
166+ }
167+ } , label: {
168+ Text ( " \( model. account. server == " https://write.as " ? " Anonymous " : " Drafts " ) " )
169+ } )
170+ ForEach ( collections) { collection in
171+ Button ( action: {
172+ if model. account. isLoggedIn {
173+ post. collectionAlias = collection. alias
174+ publishPost ( )
175+ } else {
176+ self . model. isPresentingSettingsView = true
177+ }
178+ } , label: {
179+ Text ( " \( collection. title) " )
180+ } )
181+ }
182+ } , label: {
183+ Label ( " Publish… " , systemImage: " paperplane " )
184+ } )
150185 } else {
151- self . model. isPresentingSettingsView = true
186+ Button ( action: {
187+ if model. account. isLoggedIn {
188+ publishPost ( )
189+ } else {
190+ self . model. isPresentingSettingsView = true
191+ }
192+ } , label: {
193+ Label ( " Publish " , systemImage: " paperplane " )
194+ } )
195+ . disabled (
196+ post. status ==
197+ PostStatus . published. rawValue ||
198+ !model. hasNetworkConnection ||
199+ post. body. count == 0
200+ )
201+ }
202+ Button ( action: {
203+ sharePost ( )
204+ } , label: {
205+ Label ( " Share " , systemImage: " square.and.arrow.up " )
206+ } )
207+ . disabled ( post. postId == nil )
208+ // Button(action: {
209+ // print("Tapped 'Delete...' button")
210+ // }, label: {
211+ // Label("Delete…", systemImage: "trash")
212+ // })
213+ if model. account. isLoggedIn && post. status != PostStatus . local. rawValue {
214+ Section ( header: Text ( " Move To Collection " ) ) {
215+ Label ( " Move to: " , systemImage: " arrowshape.zigzag.right " )
216+ Picker ( selection: $selectedCollection, label: Text ( " Move to… " ) ) {
217+ Text (
218+ " \( model. account. server == " https://write.as " ? " Anonymous " : " Drafts " ) "
219+ ) . tag ( nil as WFACollection ? )
220+ ForEach ( collections) { collection in
221+ Text ( " \( collection. title) " ) . tag ( collection as WFACollection ? )
222+ }
223+ }
224+ }
152225 }
153226 } , label: {
154- Image ( systemName: " paperplane " )
155- } )
156- . disabled (
157- post. status == PostStatus . published. rawValue || !model. hasNetworkConnection || post. body. count == 0
158- )
159- Button ( action: {
160- sharePost ( )
161- } , label: {
162- Image ( systemName: " square.and.arrow.up " )
227+ Image ( systemName: " ellipsis.circle " )
163228 } )
164- . disabled ( post. postId == nil )
165229 }
166230 }
167231 . onChange ( of: post. hasNewerRemoteCopy, perform: { _ in
@@ -181,6 +245,17 @@ struct PostEditorView: View {
181245 }
182246 }
183247 } )
248+ . onChange ( of: selectedCollection, perform: { [ selectedCollection] newCollection in
249+ if post. collectionAlias == newCollection? . alias {
250+ return
251+ } else {
252+ post. collectionAlias = newCollection? . alias
253+ model. move ( post: post, from: selectedCollection, to: newCollection)
254+ }
255+ } )
256+ . onAppear ( perform: {
257+ self . selectedCollection = collections. first { $0. alias == post. collectionAlias }
258+ } )
184259 . onDisappear ( perform: {
185260 if post. title. count == 0
186261 && post. body. count == 0
0 commit comments