@@ -2,12 +2,21 @@ import SwiftUI
2
2
3
3
struct PostEditorView : View {
4
4
@EnvironmentObject var model : WriteFreelyModel
5
+ @Environment ( \. managedObjectContext) var moc
5
6
@Environment ( \. horizontalSizeClass) var horizontalSizeClass
6
7
@Environment ( \. presentationMode) var presentationMode
8
+
7
9
@ObservedObject var post : WFAPost
8
10
@State private var updatingTitleFromServer : Bool = false
9
11
@State private var updatingBodyFromServer : Bool = false
10
12
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
+
11
20
var body : some View {
12
21
VStack {
13
22
if post. hasNewerRemoteCopy {
@@ -143,25 +152,80 @@ struct PostEditorView: View {
143
152
ToolbarItem ( placement: . principal) {
144
153
PostEditorStatusToolbarView ( post: post)
145
154
}
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
+ } )
150
185
} 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
+ }
152
225
}
153
226
} , 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 " )
163
228
} )
164
- . disabled ( post. postId == nil )
165
229
}
166
230
}
167
231
. onChange ( of: post. hasNewerRemoteCopy, perform: { _ in
@@ -181,6 +245,17 @@ struct PostEditorView: View {
181
245
}
182
246
}
183
247
} )
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
+ } )
184
259
. onDisappear ( perform: {
185
260
if post. title. count == 0
186
261
&& post. body. count == 0
0 commit comments