Skip to content

Commit

Permalink
FIx issue where swipey view actions publishes updates on background t… (
Browse files Browse the repository at this point in the history
#694)

Commit:
05ef83c [05ef83c]
  • Loading branch information
boscojwho committed Oct 11, 2023
1 parent faa224d commit 5e91e98
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
6 changes: 2 additions & 4 deletions Mlem/Extensions/Swipey Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct SwipeAction {

let symbol: Symbol
let color: Color
let action: () async -> Void
let action: () -> Void
}

// MARK: -
Expand Down Expand Up @@ -201,9 +201,7 @@ struct SwipeyView: ViewModifier {

reset()

Task(priority: .userInitiated) {
await swipeAction(at: finalDragPosition)?.action()
}
swipeAction(at: finalDragPosition)?.action()
}

private func reset() {
Expand Down
24 changes: 20 additions & 4 deletions Mlem/Views/Shared/Comments/Comment Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ extension CommentItem {
SwipeAction(
symbol: .init(emptyName: emptyVoteSymbolName, fillName: upvoteSymbolName),
color: .upvoteColor,
action: upvote
action: {
Task {
await upvote()
}
}
)
}

Expand All @@ -236,23 +240,35 @@ extension CommentItem {
return SwipeAction(
symbol: .init(emptyName: emptyDownvoteSymbolName, fillName: downvoteSymbolName),
color: .downvoteColor,
action: downvote
action: {
Task {
await downvote()
}
}
)
}

var saveSwipeAction: SwipeAction {
SwipeAction(
symbol: .init(emptyName: emptySaveSymbolName, fillName: saveSymbolName),
color: .saveColor,
action: saveComment
action: {
Task {
await saveComment()
}
}
)
}

var replySwipeAction: SwipeAction? {
SwipeAction(
symbol: .init(emptyName: emptyReplySymbolName, fillName: replySymbolName),
color: .accentColor,
action: replyToCommentAsyncWrapper
action: {
Task {
await replyToCommentAsyncWrapper()
}
}
)
}

Expand Down
18 changes: 15 additions & 3 deletions Mlem/Views/Shared/Posts/Feed Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ extension FeedPost {
return SwipeAction(
symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName),
color: .upvoteColor,
action: upvotePost
action: {
Task {
await upvotePost()
}
}
)
}

Expand All @@ -446,7 +450,11 @@ extension FeedPost {
return SwipeAction(
symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName),
color: .downvoteColor,
action: downvotePost
action: {
Task {
await downvotePost()
}
}
)
}

Expand All @@ -457,7 +465,11 @@ extension FeedPost {
return SwipeAction(
symbol: .init(emptyName: emptySymbolName, fillName: fullSymbolName),
color: .saveColor,
action: savePost
action: {
Task {
await savePost()
}
}
)
}

Expand Down
6 changes: 5 additions & 1 deletion Mlem/Views/Tabs/Search/CommunityResultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
)
}

Expand Down

0 comments on commit 5e91e98

Please sign in to comment.