misc: switch to universal save function

This commit is contained in:
Xyphyn committed 2023-08-19 13:42:43 -07:00
1 parent 435c529abc
commit 5de92f7ae3
3 files changed
+75 -50

No files matched your search

@@ -32,33 +32,11 @@
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import { save } from '$lib/lemmy/contentview.js'
export let comment: CommentView
export let replying: boolean = false
async function save() {
if (!$profile?.jwt) return
const saved = comment.saved
comment.saved = !saved
try {
await getClient().saveComment({
auth: $profile.jwt,
comment_id: comment.comment.id,
save: !saved,
})
} catch (error) {
comment.saved = saved
toast({
content: error as any,
type: 'error',
})
}
}
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
</script>
@@ -110,7 +88,12 @@
<span>Edit</span>
</MenuButton>
{/if}
<MenuButton on:click={save}>
<MenuButton
on:click={async () => {
if ($profile?.jwt)
comment.saved = await save(comment, !comment.saved, $profile.jwt)
}}
>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
</MenuButton>
@@ -31,6 +31,7 @@
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import { save } from '$lib/lemmy/contentview.js'
export let post: PostView
@@ -58,31 +59,6 @@
}
}
async function save(post: PostView) {
if (!$profile?.jwt) return false
const saved = post.saved
post.saved = !saved
try {
await getClient().savePost({
auth: $profile.jwt,
post_id: post.post.id,
save: !saved,
})
} catch (error) {
post.saved = saved
toast({
content: error as any,
type: 'error',
})
}
return post.saved
}
const dispatcher = createEventDispatcher<{ edit: PostView }>()
let editing = false
@@ -180,7 +156,12 @@
Copy Link
</MenuButton>
{#if $profile?.jwt}
<MenuButton on:click={async () => (post.saved = await save(post))}>
<MenuButton
on:click={async () => {
if ($profile?.jwt)
post.saved = await save(post, !post.saved, $profile.jwt)
}}
>
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
{post.saved ? 'Unsave' : 'Save'}
</MenuButton>