diff --git a/SharpbinV3.Client/src/lib/utils/misc.ts b/SharpbinV3.Client/src/lib/utils/misc.ts index 259966c..caac3ca 100644 --- a/SharpbinV3.Client/src/lib/utils/misc.ts +++ b/SharpbinV3.Client/src/lib/utils/misc.ts @@ -74,9 +74,16 @@ export function tooltip(node: HTMLElement, text: string) { if (!currentText || currentText.trim() === '') return; const el = document.createElement('div'); el.className = - 'fixed z-50 rounded bg-neutral-800 px-2 py-1 text-sm text-white shadow-lg opacity-0 pointer-events-none transition-opacity duration-150'; + 'fixed z-50 rounded bg-neutral-800 px-2 py-1 text-sm text-white shadow-lg opacity-0 transition-opacity duration-150'; el.style.maxWidth = '90%'; el.style.wordBreak = 'break-word'; + + el.addEventListener('mouseover', () => { + clearTimeout(hideTimeout); + if (tooltipEl) tooltipEl.style.opacity = '1'; + }); + el.addEventListener('mouseout', mouseOut); + const lines = currentText.split('\n'); if (lines.length > 1) { el.innerHTML = ''; @@ -172,6 +179,7 @@ export function tooltip(node: HTMLElement, text: string) { function mouseOver() { clearTimeout(hideTimeout); + if (tooltipEl) tooltipEl.style.opacity = '1'; showTimeout = setTimeout(() => { if (!tooltipEl) createTooltip(); else updateContent(); diff --git a/SharpbinV3.Client/src/routes/user/[username]/+page.svelte b/SharpbinV3.Client/src/routes/user/[username]/+page.svelte index a565e49..6d3d8cd 100644 --- a/SharpbinV3.Client/src/routes/user/[username]/+page.svelte +++ b/SharpbinV3.Client/src/routes/user/[username]/+page.svelte @@ -19,6 +19,7 @@ import { getToken } from '$lib/utils/auth'; import Modal from '$lib/components/Modal.svelte'; import { user } from '$lib/stores/user'; + import { onMount } from 'svelte'; export let data: PageData; @@ -36,6 +37,8 @@ let showDeleteModal = false; let showRoleModal = false; let modalError = ''; + let now = new Date(); + let interval: ReturnType | null = null; $: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false; @@ -111,6 +114,15 @@ showDeleteModal = false; window.location.href = '/'; } + + onMount(() => { + interval = setInterval(() => { + now = new Date(); + }, 1000); + return () => { + if (interval) clearInterval(interval); + }; + }); @@ -146,7 +158,9 @@ {/if} - {data.user?.displayName || data.user?.username} + + {data.user?.displayName || data.user?.username} + {#if data.user?.displayName && data.user?.displayName !== data.user?.username}
@@ -183,7 +197,7 @@ class="text-neutral-400" use:tooltip={new Date(data.user?.lastLogin).toLocaleString()} > - Last login {dateToRelativeString(new Date(data.user?.lastLogin))} + Last login {dateToRelativeString(new Date(data.user?.lastLogin), true, false, now)}
{/if}