mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: enhance user experience with tooltips; implement return URL handling on login and registration; add user roles; improve paste visibility checks
This commit is contained in:
@@ -141,6 +141,7 @@
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
bind:value={title}
|
||||
maxlength={data.options.maxTitleLength ?? 500}
|
||||
/>
|
||||
<textarea
|
||||
placeholder="Your paste content here..."
|
||||
@@ -148,6 +149,7 @@
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
bind:value={content}
|
||||
maxlength={data.options.maxContentSize ? Math.floor(data.options.maxContentSize / 4) : undefined}
|
||||
></textarea>
|
||||
<Dropdown
|
||||
options={syntaxOptions}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { FileBox, Eye, User, CalendarDays, CalendarOff, Code } from '@lucide/svelte/icons/index';
|
||||
import { formatBytes, extractDateFromUUIDv7, dateToRelativeString } from '$lib/utils/misc';
|
||||
import {
|
||||
formatBytes,
|
||||
extractDateFromUUIDv7,
|
||||
dateToRelativeString,
|
||||
tooltip
|
||||
} from '$lib/utils/misc';
|
||||
import { displayNames } from '$lib/consts';
|
||||
import { fade } from 'svelte/transition';
|
||||
import { resolve } from '$app/paths';
|
||||
export let data: PageData;
|
||||
let fileSizeHovered = false;
|
||||
|
||||
function addLineNumbers(html: string): string {
|
||||
const match = html.match(/<pre.*?>[\s\S]*?<code.*?>([\s\S]*?)<\/code><\/pre>/);
|
||||
@@ -31,26 +35,19 @@
|
||||
class="max-h-[80vh] w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-4"
|
||||
>
|
||||
{#if data.paste}
|
||||
<h1 class="mb-4 text-center text-4xl font-bold">{data.paste.title || 'Untitled Paste'}</h1>
|
||||
<h1
|
||||
use:tooltip={data.paste.title || 'Untitled Paste'}
|
||||
class="mb-4 truncate text-center text-4xl font-bold"
|
||||
>
|
||||
{data.paste.title || 'Untitled Paste'}
|
||||
</h1>
|
||||
<div class="mb-2 flex flex-wrap items-center justify-center gap-4">
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="relative flex shrink-0 items-center">
|
||||
<div
|
||||
class="flex"
|
||||
on:mouseenter={() => (fileSizeHovered = true)}
|
||||
on:mouseleave={() => (fileSizeHovered = false)}
|
||||
>
|
||||
<div class="flex" use:tooltip={`True Size: ${formatBytes(data.paste.trueSize)}`}>
|
||||
<FileBox class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400">{formatBytes(data.paste.size)}</span>
|
||||
</div>
|
||||
{#if fileSizeHovered}
|
||||
<div
|
||||
class="absolute -top-8 left-1/2 z-10 w-fit -translate-x-1/2 rounded bg-neutral-800 px-2 py-1 text-sm whitespace-nowrap text-white shadow-lg"
|
||||
transition:fade={{ duration: 150 }}
|
||||
>
|
||||
True Size: {formatBytes(data.paste.trueSize)}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex shrink-0 items-center">
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
setTokens(data.result.token, data.result.refreshToken);
|
||||
startTokenRefreshInterval();
|
||||
}
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const returnUrl = urlParams.get('return');
|
||||
if (returnUrl) {
|
||||
window.location.href = returnUrl;
|
||||
return;
|
||||
}
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
error = 'Invalid username or password';
|
||||
|
||||
@@ -49,7 +49,13 @@
|
||||
startTokenRefreshInterval();
|
||||
goto(resolve('/'));
|
||||
} else {
|
||||
goto(resolve('/login'));
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const returnUrl = urlParams.get('return');
|
||||
if (returnUrl) {
|
||||
goto(resolve('/login') + `?return=${encodeURIComponent(returnUrl)}`);
|
||||
} else {
|
||||
goto(resolve('/login'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error = 'Registration failed';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import type { User } from '$lib/types/user';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
|
||||
const { username } = params;
|
||||
@@ -9,6 +10,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
|
||||
Authorization: token ? `Bearer ${token}` : ''
|
||||
}
|
||||
});
|
||||
const user = await res.json();
|
||||
|
||||
const user = await res.json() as User;
|
||||
return { user };
|
||||
}
|
||||
@@ -1,7 +1,85 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import type { PageData } from './$types';
|
||||
import { resolve } from '$app/paths';
|
||||
import type { PageData } from './$types';
|
||||
import { User, CalendarDays, ShieldUser, Ban, File, AtSign } from '@lucide/svelte';
|
||||
import { extractDateFromUUIDv7, tooltip } from '$lib/utils/misc';
|
||||
import { roles } from '$lib/consts';
|
||||
|
||||
export let data: PageData;
|
||||
console.log(data);
|
||||
</script>
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<main
|
||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||
>
|
||||
<div class="w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="flex items-center justify-center gap-4 text-center text-4xl font-bold">
|
||||
{#if data.user.roles.includes(1) || data.user.roles.includes(255)}
|
||||
{#if Math.max(...data.user.roles.filter((r) => r !== 403)) !== -Infinity}
|
||||
<span
|
||||
use:tooltip={roles[
|
||||
Math.max(...data.user.roles.filter((r) => r !== 403)) as keyof typeof roles
|
||||
]}
|
||||
>
|
||||
<ShieldUser class="h-8 w-8 text-neutral-400" />
|
||||
</span>
|
||||
{:else}
|
||||
<span use:tooltip={'User'}>
|
||||
<User class="h-8 w-8 text-neutral-400" />
|
||||
</span>
|
||||
{/if}
|
||||
{:else if data.user.roles.includes(403)}
|
||||
<span class="relative flex items-center justify-center" use:tooltip={roles[403]}>
|
||||
<User class="h-8 w-8 text-neutral-500 opacity-90" />
|
||||
<Ban class="absolute h-7 w-7 text-red-500" />
|
||||
</span>
|
||||
{:else}
|
||||
<span use:tooltip={'User'}>
|
||||
<User class="h-8 w-8 text-neutral-400" />
|
||||
</span>
|
||||
{/if}
|
||||
{data.user.displayName || data.user.username}
|
||||
</h1>
|
||||
{#if data.user.displayName && data.user.displayName !== data.user.username}
|
||||
<div class="mb-2 flex items-center justify-center">
|
||||
<AtSign class="mr-2 inline h-5 w-5 text-neutral-400" />
|
||||
<span class="text-neutral-400">{data.user.username}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="mb-2 flex flex-wrap items-center justify-center gap-4">
|
||||
<div class="flex shrink-0 items-center">
|
||||
<CalendarDays class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span
|
||||
class="text-neutral-400"
|
||||
use:tooltip={extractDateFromUUIDv7(data.user.uuid)?.toLocaleString() ?? 'Unknown'}
|
||||
>
|
||||
Joined {extractDateFromUUIDv7(data.user.uuid)?.toLocaleDateString() ?? 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center">
|
||||
<File class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400"
|
||||
>{data.user.pastes?.length} paste{data.user.pastes?.length !== 1 ? 's' : ''}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6 max-h-[60vh] space-y-4 overflow-y-auto">
|
||||
{#if data.user.pastes && data.user.pastes.length > 0}
|
||||
{#each data.user.pastes as paste}
|
||||
<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"
|
||||
>
|
||||
<span class="truncate text-lg font-semibold text-neutral-100 hover:text-white">
|
||||
{paste.title || 'Untitled Paste'}
|
||||
</span>
|
||||
<p class="text-sm text-neutral-400">
|
||||
Created on {extractDateFromUUIDv7(paste.uuid)?.toLocaleDateString() ?? 'Unknown Date'}
|
||||
</p>
|
||||
</a>
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-center text-neutral-400">This user has not created any pastes yet.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user