Bugfix: post not refreshed when updated from server (#246)

This commit is contained in:
Angelo Stavrow 2023-04-16 06:08:32 -04:00 committed by GitHub
parent 39a78c56b6
commit 79b4301988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 2 deletions

View File

@ -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 a bug where alerts weren't presented for login errors.
- [Mac] Fixed some build warnings in the project. - [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] 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 ## [1.0.15-ios] - 2022-01-15

View File

@ -142,7 +142,9 @@ extension WriteFreelyModel {
} }
// We're starting the network request. // We're starting the network request.
DispatchQueue.main.async { DispatchQueue.main.async {
#if os(iOS)
self.selectedPost = post self.selectedPost = post
#endif
self.isProcessingRequest = true self.isProcessingRequest = true
} }
loggedInClient.getPost(byId: postId, completion: updateFromServerHandler) loggedInClient.getPost(byId: postId, completion: updateFromServerHandler)

View File

@ -221,11 +221,18 @@ extension WriteFreelyModel {
// See: https://github.com/writeas/writefreely-swift/issues/20 // See: https://github.com/writeas/writefreely-swift/issues/20
do { do {
let fetchedPost = try result.get() let fetchedPost = try result.get()
#if os(iOS)
guard let cachedPost = self.selectedPost else { return } guard let cachedPost = self.selectedPost else { return }
#else
guard let cachedPost = self.editor.postToUpdate else { return }
#endif
importData(from: fetchedPost, into: cachedPost) importData(from: fetchedPost, into: cachedPost)
cachedPost.hasNewerRemoteCopy = false cachedPost.hasNewerRemoteCopy = false
DispatchQueue.main.async { DispatchQueue.main.async {
LocalStorageManager.standard.saveContext() LocalStorageManager.standard.saveContext()
#if os(macOS)
self.selectedPost = cachedPost
#endif
} }
} catch { } catch {
self.currentError = AppError.genericError(error.localizedDescription) self.currentError = AppError.genericError(error.localizedDescription)

View File

@ -12,6 +12,10 @@ struct PostEditorModel {
@AppStorage(WFDefaults.selectedCollectionURL, store: UserDefaults.shared) var selectedCollectionURL: URL? @AppStorage(WFDefaults.selectedCollectionURL, store: UserDefaults.shared) var selectedCollectionURL: URL?
@AppStorage(WFDefaults.lastDraftURL, store: UserDefaults.shared) var lastDraftURL: URL? @AppStorage(WFDefaults.lastDraftURL, store: UserDefaults.shared) var lastDraftURL: URL?
#if os(macOS)
var postToUpdate: WFAPost?
#endif
func saveLastDraft(_ post: WFAPost) { func saveLastDraft(_ post: WFAPost) {
self.lastDraftURL = post.status != PostStatus.published.rawValue ? post.objectID.uriRepresentation() : nil self.lastDraftURL = post.status != PostStatus.published.rawValue ? post.objectID.uriRepresentation() : nil
} }

View File

@ -16,7 +16,11 @@ struct PostEditorStatusToolbarView: View {
.font(.callout) .font(.callout)
.foregroundColor(.secondary) .foregroundColor(.secondary)
Button(action: { Button(action: {
model.editor.postToUpdate = post
model.updateFromServer(post: post) model.updateFromServer(post: post)
DispatchQueue.main.async {
model.selectedPost = nil
}
}, label: { }, label: {
Image(systemName: "square.and.arrow.down") Image(systemName: "square.and.arrow.down")
}) })

View File

@ -1278,7 +1278,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 704; CURRENT_PROJECT_VERSION = 707;
DEVELOPMENT_TEAM = TPPAB4YBA6; DEVELOPMENT_TEAM = TPPAB4YBA6;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@ -1305,7 +1305,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 704; CURRENT_PROJECT_VERSION = 707;
DEVELOPMENT_TEAM = TPPAB4YBA6; DEVELOPMENT_TEAM = TPPAB4YBA6;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;