From e20a6200dd3c1f0dfe26645c625cac448dc50d76 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 25 Apr 2026 05:00:52 -0400 Subject: [PATCH] feat: add sub tab to the settings tab --- .../src/routes/user/[username]/+page.svelte | 555 ++++++++++-------- 1 file changed, 314 insertions(+), 241 deletions(-) diff --git a/SharpbinV3.Client/src/routes/user/[username]/+page.svelte b/SharpbinV3.Client/src/routes/user/[username]/+page.svelte index 19ec6a7..5223cfe 100644 --- a/SharpbinV3.Client/src/routes/user/[username]/+page.svelte +++ b/SharpbinV3.Client/src/routes/user/[username]/+page.svelte @@ -78,13 +78,28 @@ let reportsTarget = $derived(data.reportsTarget); let activeTab: 'pastes' | 'reportsSubmitted' | 'reportsTarget' | 'settings' = $state('pastes'); + let activeSubTab: + | 'settings:general' + | 'settings:security' + | 'settings:admin' + | 'settings:developer' + | null = $state(null); - async function updateTab(newPageTab: typeof activeTab) { - if (activeTab === newPageTab) return; + async function updateTab( + newPageTab: typeof activeTab, + newPageSubTab: typeof activeSubTab = null + ) { + if (activeTab === newPageTab && activeSubTab === newPageSubTab) return; activeTab = newPageTab; + activeSubTab = newPageSubTab; const url = new URL(page.url); url.searchParams.set('tab', newPageTab); + if (newPageSubTab) { + url.searchParams.set('subtab', newPageSubTab); + } else { + url.searchParams.delete('subtab'); + } // @ts-expect-error - resolve still works even though it's flagged as an error // eslint-disable-next-line svelte/no-navigation-without-resolve @@ -95,13 +110,19 @@ invalidateAll: false }); - if (newPageTab === 'settings' && isOwner && apiKeys.length === 0) { + if ( + newPageTab === 'settings' && + newPageSubTab === 'settings:developer' && + isOwner && + apiKeys.length === 0 + ) { await fetchApiKeys(); } } $effect(() => { const tab = page.url.searchParams.get('tab'); + const subTab = page.url.searchParams.get('subtab'); switch (tab) { case 'pastes': activeTab = 'pastes'; @@ -126,6 +147,29 @@ activeTab = 'pastes'; } } + + switch (subTab) { + case 'settings:general': + activeSubTab = 'settings:general'; + break; + case 'settings:security': + activeSubTab = 'settings:security'; + break; + case 'settings:admin': + activeSubTab = 'settings:admin'; + break; + case 'settings:developer': + activeSubTab = 'settings:developer'; + break; + default: + if (activeTab === 'settings' && isOwner) { + activeSubTab = 'settings:general'; + } else if ($user?.roles && hasRole($user.roles, roles.Admin) && activeTab === 'settings') { + activeSubTab = 'settings:admin'; + } else { + activeSubTab = null; + } + } }); const roleOptions = [ @@ -689,27 +733,79 @@
{#if loading} -
+
{/if} {#if activeTab === 'settings'} +
+ + {#if isOwner} + + {/if} + {#if $user?.roles && hasRole($user.roles, roles.Admin)} + + {/if} + {#if isOwner} + + {/if} +
-
-
-
-
-

Display Name

-

- {isOwner - ? 'Your display name is shown publicly on your profile and pastes.' - : "This user's display name is shown publicly on their profile and pastes."} -

-
-
+ {#if activeSubTab === 'settings:general'} +
+

Display Name

+

+ {isOwner + ? 'Your display name is shown publicly on your profile and pastes.' + : "This user's display name is shown publicly on their profile and pastes."} +

+
{#if isEditingDisplayName}
@@ -752,235 +848,28 @@ {/if}
-
- - {#if isOwner} -
-
-
-
-

Security

-

- Manage your account security settings. -

-
-
- -
-
-
- Two-Factor Authentication - {totpEnabled ? 'Enabled' : 'Disabled'} -
- -
-
-
-
- {/if} - - {#if $user?.roles && hasRole($user.roles, roles.Admin)} -
-
-
-
-

Administration

-

Manage user roles and permissions.

-
-
-
-
-
- User Roles - {(() => { - let count = 0; - if (data.user?.roles) { - if (hasRole(data.user.roles, roles.User)) count++; - if (hasRole(data.user.roles, roles.Moderator)) count++; - if (hasRole(data.user.roles, roles.Admin)) count++; - } - return count; - })()} roles assigned -
- -
-
-
-
- {/if} - - {#if isOwner} + {:else if isOwner && activeSubTab === 'settings:security'}
-
-
-
-

- API Keys ({apiKeys.length}/10) -

-

- Manage API keys for accessing Sharpbin programmatically. -

+
+
+
+ Two-Factor Authentication + {totpEnabled ? 'Enabled' : 'Disabled'}
-
- - {#if apiKeyError} -
- {apiKeyError} -
- {/if} - -
- {#if isCreatingApiKey} -
- - - -
- {:else} - - {/if} -
- - {#if newApiKeyValue} -
-
- API Key Created - -
-

- Please copy your API key now. You won't be able to see it again. -

-
- {newApiKeyValue} - -
-
- {/if} - -
- {#if apiKeys.length !== 0} - {#each apiKeys as key (key.uuid)} -
-
- {key.name} -
- Created: {new Date(key.createdAt).toLocaleDateString()} - Last used: {key.lastUsedAt - ? dateToRelativeString(new Date(key.lastUsedAt), true, false, now) - : 'Never'} -
-
- -
- {/each} - {/if} + {totpEnabled ? 'Manage' : 'Enable'} +
- {/if} - - {#if isOwner || ($user?.roles && hasRole($user.roles, roles.Admin))} -
-
-
-
-

Danger Zone

-

- Irreversible actions related to this account. -

-
-
- -
+ {#if isOwner} +
+

Delete Account

@@ -995,6 +884,190 @@

+ {/if} + {:else if $user?.roles && hasRole($user.roles, roles.Admin) && activeSubTab === 'settings:admin'} +
+
+
+
+ User Roles + {(() => { + let count = 0; + if (data.user?.roles) { + if (hasRole(data.user.roles, roles.User)) count++; + if (hasRole(data.user.roles, roles.Moderator)) count++; + if (hasRole(data.user.roles, roles.Admin)) count++; + } + return count; + })()} roles assigned +
+ +
+
+
+ {#if !isOwner && data.user?.roles && !hasRole(data.user.roles, roles.Admin)} +
+
+
+

Delete Account

+

+ Permanently delete this account and all associated data. +

+
+ +
+
+ {/if} + {:else if isOwner && activeSubTab === 'settings:developer'} +
+
+

+ API Keys ({apiKeys.length}/10) +

+

+ Manage API keys for accessing Sharpbin programmatically. +

+
+ + {#if apiKeyError} +
+ {apiKeyError} +
+ {/if} + +
+ {#if isCreatingApiKey} +
+ + + +
+ {:else} + + {/if} +
+ + {#if newApiKeyValue} +
+
+ API Key Created + +
+

+ Please copy your API key now. You won't be able to see it again. +

+
+ {newApiKeyValue} + +
+
+ {/if} + +
+ {#if apiKeys.length !== 0} + {#each apiKeys as key (key.uuid)} +
+
+ {key.name} +
+ Created: {new Date(key.createdAt).toLocaleDateString()} + Last used: {key.lastUsedAt + ? dateToRelativeString(new Date(key.lastUsedAt), true, false, now) + : 'Never'} +
+
+ +
+ {/each} + {/if} +
{/if}