diff options
Diffstat (limited to 'src/routes/user')
| -rw-r--r-- | src/routes/user/[user]/+page.svelte | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/routes/user/[user]/+page.svelte b/src/routes/user/[user]/+page.svelte index ecbc8330..fd1e2d7e 100644 --- a/src/routes/user/[user]/+page.svelte +++ b/src/routes/user/[user]/+page.svelte @@ -30,6 +30,18 @@ $: ({ Profile } = data); $: preferences = $Profile.fetching ? undefined : ($Profile.data?.User?.preferences as Preferences | undefined); +$: isOwner = Boolean(userData && userData.id === $identity.id); +$: ownerPreferences = preferences ?? { + created_at: "", + updated_at: "", + user_id: userData?.id ?? 0, + pinned_hololive_streams: [], + hide_missing_badges: false, + biography: null, + badge_wall_css: "", + hide_awc_badges: false, + pinned_badge_wall_categories: [], +}; const setCategoriesQuery = graphql(` mutation SetCategories($categories: [String!]!) { @@ -139,17 +151,17 @@ const handleDragEnter = ( ) => { event.preventDefault(); - if (draggedCategory !== category && preferences && draggedCategory) { + if (draggedCategory !== category && draggedCategory) { draggedOverCategory = category; - const categories = preferences.pinned_badge_wall_categories; + const categories = ownerPreferences.pinned_badge_wall_categories; const draggedIndex = categories.indexOf(draggedCategory); const targetIndex = categories.indexOf(category || ""); categories.splice(draggedIndex, 1); categories.splice(targetIndex, 0, draggedCategory); - preferences.pinned_badge_wall_categories = categories; + ownerPreferences.pinned_badge_wall_categories = categories; } }; @@ -159,26 +171,26 @@ const handleDragLeave = ( ) => { event.preventDefault(); - if (draggedOverCategory === category && preferences && draggedCategory) { + if (draggedOverCategory === category && draggedCategory) { draggedOverCategory = null; - const categories = preferences.pinned_badge_wall_categories; + const categories = ownerPreferences.pinned_badge_wall_categories; const draggedIndex = categories.indexOf(draggedCategory); categories.splice(draggedIndex, 1); categories.splice(categories.indexOf(category) + 1, 0, draggedCategory); - preferences.pinned_badge_wall_categories = categories; + ownerPreferences.pinned_badge_wall_categories = categories; } }; const handleDrop = (event: { preventDefault: () => void }) => { event.preventDefault(); - if (userData && preferences) + if (userData) setCategoriesQuery .mutate({ - categories: preferences.pinned_badge_wall_categories, + categories: ownerPreferences.pinned_badge_wall_categories, }) .then(); @@ -360,7 +372,7 @@ const toggleCategory = () => { </div> {/if} - {#if preferences && userData && userData.id === $identity.id} + {#if isOwner} <Spacer /> <details open> @@ -371,7 +383,7 @@ const toggleCategory = () => { onchange={() => { if (userData) toggleHideMissingBadgesQuery.mutate(null).then(); }} - checked={preferences.hide_missing_badges} + checked={ownerPreferences.hide_missing_badges} /> {$locale().user.preferences.hideMissingBadges.title} <SettingHint lineBreak>{$locale().user.preferences.hideMissingBadges.hint}</SettingHint> @@ -383,7 +395,7 @@ const toggleCategory = () => { onchange={() => { if (userData) toggleHideAWCBadgesQuery.mutate(null).then(); }} - checked={preferences.hide_awc_badges} + checked={ownerPreferences.hide_awc_badges} /> {$locale().user.preferences.hideAWCBadges.title} @@ -392,7 +404,7 @@ const toggleCategory = () => { Pinned Categories <div class="pinned-categories"> - {#each preferences.pinned_badge_wall_categories as category} + {#each ownerPreferences.pinned_badge_wall_categories as category} <div class="card card-small pinned-category" draggable="true" @@ -440,7 +452,7 @@ const toggleCategory = () => { }}>Save</button > <textarea - value={preferences.biography} + value={ownerPreferences.biography} rows="5" cols="100" id="biography" @@ -462,7 +474,7 @@ const toggleCategory = () => { }}>Save</button > <textarea - value={preferences.badge_wall_css} + value={ownerPreferences.badge_wall_css} rows="10" cols="100" id="badgeWallCSS" |