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
  • Loading branch information
boscojwho authored Oct 4, 2023
1 parent 78351b1 commit 05ef83c
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 05ef83c

Please sign in to comment.