Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx issue where swipey view actions publishes updates on background t… #694

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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