diff --git a/CHANGELOG.md b/CHANGELOG.md index efe1575..a1650a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Mac] Fixed a bug where alerts weren't presented for login errors. - [Mac] Fixed some build warnings in the project. - [Mac] Bumped WriteFreely package to v0.3.6 to handle decoding of fractional seconds in dates. +- [Mac] Fixed a bug that prevented a remotely-edited post from updating until you navigated away and back. ## [1.0.15-ios] - 2022-01-15 diff --git a/Shared/Extensions/WriteFreelyModel+API.swift b/Shared/Extensions/WriteFreelyModel+API.swift index 36e657a..3a9010b 100644 --- a/Shared/Extensions/WriteFreelyModel+API.swift +++ b/Shared/Extensions/WriteFreelyModel+API.swift @@ -142,7 +142,9 @@ extension WriteFreelyModel { } // We're starting the network request. DispatchQueue.main.async { + #if os(iOS) self.selectedPost = post + #endif self.isProcessingRequest = true } loggedInClient.getPost(byId: postId, completion: updateFromServerHandler) diff --git a/Shared/Extensions/WriteFreelyModel+APIHandlers.swift b/Shared/Extensions/WriteFreelyModel+APIHandlers.swift index 3163676..a7e9918 100644 --- a/Shared/Extensions/WriteFreelyModel+APIHandlers.swift +++ b/Shared/Extensions/WriteFreelyModel+APIHandlers.swift @@ -221,11 +221,18 @@ extension WriteFreelyModel { // See: https://github.com/writeas/writefreely-swift/issues/20 do { let fetchedPost = try result.get() + #if os(iOS) guard let cachedPost = self.selectedPost else { return } + #else + guard let cachedPost = self.editor.postToUpdate else { return } + #endif importData(from: fetchedPost, into: cachedPost) cachedPost.hasNewerRemoteCopy = false DispatchQueue.main.async { LocalStorageManager.standard.saveContext() + #if os(macOS) + self.selectedPost = cachedPost + #endif } } catch { self.currentError = AppError.genericError(error.localizedDescription) diff --git a/Shared/PostEditor/PostEditorModel.swift b/Shared/PostEditor/PostEditorModel.swift index 29a3bc8..b8bda48 100644 --- a/Shared/PostEditor/PostEditorModel.swift +++ b/Shared/PostEditor/PostEditorModel.swift @@ -12,6 +12,10 @@ struct PostEditorModel { @AppStorage(WFDefaults.selectedCollectionURL, store: UserDefaults.shared) var selectedCollectionURL: URL? @AppStorage(WFDefaults.lastDraftURL, store: UserDefaults.shared) var lastDraftURL: URL? + #if os(macOS) + var postToUpdate: WFAPost? + #endif + func saveLastDraft(_ post: WFAPost) { self.lastDraftURL = post.status != PostStatus.published.rawValue ? post.objectID.uriRepresentation() : nil } diff --git a/Shared/PostEditor/PostEditorStatusToolbarView.swift b/Shared/PostEditor/PostEditorStatusToolbarView.swift index be49544..8d98614 100644 --- a/Shared/PostEditor/PostEditorStatusToolbarView.swift +++ b/Shared/PostEditor/PostEditorStatusToolbarView.swift @@ -16,7 +16,11 @@ struct PostEditorStatusToolbarView: View { .font(.callout) .foregroundColor(.secondary) Button(action: { + model.editor.postToUpdate = post model.updateFromServer(post: post) + DispatchQueue.main.async { + model.selectedPost = nil + } }, label: { Image(systemName: "square.and.arrow.down") }) diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index 7177fb9..cba8823 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -1278,7 +1278,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 704; + CURRENT_PROJECT_VERSION = 707; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1305,7 +1305,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 704; + CURRENT_PROJECT_VERSION = 707; DEVELOPMENT_TEAM = TPPAB4YBA6; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES;