misc: use bindings to show updated data easily

This commit is contained in:
Xyphyn committed 2023-08-12 10:11:39 -07:00
1 parent 4646a59ddf
commit dca0edf0b1
8 files changed
+63 -58

No files matched your search

@@ -153,7 +153,7 @@
{#if actions} {#if actions}
<div class="flex flex-row gap-2 items-center"> <div class="flex flex-row gap-2 items-center">
<CommentActions <CommentActions
comment={node.comment_view} bind:comment={node.comment_view}
bind:replying bind:replying
on:edit={() => (editing = true)} on:edit={() => (editing = true)}
/> />
@@ -78,7 +78,7 @@
<span class="text-xs">Reply</span> <span class="text-xs">Reply</span>
</Button> </Button>
{#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))} {#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))}
<CommentModerationMenu item={comment} /> <CommentModerationMenu bind:item={comment} />
{/if} {/if}
<Menu <Menu
let:toggleOpen let:toggleOpen
@@ -109,7 +109,7 @@
op={post.creator_id == node.comment_view.creator.id} op={post.creator_id == node.comment_view.creator.id}
> >
{#if node.children?.length > 0} {#if node.children?.length > 0}
<svelte:self {post} nodes={node.children} isParent={false} /> <svelte:self {post} bind:nodes={node.children} isParent={false} />
{/if} {/if}
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0} {#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<div <div
+2 -5
View File
@@ -101,7 +101,7 @@
class:opacity-100={loaded} class:opacity-100={loaded}
width={512} width={512}
height={300} height={300}
class:blur-3xl={post.post.nsfw} class:blur-3xl={post.post.nsfw && $userSettings.nsfwBlur}
on:load={() => (loaded = true)} on:load={() => (loaded = true)}
/> />
</picture> </picture>
@@ -129,11 +129,8 @@
{/if} {/if}
{#if actions} {#if actions}
<PostActions <PostActions
{post} bind:post
on:edit={(e) => { on:edit={(e) => {
post.post.name = e.detail.post.name
post.post.body = e.detail.post.body
post.post.url = e.detail.post.url
toast({ toast({
content: 'The post was edited successfully.', content: 'The post was edited successfully.',
type: 'success', type: 'success',
@@ -59,7 +59,7 @@
} }
async function save(post: PostView) { async function save(post: PostView) {
if (!$profile?.jwt) return if (!$profile?.jwt) return false
const saved = post.saved const saved = post.saved
@@ -79,6 +79,8 @@
type: 'error', type: 'error',
}) })
} }
return post.saved
} }
const dispatcher = createEventDispatcher<{ edit: PostView }>() const dispatcher = createEventDispatcher<{ edit: PostView }>()
@@ -119,7 +121,7 @@
</Button> </Button>
<div class="ml-auto" /> <div class="ml-auto" />
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))} {#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
<ModerationMenu item={post} community={post.community} /> <ModerationMenu bind:item={post} community={post.community} />
{/if} {/if}
<Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen> <Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen>
<Button <Button
@@ -166,7 +168,7 @@
Copy Link Copy Link
</MenuButton> </MenuButton>
{#if $profile?.jwt} {#if $profile?.jwt}
<MenuButton on:click={() => save(post)}> <MenuButton on:click={async () => (post.saved = await save(post))}>
<Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini /> <Icon src={post.saved ? BookmarkSlash : Bookmark} width={16} mini />
{post.saved ? 'Unsave' : 'Save'} {post.saved ? 'Unsave' : 'Save'}
</MenuButton> </MenuButton>
+2
View File
@@ -31,6 +31,7 @@ interface Settings {
notifRate: number notifRate: number
} }
displayNames: boolean displayNames: boolean
nsfwBlur: boolean
} }
const defaultSettings: Settings = { const defaultSettings: Settings = {
@@ -61,6 +62,7 @@ const defaultSettings: Settings = {
notifRate: 10 * 60 * 1000, notifRate: 10 * 60 * 1000,
}, },
displayNames: true, displayNames: true,
nsfwBlur: true,
} }
export const userSettings = writable(defaultSettings) export const userSettings = writable(defaultSettings)
@@ -22,15 +22,12 @@
export let data export let data
const postData = data.post.post_view
const post = postData.post
onMount(async () => { onMount(async () => {
if (!postData.read && $profile?.jwt) { if (!data.post.post_view.read && $profile?.jwt) {
getClient().markPostAsRead({ getClient().markPostAsRead({
auth: $profile.jwt, auth: $profile.jwt,
read: true, read: true,
post_id: post.id, post_id: data.post.post_view.post.id,
}) })
} }
}) })
@@ -60,11 +57,11 @@
<title>{data.post.post_view.post.name}</title> <title>{data.post.post_view.post.name}</title>
<meta property="og:title" content={data.post.post_view.post.name} /> <meta property="og:title" content={data.post.post_view.post.name} />
<meta property="og:url" content={$page.url.toString()} /> <meta property="og:url" content={$page.url.toString()} />
{#if isImage(post.url)} {#if isImage(data.post.post_view.post.url)}
<meta property="og:image" content={post.url} /> <meta property="og:image" content={data.post.post_view.post.url} />
{/if} {/if}
{#if post.body} {#if data.post.post_view.post.body}
<meta property="og:description" content={post.body} /> <meta property="og:description" content={data.post.post_view.post.body} />
{/if} {/if}
</svelte:head> </svelte:head>
@@ -86,72 +83,68 @@
{/if} {/if}
<PostMeta <PostMeta
community={postData.community} community={data.post.post_view.community}
user={postData.creator} user={data.post.post_view.creator}
upvotes={postData.counts.upvotes} upvotes={data.post.post_view.counts.upvotes}
downvotes={postData.counts.downvotes} downvotes={data.post.post_view.counts.downvotes}
deleted={postData.post.deleted} deleted={data.post.post_view.post.deleted}
removed={postData.post.removed} removed={data.post.post_view.post.removed}
locked={postData.post.locked} locked={data.post.post_view.post.locked}
featured={postData.post.featured_community || postData.post.featured_local} featured={data.post.post_view.post.featured_community ||
nsfw={postData.post.nsfw} data.post.post_view.post.featured_local}
published={new Date(postData.post.published + 'Z')} nsfw={data.post.post_view.post.nsfw}
saved={postData.saved} published={new Date(data.post.post_view.post.published + 'Z')}
saved={data.post.post_view.saved}
/> />
<h1 class="font-bold text-lg">{post.name}</h1> <h1 class="font-bold text-lg">{data.post.post_view.post.name}</h1>
{#if isImage(post.url)} {#if isImage(data.post.post_view.post.url)}
<img <img
src={post.url} src={data.post.post_view.post.url}
alt={post.name} alt={data.post.post_view.post.name}
class="rounded-md max-w-screen max-h-[80svh] mx-auto" class="rounded-md max-w-screen max-h-[80svh] mx-auto"
/> />
{:else if isVideo(post.url)} {:else if isVideo(data.post.post_view.post.url)}
<!-- svelte-ignore a11y-media-has-caption --> <!-- svelte-ignore a11y-media-has-caption -->
<video class="rounded-md max-w-screen max-h-[80svh] mx-auto" controls> <video class="rounded-md max-w-screen max-h-[80svh] mx-auto" controls>
<source src={post.url} /> <source src={data.post.post_view.post.url} />
</video> </video>
{:else if post.url && !post.thumbnail_url} {:else if data.post.post_view.post.url && !data.post.post_view.post.thumbnail_url}
<a <a
href={post.url} href={data.post.post_view.post.url}
class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs" class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs"
> >
{post.url} {data.post.post_view.post.url}
</a> </a>
{:else if post.thumbnail_url && post.url} {:else if data.post.post_view.post.thumbnail_url && data.post.post_view.post.url}
<PostLink <PostLink
thumbnail_url={post.thumbnail_url} thumbnail_url={data.post.post_view.post.thumbnail_url}
url={post.url} url={data.post.post_view.post.url}
nsfw={post.nsfw} nsfw={data.post.post_view.post.nsfw}
/> />
{/if} {/if}
{#if post.body} {#if data.post.post_view.post.body}
<div <div
class="bg-slate-100 border border-slate-200 dark:border-zinc-800 class="bg-slate-100 border border-slate-200 dark:border-zinc-800
dark:bg-zinc-900 p-2 text-sm rounded-md leading-[22px]" dark:bg-zinc-900 p-2 text-sm rounded-md leading-[22px]"
> >
<Markdown source={post.body} /> <Markdown source={data.post.post_view.post.body} />
</div> </div>
{/if} {/if}
<div class="w-full relative"> <div class="w-full relative">
<PostActions <PostActions
post={data.post.post_view} bind:post={data.post.post_view}
on:edit={(e) => { on:edit={() =>
post.name = e.detail.post.name
post.body = e.detail.post.body
post.url = e.detail.post.url
toast({ toast({
content: 'The post was edited successfully.', content: 'The post was edited successfully.',
type: 'success', type: 'success',
}) })}
}}
/> />
</div> </div>
</div> </div>
<div class="mt-4 flex flex-col gap-2"> <div class="mt-4 flex flex-col gap-2">
<div class="font-bold text-lg"> <div class="font-bold text-lg">
Comments <span class="text-sm font-normal ml-2 opacity-80"> Comments <span class="text-sm font-normal ml-2 opacity-80">
{postData.counts.comments} {data.post.post_view.counts.comments}
</span> </span>
</div> </div>
<MultiSelect <MultiSelect
@@ -172,13 +165,13 @@
{:then comments} {:then comments}
{#if $profile?.user} {#if $profile?.user}
<CommentForm <CommentForm
postId={post.id} postId={data.post.post_view.post.id}
on:comment={(comment) => on:comment={(comment) =>
(comments.comments = [ (comments.comments = [
comment.detail.comment_view, comment.detail.comment_view,
...comments.comments, ...comments.comments,
])} ])}
locked={postData.post.locked} locked={data.post.post_view.post.locked}
/> />
{/if} {/if}
{#await buildCommentsTreeAsync(comments.comments)} {#await buildCommentsTreeAsync(comments.comments)}
@@ -186,7 +179,11 @@
<Spinner width={36} /> <Spinner width={36} />
</div> </div>
{:then comments} {:then comments}
<Comments {post} nodes={comments} isParent={true} /> <Comments
post={data.post.post_view.post}
nodes={comments}
isParent={true}
/>
{/await} {/await}
{:catch} {:catch}
<div class="bg-red-500/10 border border-red-500 rounded-md p-4"> <div class="bg-red-500/10 border border-red-500 rounded-md p-4">
+7
View File
@@ -101,6 +101,13 @@
bind:selected={$userSettings.showCompactPosts} bind:selected={$userSettings.showCompactPosts}
/> />
</Setting> </Setting>
<Setting>
<Checkbox bind:checked={$userSettings.nsfwBlur} slot="title">
NSFW blur
</Checkbox>
<span slot="description">Blur images of NSFW content.</span>
</Setting>
<SectionTitle class="mt-4">Instances</SectionTitle> <SectionTitle class="mt-4">Instances</SectionTitle>
<Setting> <Setting>
<span slot="title">Show instances</span> <span slot="title">Show instances</span>