feat(frontend): improve user page UX

This commit is contained in:
2026-02-13 02:35:05 -05:00
parent 53d0f33ff0
commit ff706d8777
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { resolve } from '$app/paths'; import { resolve } from '$app/paths';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/state';
import type { PageData } from './$types'; import type { PageData } from './$types';
import type { Pagination } from '$lib/types/pagination'; import type { Pagination } from '$lib/types/pagination';
import { import {
@@ -8,13 +9,13 @@
CalendarDays, CalendarDays,
ShieldUser, ShieldUser,
Ban, Ban,
File,
AtSign, AtSign,
Pencil, Pencil,
Trash2, Trash2,
Clock, Clock,
Hash, Hash,
Flag Flag,
LoaderCircle
} from '@lucide/svelte'; } from '@lucide/svelte';
import { import {
extractDateFromUUIDv7, extractDateFromUUIDv7,
@@ -53,6 +54,26 @@
$: reportsSubmitted = data.reportsSubmitted; $: reportsSubmitted = data.reportsSubmitted;
$: reportsTarget = data.reportsTarget; $: reportsTarget = data.reportsTarget;
let activeTab: 'pastes' | 'reportsSubmitted' | 'reportsTarget' = 'pastes';
function updateTab(tab: typeof activeTab) {
activeTab = tab;
const url = new URL(page.url);
url.searchParams.set('tab', tab);
goto(url, { replaceState: true, noScroll: true, keepFocus: true });
}
$: {
const tab = page.url.searchParams.get('tab');
if (tab === 'reportsSubmitted' && reportsSubmitted) {
activeTab = 'reportsSubmitted';
} else if (tab === 'reportsTarget' && reportsTarget) {
activeTab = 'reportsTarget';
} else {
activeTab = 'pastes';
}
}
const roleOptions = [ const roleOptions = [
{ label: 'Member', value: 0 }, { label: 'Member', value: 0 },
{ label: 'Moderator', value: 1 }, { label: 'Moderator', value: 1 },
@@ -317,33 +338,7 @@
Joined {extractDateFromUUIDv7(data.user?.uuid)?.toLocaleDateString() ?? 'Unknown'} Joined {extractDateFromUUIDv7(data.user?.uuid)?.toLocaleDateString() ?? 'Unknown'}
</span> </span>
</div> </div>
<div class="flex shrink-0 items-center">
<File class="mr-2 h-6 w-6 text-neutral-400" />
<span class="text-neutral-400"
>{pagination.totalCount} paste{pagination.totalCount !== 1 ? 's' : ''}</span
>
</div>
{#if reportsSubmitted}
<div class="flex shrink-0 items-center">
<Flag class="mr-2 h-6 w-6 text-neutral-400" />
<span class="text-neutral-400"
>{reportsSubmitted.pagination.totalCount} submitted report{reportsSubmitted.pagination
.totalCount !== 1
? 's'
: ''}</span
>
</div>
{/if}
{#if reportsTarget}
<div class="flex shrink-0 items-center">
<Flag class="mr-2 h-6 w-6 text-neutral-400" />
<span class="text-neutral-400"
>{reportsTarget.pagination.totalCount} report{reportsTarget.pagination.totalCount !== 1
? 's'
: ''}</span
>
</div>
{/if}
<div class="flex shrink-0 items-center"> <div class="flex shrink-0 items-center">
<Hash class="mr-1 h-6 w-6 text-neutral-400" /> <Hash class="mr-1 h-6 w-6 text-neutral-400" />
<span class="text-neutral-400" use:tooltip={`User #${data.user?.uid}`}> <span class="text-neutral-400" use:tooltip={`User #${data.user?.uid}`}>
@@ -419,9 +414,64 @@
{/if} {/if}
</div> </div>
{/if} {/if}
<div class="mt-8 flex w-full border-b border-neutral-800">
<button
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeTab ===
'pastes'
? 'border-neutral-200 text-white'
: 'border-transparent text-neutral-400'}"
on:click={() => updateTab('pastes')}
>
Pastes
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>{pagination.totalCount}</span
>
</button>
{#if reportsSubmitted}
<button
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeTab ===
'reportsSubmitted'
? 'border-neutral-200 text-white'
: 'border-transparent text-neutral-400'}"
on:click={() => updateTab('reportsSubmitted')}
>
Submitted Reports
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>{reportsSubmitted.pagination.totalCount}</span
>
</button>
{/if}
{#if reportsTarget}
<button
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeTab ===
'reportsTarget'
? 'border-neutral-200 text-white'
: 'border-transparent text-neutral-400'}"
on:click={() => updateTab('reportsTarget')}
>
Reports Against User
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>{reportsTarget.pagination.totalCount}</span
>
</button>
{/if}
</div>
<div class="relative mt-4 min-h-50 w-full">
{#if loading}
<div
class="absolute inset-0 z-10 flex items-center justify-center bg-neutral-900/50 backdrop-blur-sm"
>
<LoaderCircle class="h-8 w-8 animate-spin text-neutral-200" />
</div>
{/if}
{#if activeTab === 'pastes'}
<div class="mt-6 max-h-[60vh] space-y-4 overflow-y-auto"> <div class="mt-6 max-h-[60vh] space-y-4 overflow-y-auto">
{#if pastes && pastes.length > 0} {#if pastes && pastes.length > 0}
{#each pastes.slice().sort((a, b) => b.uuid.localeCompare(a.uuid)) as paste (paste.uuid)} {#each pastes
.slice()
.sort((a, b) => b.uuid.localeCompare(a.uuid)) as paste (paste.uuid)}
<Paste {paste} {now} showUser={false} compact={true} /> <Paste {paste} {now} showUser={false} compact={true} />
{/each} {/each}
{:else} {:else}
@@ -430,12 +480,29 @@
</p> </p>
{/if} {/if}
</div> </div>
{#if reportsSubmitted || reportsTarget} {#if pagination.totalPages && pagination.totalPages > 1}
<div class="mt-6 space-y-6"> <div class="mt-4 flex items-center justify-center gap-4">
{#if reportsSubmitted && reportsSubmitted.reports.length > 0} <button
<div class="rounded border border-neutral-800 bg-neutral-900/60 p-4"> class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
<h2 class="mb-3 text-xl font-semibold text-neutral-200">Submitted Reports</h2> on:click={() => fetchPage(currentPage - 1)}
<div class="space-y-3"> disabled={currentPage === 1 || loading}
>
Prev
</button>
<span class="text-neutral-400">
Page {currentPage} of {pagination.totalPages}
</span>
<button
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
on:click={() => fetchPage(currentPage + 1)}
disabled={currentPage === pagination.totalPages || loading}
>
Next
</button>
</div>
{/if}
{:else if activeTab === 'reportsSubmitted' && reportsSubmitted && reportsSubmitted.reports.length > 0}
<div class="mt-6 space-y-3">
{#each reportsSubmitted.reports as report (report.reportID)} {#each reportsSubmitted.reports as report (report.reportID)}
<div <div
class="flex cursor-pointer 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" class="flex cursor-pointer 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"
@@ -493,12 +560,8 @@
</div> </div>
{/each} {/each}
</div> </div>
</div> {:else if activeTab === 'reportsTarget' && reportsTarget && reportsTarget.reports.length > 0}
{/if} <div class="mt-6 space-y-3">
{#if reportsTarget && reportsTarget.reports.length > 0}
<div class="rounded border border-neutral-800 bg-neutral-900/60 p-4">
<h2 class="mb-3 text-xl font-semibold text-neutral-200">Reports About This User</h2>
<div class="space-y-3">
{#each reportsTarget.reports as report (report.reportID)} {#each reportsTarget.reports as report (report.reportID)}
<div <div
class="flex cursor-pointer 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" class="flex cursor-pointer 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"
@@ -568,31 +631,18 @@
</div> </div>
{/each} {/each}
</div> </div>
</div> {:else}
<p class="mt-6 text-center text-neutral-400">
{#if activeTab === 'reportsSubmitted'}
{isOwner ? 'You have' : 'This user has'} not submitted any reports.
{:else if activeTab === 'reportsTarget'}
{isOwner ? 'You have' : 'This user has'} not been reported.
{:else}
No reports found.
{/if}
</p>
{/if} {/if}
</div> </div>
{/if}
{#if pagination.totalPages && pagination.totalPages > 1}
<div class="mt-4 flex items-center justify-center gap-4">
<button
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
on:click={() => fetchPage(currentPage - 1)}
disabled={currentPage === 1 || loading}
>
Prev
</button>
<span class="text-neutral-400">
Page {currentPage} of {pagination.totalPages}
</span>
<button
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
on:click={() => fetchPage(currentPage + 1)}
disabled={currentPage === pagination.totalPages || loading}
>
Next
</button>
</div>
{/if}
</div> </div>
</main> </main>