From 5f4c32fe2cec7279d7a297b779376e075245f369 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Thu, 13 Jul 2023 19:09:55 -0700 Subject: [PATCH] fix: Fix if vote is undefined --- src/lib/components/lemmy/Post.svelte | 23 ++++++++++++++++++++--- src/lib/components/lemmy/PostVote.svelte | 4 ++++ src/lib/lemmy.ts | 3 --- svelte.config.js | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/lib/components/lemmy/Post.svelte b/src/lib/components/lemmy/Post.svelte index f51e9bbc..a4c6d2d2 100644 --- a/src/lib/components/lemmy/Post.svelte +++ b/src/lib/components/lemmy/Post.svelte @@ -35,6 +35,19 @@ post_id: postRes.post.id, }) } + + function youtubeToPiped(url: string): string { + const youtubeDomainsRegex = + /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\//i + + if (youtubeDomainsRegex.test(url)) { + return url + .replace(youtubeDomainsRegex, '$1$2invidious.io.lol/') + .replace('www.', '') + } + + return url + } @@ -87,14 +100,18 @@ src="{postRes.post.url}?thumbnail=1024&format=webp" alt={postRes.post.name} class="rounded-md max-h-[32rem] w-full max-w-full" + loading="lazy" /> {:else if postRes.post.embed_video_url}
- + {#if postRes.post.embed_video_url} + + {/if}
{:else if postRes.post.thumbnail_url}
diff --git a/src/lib/components/lemmy/PostVote.svelte b/src/lib/components/lemmy/PostVote.svelte index ca32e001..e502d472 100644 --- a/src/lib/components/lemmy/PostVote.svelte +++ b/src/lib/components/lemmy/PostVote.svelte @@ -12,6 +12,8 @@ async function upvote() { if (!$authData) return + if (vote == undefined) vote = 0 + const upvoted = vote == 1 if (vote == -1) { @@ -36,6 +38,8 @@ async function downvote() { if (!$authData) return + if (vote == undefined) vote = 0 + const upvoted = vote == -1 if (vote == -1) { diff --git a/src/lib/lemmy.ts b/src/lib/lemmy.ts index 40097b11..e992a0f1 100644 --- a/src/lib/lemmy.ts +++ b/src/lib/lemmy.ts @@ -77,11 +77,8 @@ authData.subscribe(async (data) => { const site = await getClient().getSite({ auth: data.token, }) - if (!site?.my_user) throw Error('Missing user') - user.set({ ...site.my_user.local_user_view, unreads: 0 }) - if (typeof localStorage != 'undefined') { localStorage.setItem('user', JSON.stringify(data)) } diff --git a/svelte.config.js b/svelte.config.js index 12aa3119..590a08b6 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -15,7 +15,7 @@ const config = { csp: { directives: { 'script-src': ['self'], - 'object-src': ['none'], + // 'object-src': ['none'], 'base-uri': ['none'] }, mode: 'nonce'