feat: Add save to post actions
This commit is contained in:
1 parent
11c36e5187
commit
a363fe3baf
1 file changed
+28
-9
@@ -5,6 +5,8 @@
|
|||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import {
|
import {
|
||||||
|
Bookmark,
|
||||||
|
BookmarkSlash,
|
||||||
ChatBubbleOvalLeft,
|
ChatBubbleOvalLeft,
|
||||||
EllipsisHorizontal,
|
EllipsisHorizontal,
|
||||||
Icon,
|
Icon,
|
||||||
@@ -19,6 +21,7 @@
|
|||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { user, authData } from '$lib/lemmy.js'
|
import { user, authData } from '$lib/lemmy.js'
|
||||||
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
|
|
||||||
@@ -32,17 +35,27 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function youtubeToPiped(url: string): string {
|
async function save(post: PostView) {
|
||||||
const youtubeDomainsRegex =
|
if (!$authData) return
|
||||||
/^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\//i
|
|
||||||
|
|
||||||
if (youtubeDomainsRegex.test(url)) {
|
const saved = post.saved
|
||||||
return url
|
|
||||||
.replace(youtubeDomainsRegex, '$1$2invidious.io.lol/')
|
post.saved = !saved
|
||||||
.replace('www.', '')
|
|
||||||
|
try {
|
||||||
|
await getClient().savePost({
|
||||||
|
auth: $authData.token,
|
||||||
|
post_id: post.post.id,
|
||||||
|
save: !saved,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
post.saved = saved
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: error as any,
|
||||||
|
type: ToastType.error,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -85,6 +98,12 @@
|
|||||||
<Icon src={Square2Stack} width={16} mini />
|
<Icon src={Square2Stack} width={16} mini />
|
||||||
Copy Link
|
Copy Link
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
{#if $authData?.token}
|
||||||
|
<MenuButton on:click={() => save(post)}>
|
||||||
|
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
|
||||||
|
{post.saved ? 'Unsave' : 'Save'}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
{#if $user?.person.id == post.post.creator_id}
|
{#if $user?.person.id == post.post.creator_id}
|
||||||
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||||
<Icon src={Trash} width={16} mini />
|
<Icon src={Trash} width={16} mini />
|
||||||
|
|||||||
Reference in new issue
Block a user