mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Set isProcessingRequest on network request start, unset on end
This commit is contained in:
parent
1feeed7354
commit
3ebfa7a0d1
@ -119,16 +119,28 @@ extension WriteFreelyModel {
|
||||
|
||||
func fetchUserCollections() {
|
||||
guard let loggedInClient = client else { return }
|
||||
// We're starting the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = true
|
||||
}
|
||||
loggedInClient.getUserCollections(completion: fetchUserCollectionsHandler)
|
||||
}
|
||||
|
||||
func fetchUserPosts() {
|
||||
guard let loggedInClient = client else { return }
|
||||
// We're starting the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = true
|
||||
}
|
||||
loggedInClient.getPosts(completion: fetchUserPostsHandler)
|
||||
}
|
||||
|
||||
func publish(post: WFAPost) {
|
||||
guard let loggedInClient = client else { return }
|
||||
// We're starting the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = true
|
||||
}
|
||||
|
||||
if post.language == nil {
|
||||
if let languageCode = Locale.current.languageCode {
|
||||
@ -169,8 +181,10 @@ extension WriteFreelyModel {
|
||||
func updateFromServer(post: WFAPost) {
|
||||
guard let loggedInClient = client else { return }
|
||||
guard let postId = post.postId else { return }
|
||||
// We're starting the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPost = post
|
||||
self.isProcessingRequest = true
|
||||
}
|
||||
if let postCollectionAlias = post.collectionAlias,
|
||||
let postSlug = post.slug {
|
||||
@ -183,6 +197,10 @@ extension WriteFreelyModel {
|
||||
func move(post: WFAPost, from oldCollection: WFACollection?, to newCollection: WFACollection?) {
|
||||
guard let loggedInClient = client,
|
||||
let postId = post.postId else { return }
|
||||
// We're starting the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = true
|
||||
}
|
||||
|
||||
post.collectionAlias = newCollection?.alias
|
||||
loggedInClient.movePost(postId: postId, to: newCollection?.alias, completion: movePostHandler)
|
||||
@ -272,6 +290,10 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func fetchUserCollectionsHandler(result: Result<[WFCollection], Error>) {
|
||||
// We're done with the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = false
|
||||
}
|
||||
do {
|
||||
let fetchedCollections = try result.get()
|
||||
for fetchedCollection in fetchedCollections {
|
||||
@ -295,6 +317,10 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func fetchUserPostsHandler(result: Result<[WFPost], Error>) {
|
||||
// We're done with the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = false
|
||||
}
|
||||
do {
|
||||
var postsToDelete = posts.userPosts.filter { $0.status != PostStatus.local.rawValue }
|
||||
let fetchedPosts = try result.get()
|
||||
@ -337,6 +363,10 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func publishHandler(result: Result<WFPost, Error>) {
|
||||
// We're done with the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = false
|
||||
}
|
||||
// ⚠️ NOTE:
|
||||
// The API does not return a collection alias, so we take care not to overwrite the
|
||||
// cached post's collection alias with the 'nil' value from the fetched post.
|
||||
@ -367,6 +397,10 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func updateFromServerHandler(result: Result<WFPost, Error>) {
|
||||
// We're done with the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = false
|
||||
}
|
||||
// ⚠️ NOTE:
|
||||
// The API does not return a collection alias, so we take care not to overwrite the
|
||||
// cached post's collection alias with the 'nil' value from the fetched post.
|
||||
@ -394,6 +428,10 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func movePostHandler(result: Result<Bool, Error>) {
|
||||
// We're done with the network request.
|
||||
DispatchQueue.main.async {
|
||||
self.isProcessingRequest = false
|
||||
}
|
||||
do {
|
||||
let succeeded = try result.get()
|
||||
if succeeded {
|
||||
|
Loading…
Reference in New Issue
Block a user