mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: enhance Paste component layout and user information display
This commit is contained in:
@@ -7,17 +7,102 @@
|
||||
formatBytes
|
||||
} from '$lib/utils/misc';
|
||||
import { resolve } from '$app/paths';
|
||||
import { Eye, FileBox, Code, User, History, Calendar, Timer } from '@lucide/svelte';
|
||||
import {
|
||||
Eye,
|
||||
FileBox,
|
||||
Code,
|
||||
User,
|
||||
History,
|
||||
Calendar,
|
||||
Timer,
|
||||
Lock,
|
||||
EyeOff,
|
||||
Globe
|
||||
} from '@lucide/svelte';
|
||||
import { syntaxes } from '$lib/consts';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
|
||||
export let paste: Paste;
|
||||
export let now: Date;
|
||||
export let showUser: boolean = true;
|
||||
export let compact: boolean = false;
|
||||
|
||||
const createdAt = extractDateFromUUIDv7(paste.uuid);
|
||||
const syntax = syntaxes[paste.syntax] ?? syntaxes['plaintext'];
|
||||
</script>
|
||||
|
||||
{#if compact}
|
||||
<a
|
||||
href={resolve(`/${paste.id}`)}
|
||||
class="flex flex-col gap-1 rounded border border-neutral-700 bg-neutral-800 px-4 py-3 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
>
|
||||
<div class="flex w-full flex-row justify-between">
|
||||
<span
|
||||
class="text-md w-fit max-w-full truncate font-semibold text-neutral-100 hover:text-white"
|
||||
use:tooltip={paste.title || 'Untitled Paste'}
|
||||
>
|
||||
{paste.title || 'Untitled Paste'}
|
||||
</span>
|
||||
<div
|
||||
class="flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={`${createdAt?.toLocaleString()} • ${dateToRelativeString(createdAt ?? new Date(), true, false, now)}`}
|
||||
>
|
||||
<Calendar class="h-4 w-4" />
|
||||
{#if createdAt}
|
||||
{#if createdAt.getTime() > Date.now() - 86_400_000}
|
||||
Created {dateToRelativeString(createdAt, true, false, now)}
|
||||
{:else}
|
||||
Created on {createdAt.toLocaleDateString()}
|
||||
{/if}
|
||||
{:else}
|
||||
Creation date unknown
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row justify-between text-sm text-neutral-400">
|
||||
<div>
|
||||
{#if showUser}
|
||||
<div class="flex items-center gap-2">
|
||||
<User class="h-4 w-4" />
|
||||
{paste.author?.username ?? 'Anonymous'}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center gap-2">
|
||||
{#if paste.visibility === 0}
|
||||
<Globe class="h-4 w-4" />
|
||||
Public
|
||||
{:else if paste.visibility === 1}
|
||||
<EyeOff class="h-4 w-4" />
|
||||
Unlisted
|
||||
{:else}
|
||||
<Lock class="h-4 w-4" />
|
||||
Private
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex items-center gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
|
||||
{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
class="flex items-center gap-2"
|
||||
use:tooltip={paste.isCompressed ? `Compressed Size: ${formatBytes(paste.size)}` : ''}
|
||||
>
|
||||
<FileBox class="h-4 w-4" />
|
||||
{formatBytes(paste.trueSize)}
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Code class="h-4 w-4" />
|
||||
{syntax.name}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{:else}
|
||||
<a
|
||||
href={resolve(`/${paste.id}`)}
|
||||
class="flex flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
@@ -60,10 +145,12 @@
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if showUser}
|
||||
<div class="mt-1 flex items-center gap-2 text-sm text-neutral-400">
|
||||
<User class="h-4 w-4" />
|
||||
<span>{paste.author?.username ?? 'Anonymous'}</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if paste.editedAt}
|
||||
<div
|
||||
class="mt-1 flex items-center gap-2 text-sm text-neutral-400"
|
||||
@@ -93,3 +180,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
@@ -413,7 +413,7 @@
|
||||
<div class="mt-6 max-h-[60vh] space-y-4 overflow-y-auto">
|
||||
{#if pastes && pastes.length > 0}
|
||||
{#each pastes.slice().sort((a, b) => b.uuid.localeCompare(a.uuid)) as paste (paste.uuid)}
|
||||
<Paste {paste} {now} />
|
||||
<Paste {paste} {now} showUser={false} compact={true} />
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-center text-neutral-400">
|
||||
|
||||
Reference in New Issue
Block a user