add dynamic page titles for profiles and teams

This commit is contained in:
Justin Edmund 2025-12-14 21:55:54 -08:00
parent 8541f54f90
commit 0336fabaa8
2 changed files with 40 additions and 3 deletions

View file

@ -8,6 +8,8 @@
import { IsInViewport } from 'runed'
import Icon from '$lib/components/Icon.svelte'
import Button from '$lib/components/ui/Button.svelte'
import PageMeta from '$lib/components/PageMeta.svelte'
import * as m from '$lib/paraglide/messages'
const { data }: { data: PageData } = $props()
const isOwner = $derived(data.isOwner || false)
@ -62,9 +64,10 @@
})
</script>
<svelte:head>
<title>{data.user.username}'s Teams | Hensei</title>
</svelte:head>
<PageMeta
title={m.page_title_profile({ username: data.user?.username ?? '' })}
description={m.page_desc_profile({ username: data.user?.username ?? '' })}
/>
<section class="profile">
<ProfileHeader

View file

@ -5,9 +5,25 @@
import { partyQueries } from '$lib/api/queries/party.queries'
import { withInitialData } from '$lib/query/ssr'
import { GridType } from '$lib/types/enums'
import PageMeta from '$lib/components/PageMeta.svelte'
import * as m from '$lib/paraglide/messages'
let { data }: { data: PageData } = $props()
// Element emoji mapping for party titles
function getElementEmoji(element: number | undefined | null): string {
const emojis: Record<number, string> = {
0: '⚪', // null/unknown
1: '🔴', // fire
2: '🔵', // water
3: '🟤', // earth
4: '🟢', // wind
5: '🟡', // light
6: '🟣' // dark
}
return emojis[element ?? 0] ?? '⚪'
}
// Map URL segment to GridType
const tabMap: Record<string, GridType> = {
weapons: GridType.Weapon,
@ -41,8 +57,26 @@
// Use query data if available, fall back to server data
// This allows the query to refetch and update the UI automatically
const party = $derived(partyQuery.data ?? data.party)
// Generate dynamic page title
const pageTitle = $derived(() => {
if (!party) return 'Team / granblue.team'
const emoji = getElementEmoji(party.element)
const teamName = party.name || 'Unnamed Team'
const username = party.user?.username || 'Anonymous'
return m.page_title_party({ emoji, teamName, username })
})
const pageDescription = $derived(() => {
if (!party) return m.page_desc_home()
const raidName = party.raid?.name || 'Unknown Raid'
const username = party.user?.username || 'Anonymous'
return m.page_desc_party({ raidName, username })
})
</script>
<PageMeta title={pageTitle()} description={pageDescription()} />
{#if party}
<Party party={party} canEdit={data.canEdit || false} authUserId={data.authUserId} {initialTab} />
{:else}