From 61c420fc0a6fc9919256adc1631b7d1cf3596ded Mon Sep 17 00:00:00 2001 From: Bosco Ho Date: Tue, 3 Oct 2023 18:16:49 -0700 Subject: [PATCH] FIx issue where swipey view actions publishes updates on background thread. --- Mlem/Extensions/Swipey Actions.swift | 6 ++--- Mlem/Views/Shared/Comments/Comment Item.swift | 24 +++++++++++++++---- Mlem/Views/Shared/Posts/Feed Post.swift | 18 +++++++++++--- .../Tabs/Search/CommunityResultView.swift | 6 ++++- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Mlem/Extensions/Swipey Actions.swift b/Mlem/Extensions/Swipey Actions.swift index 15761f548..b58099bd6 100644 --- a/Mlem/Extensions/Swipey Actions.swift +++ b/Mlem/Extensions/Swipey Actions.swift @@ -18,7 +18,7 @@ public struct SwipeAction { let symbol: Symbol let color: Color - let action: () async -> Void + let action: () -> Void } // MARK: - @@ -201,9 +201,7 @@ struct SwipeyView: ViewModifier { reset() - Task(priority: .userInitiated) { - await swipeAction(at: finalDragPosition)?.action() - } + swipeAction(at: finalDragPosition)?.action() } private func reset() { diff --git a/Mlem/Views/Shared/Comments/Comment Item.swift b/Mlem/Views/Shared/Comments/Comment Item.swift index d1bf0ec87..9e7b2b60c 100644 --- a/Mlem/Views/Shared/Comments/Comment Item.swift +++ b/Mlem/Views/Shared/Comments/Comment Item.swift @@ -227,7 +227,11 @@ extension CommentItem { SwipeAction( symbol: .init(emptyName: emptyVoteSymbolName, fillName: upvoteSymbolName), color: .upvoteColor, - action: upvote + action: { + Task { + await upvote() + } + } ) } @@ -236,7 +240,11 @@ extension CommentItem { return SwipeAction( symbol: .init(emptyName: emptyDownvoteSymbolName, fillName: downvoteSymbolName), color: .downvoteColor, - action: downvote + action: { + Task { + await downvote() + } + } ) } @@ -244,7 +252,11 @@ extension CommentItem { SwipeAction( symbol: .init(emptyName: emptySaveSymbolName, fillName: saveSymbolName), color: .saveColor, - action: saveComment + action: { + Task { + await saveComment() + } + } ) } @@ -252,7 +264,11 @@ extension CommentItem { SwipeAction( symbol: .init(emptyName: emptyReplySymbolName, fillName: replySymbolName), color: .accentColor, - action: replyToCommentAsyncWrapper + action: { + Task { + await replyToCommentAsyncWrapper() + } + } ) } diff --git a/Mlem/Views/Shared/Posts/Feed Post.swift b/Mlem/Views/Shared/Posts/Feed Post.swift index 8e67649b6..9e365b99b 100644 --- a/Mlem/Views/Shared/Posts/Feed Post.swift +++ b/Mlem/Views/Shared/Posts/Feed Post.swift @@ -433,7 +433,11 @@ extension FeedPost { return SwipeAction( symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName), color: .upvoteColor, - action: upvotePost + action: { + Task { + await upvotePost() + } + } ) } @@ -446,7 +450,11 @@ extension FeedPost { return SwipeAction( symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName), color: .downvoteColor, - action: downvotePost + action: { + Task { + await downvotePost() + } + } ) } @@ -457,7 +465,11 @@ extension FeedPost { return SwipeAction( symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName), color: .saveColor, - action: savePost + action: { + Task { + await savePost() + } + } ) } diff --git a/Mlem/Views/Tabs/Search/CommunityResultView.swift b/Mlem/Views/Tabs/Search/CommunityResultView.swift index f60db7fd6..800c79c76 100644 --- a/Mlem/Views/Tabs/Search/CommunityResultView.swift +++ b/Mlem/Views/Tabs/Search/CommunityResultView.swift @@ -23,7 +23,11 @@ struct CommunityResultView: View { return SwipeAction( symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName), color: community.subscribed ? .red : .green, - action: subscribe + action: { + Task { + await subscribe() + } + } ) }