fix: enhance tooltip functionality and update last login display

This commit is contained in:
2026-01-07 09:46:58 -05:00
parent 7650fd786d
commit d3c2efd210
2 changed files with 25 additions and 3 deletions
+9 -1
View File
@@ -74,9 +74,16 @@ export function tooltip(node: HTMLElement, text: string) {
if (!currentText || currentText.trim() === '') return; if (!currentText || currentText.trim() === '') return;
const el = document.createElement('div'); const el = document.createElement('div');
el.className = 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.maxWidth = '90%';
el.style.wordBreak = 'break-word'; 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'); const lines = currentText.split('\n');
if (lines.length > 1) { if (lines.length > 1) {
el.innerHTML = ''; el.innerHTML = '';
@@ -172,6 +179,7 @@ export function tooltip(node: HTMLElement, text: string) {
function mouseOver() { function mouseOver() {
clearTimeout(hideTimeout); clearTimeout(hideTimeout);
if (tooltipEl) tooltipEl.style.opacity = '1';
showTimeout = setTimeout(() => { showTimeout = setTimeout(() => {
if (!tooltipEl) createTooltip(); if (!tooltipEl) createTooltip();
else updateContent(); else updateContent();
@@ -19,6 +19,7 @@
import { getToken } from '$lib/utils/auth'; import { getToken } from '$lib/utils/auth';
import Modal from '$lib/components/Modal.svelte'; import Modal from '$lib/components/Modal.svelte';
import { user } from '$lib/stores/user'; import { user } from '$lib/stores/user';
import { onMount } from 'svelte';
export let data: PageData; export let data: PageData;
@@ -36,6 +37,8 @@
let showDeleteModal = false; let showDeleteModal = false;
let showRoleModal = false; let showRoleModal = false;
let modalError = ''; let modalError = '';
let now = new Date();
let interval: ReturnType<typeof setInterval> | null = null;
$: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false; $: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false;
@@ -111,6 +114,15 @@
showDeleteModal = false; showDeleteModal = false;
window.location.href = '/'; window.location.href = '/';
} }
onMount(() => {
interval = setInterval(() => {
now = new Date();
}, 1000);
return () => {
if (interval) clearInterval(interval);
};
});
</script> </script>
<svelte:head> <svelte:head>
@@ -146,7 +158,9 @@
<User class="h-8 w-8 text-neutral-400" /> <User class="h-8 w-8 text-neutral-400" />
</span> </span>
{/if} {/if}
{data.user?.displayName || data.user?.username} <span use:tooltip={data.user?.uuid || 'Unknown UUID'}>
{data.user?.displayName || data.user?.username}
</span>
</h1> </h1>
{#if data.user?.displayName && data.user?.displayName !== data.user?.username} {#if data.user?.displayName && data.user?.displayName !== data.user?.username}
<div class="mb-2 flex items-center justify-center"> <div class="mb-2 flex items-center justify-center">
@@ -183,7 +197,7 @@
class="text-neutral-400" class="text-neutral-400"
use:tooltip={new Date(data.user?.lastLogin).toLocaleString()} 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)}
</span> </span>
</div> </div>
{/if} {/if}