misc: Improve performance

This commit is contained in:
Xyphyn committed 2023-07-07 13:08:36 -07:00
1 parent dbbfd04875
commit 6b372fc906
5 files changed
+19 -43

No files matched your search

+2 -2
View File
@@ -8,8 +8,8 @@
<a <a
{href} {href}
class="px-2 py-1 rounded-md {color} flex flex-row items-center class="px-3 py-1 rounded-md {color} flex flex-row items-center
justify-center text-sm transition-all" justify-center text-sm transition-all gap-1"
aria-label={label} aria-label={label}
> >
<slot name="icon" /> <slot name="icon" />
+11 -36
View File
@@ -27,6 +27,7 @@
import { Color } from '$lib/ui/colors.js' import { Color } from '$lib/ui/colors.js'
import { page } from '$app/stores' import { page } from '$app/stores'
import Avatar from '$lib/components/ui/Avatar.svelte' import Avatar from '$lib/components/ui/Avatar.svelte'
import Link from '$lib/components/input/Link.svelte'
let postRes: PostView let postRes: PostView
export { postRes as post } export { postRes as post }
@@ -48,8 +49,7 @@
} }
</script> </script>
<Card class="bg-white flex flex-col overflow-hidden w-full relative"> <Card class="bg-white flex flex-col overflow-hidden w-full relative p-5 gap-2">
<div class="flex flex-col gap-2 bg-white dark:bg-zinc-900 p-4 rounded-md">
<span class="flex flex-row gap-2 text-xs items-center"> <span class="flex flex-row gap-2 text-xs items-center">
<Avatar <Avatar
url={postRes.community.icon} url={postRes.community.icon}
@@ -72,8 +72,6 @@
</span> </span>
</span> </span>
</div> </div>
<div class="ml-auto" />
<span class="opacity-50 capitalize" />
</span> </span>
<a <a
href="/post/{getInstance()}/{postRes.post.id}" href="/post/{getInstance()}/{postRes.post.id}"
@@ -91,56 +89,33 @@
</a> </a>
{/if} {/if}
{#if isImage(postRes.post.url)} {#if isImage(postRes.post.url)}
<a <div class="self-start">
href="/post/{getInstance()}/{postRes.post.id}"
class="inline self-start"
>
<img <img
src={postRes.post.url} src="{postRes.post.url}?thumbnail=1024&format=webp"
alt={postRes.post.name} alt={postRes.post.name}
class="rounded-md max-h-[32rem] w-full max-w-full" class="rounded-md max-h-[32rem] w-full max-w-full"
loading="lazy"
/> />
</a> </div>
{:else if isVideo(postRes.post.url)}
<!-- svelte-ignore a11y-media-has-caption -->
<a
href="/post/{getInstance()}/{postRes.post.id}"
class="inline self-start"
>
<video class="rounded-md max-h-64 max-w-full" preload="metadata">
<source src={postRes.post.url} />
</video>
</a>
{/if} {/if}
{#if postRes.post.body} {#if postRes.post.body}
<p <p
class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800 border class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800
border-slate200 dark:border-zinc-700 rounded-md p-2 mt-2" border border-slate200 dark:border-zinc-700 rounded-md p-2 mt-2"
> >
{postRes.post.body} {postRes.post.body}
</p> </p>
{/if} {/if}
</div> <div class="flex flex-row gap-2 items-center pt-1">
<div class="flex flex-row gap-2 pb-4 px-4">
<PostVote <PostVote
post={postRes.post} post={postRes.post}
vote={postRes.my_vote} vote={postRes.my_vote}
score={postRes.counts.score} score={postRes.counts.score}
/> />
<a <Link color={Color.border} href="/post/{getInstance()}/{postRes.post.id}">
class="flex flex-row items-center gap-1 p-1 px-3 rounded-md <Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200
dark:hover:bg-zinc-700 transition-colors border border-slate-200
dark:border-zinc-700"
href="/post/{getInstance()}/{postRes.post.id}"
>
<Icon src={ChatBubbleOvalLeft} mini width={16} height={16} />
<span class="text-sm">
<FormattedNumber number={postRes.counts.comments} /> <FormattedNumber number={postRes.counts.comments} />
</span> </Link>
</a>
<Menu top absolute class="bottom-0 right-0 m-5 z-10"> <Menu top absolute class="bottom-0 right-0 m-5 z-10">
<Button slot="button" label="Post actions"> <Button slot="button" label="Post actions">
<Icon src={EllipsisHorizontal} width={16} mini /> <Icon src={EllipsisHorizontal} width={16} mini />
+4 -4
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { authData, getClient } from '$lib/lemmy' import { authData, getClient } from '$lib/lemmy'
import { Color } from '$lib/ui/colors.js'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons' import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
@@ -59,8 +60,9 @@
<slot {upvote} {downvote} {vote} {score}> <slot {upvote} {downvote} {vote} {score}>
<div <div
class="flex flex-row items-center gap-1 rounded-md transition-colors class="{Color.border} text-sm rounded-md flex flex-row items-center px-1.5
cursor-pointer border border-slate-200 dark:border-zinc-700 px-1 py-[2px] py-0.5
transition-colors cursor-pointer
{// upvote {// upvote
vote == 1 vote == 1
? 'bg-orange-600/20 text-orange-500' ? 'bg-orange-600/20 text-orange-500'
@@ -73,9 +75,7 @@
<button aria-label="Upvote" class="p-0.5 px-1" on:click={upvote}> <button aria-label="Upvote" class="p-0.5 px-1" on:click={upvote}>
<Icon src={ChevronUp} mini width={20} height={20} /> <Icon src={ChevronUp} mini width={20} height={20} />
</button> </button>
<span class="text-sm">
<FormattedNumber number={score} /> <FormattedNumber number={score} />
</span>
<button aria-label="Downvote" class="p-0.5 px-1" on:click={downvote}> <button aria-label="Downvote" class="p-0.5 px-1" on:click={downvote}>
<Icon src={ChevronDown} mini width={20} height={20} /> <Icon src={ChevronDown} mini width={20} height={20} />
</button> </button>
+1
View File
@@ -9,4 +9,5 @@ export enum Color {
'secondary' = 'hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white fill-black dark:fill-white', 'secondary' = 'hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white fill-black dark:fill-white',
'danger' = 'border border-red-500 bg-red-500 text-white hover:text-red-500 hover:bg-transparent', 'danger' = 'border border-red-500 bg-red-500 text-white hover:text-red-500 hover:bg-transparent',
'dangerSecondary' = 'hover:bg-red-500 text-red-500 hover:text-white', 'dangerSecondary' = 'hover:bg-red-500 text-red-500 hover:text-white',
'border' = 'border border-slate-200 dark:border-zinc-800 bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 hover:dark:bg-slate-800',
} }
+1 -1
View File
@@ -11,7 +11,7 @@ export async function load({ url, params }) {
return { return {
posts: getClient().getPosts({ posts: getClient().getPosts({
limit: 40, limit: 20,
page: page, page: page,
sort: sort, sort: sort,
type_: listingType, type_: listingType,