mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add sub tab to the settings tab
This commit is contained in:
@@ -78,13 +78,28 @@
|
|||||||
let reportsTarget = $derived(data.reportsTarget);
|
let reportsTarget = $derived(data.reportsTarget);
|
||||||
|
|
||||||
let activeTab: 'pastes' | 'reportsSubmitted' | 'reportsTarget' | 'settings' = $state('pastes');
|
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) {
|
async function updateTab(
|
||||||
if (activeTab === newPageTab) return;
|
newPageTab: typeof activeTab,
|
||||||
|
newPageSubTab: typeof activeSubTab = null
|
||||||
|
) {
|
||||||
|
if (activeTab === newPageTab && activeSubTab === newPageSubTab) return;
|
||||||
activeTab = newPageTab;
|
activeTab = newPageTab;
|
||||||
|
activeSubTab = newPageSubTab;
|
||||||
|
|
||||||
const url = new URL(page.url);
|
const url = new URL(page.url);
|
||||||
url.searchParams.set('tab', newPageTab);
|
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
|
// @ts-expect-error - resolve still works even though it's flagged as an error
|
||||||
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
||||||
@@ -95,13 +110,19 @@
|
|||||||
invalidateAll: false
|
invalidateAll: false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newPageTab === 'settings' && isOwner && apiKeys.length === 0) {
|
if (
|
||||||
|
newPageTab === 'settings' &&
|
||||||
|
newPageSubTab === 'settings:developer' &&
|
||||||
|
isOwner &&
|
||||||
|
apiKeys.length === 0
|
||||||
|
) {
|
||||||
await fetchApiKeys();
|
await fetchApiKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const tab = page.url.searchParams.get('tab');
|
const tab = page.url.searchParams.get('tab');
|
||||||
|
const subTab = page.url.searchParams.get('subtab');
|
||||||
switch (tab) {
|
switch (tab) {
|
||||||
case 'pastes':
|
case 'pastes':
|
||||||
activeTab = 'pastes';
|
activeTab = 'pastes';
|
||||||
@@ -126,6 +147,29 @@
|
|||||||
activeTab = 'pastes';
|
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 = [
|
const roleOptions = [
|
||||||
@@ -689,27 +733,79 @@
|
|||||||
|
|
||||||
<div class="relative mt-4 min-h-50 w-full">
|
<div class="relative mt-4 min-h-50 w-full">
|
||||||
{#if loading}
|
{#if loading}
|
||||||
<div
|
<div class="absolute inset-0 z-10 flex items-center justify-center bg-neutral-900/50">
|
||||||
class="absolute inset-0 z-10 flex items-center justify-center bg-neutral-900/50 backdrop-blur-sm"
|
|
||||||
>
|
|
||||||
<LoaderCircle class="h-8 w-8 animate-spin text-neutral-200" />
|
<LoaderCircle class="h-8 w-8 animate-spin text-neutral-200" />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if activeTab === 'settings'}
|
{#if activeTab === 'settings'}
|
||||||
|
<div class="-mt-4 mb-4 flex w-full border-b border-neutral-800">
|
||||||
|
<button
|
||||||
|
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeSubTab ===
|
||||||
|
'settings:general'
|
||||||
|
? 'border-neutral-200 text-white'
|
||||||
|
: 'border-transparent text-neutral-400'}"
|
||||||
|
onclick={() =>
|
||||||
|
updateTab(
|
||||||
|
'settings',
|
||||||
|
activeSubTab === 'settings:general' ? null : 'settings:general'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
General
|
||||||
|
</button>
|
||||||
|
{#if isOwner}
|
||||||
|
<button
|
||||||
|
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeSubTab ===
|
||||||
|
'settings:security'
|
||||||
|
? 'border-neutral-200 text-white'
|
||||||
|
: 'border-transparent text-neutral-400'}"
|
||||||
|
onclick={() =>
|
||||||
|
updateTab(
|
||||||
|
'settings',
|
||||||
|
activeSubTab === 'settings:security' ? null : 'settings:security'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Security
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
{#if $user?.roles && hasRole($user.roles, roles.Admin)}
|
||||||
|
<button
|
||||||
|
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeSubTab ===
|
||||||
|
'settings:admin'
|
||||||
|
? 'border-neutral-200 text-white'
|
||||||
|
: 'border-transparent text-neutral-400'}"
|
||||||
|
onclick={() =>
|
||||||
|
updateTab('settings', activeSubTab === 'settings:admin' ? null : 'settings:admin')}
|
||||||
|
>
|
||||||
|
Admin
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
{#if isOwner}
|
||||||
|
<button
|
||||||
|
class="border-b-2 px-4 py-2 font-medium transition-colors hover:text-white {activeSubTab ===
|
||||||
|
'settings:developer'
|
||||||
|
? 'border-neutral-200 text-white'
|
||||||
|
: 'border-transparent text-neutral-400'}"
|
||||||
|
onclick={() =>
|
||||||
|
updateTab(
|
||||||
|
'settings',
|
||||||
|
activeSubTab === 'settings:developer' ? null : 'settings:developer'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Developer
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
|
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||||
|
{#if activeSubTab === 'settings:general'}
|
||||||
<div class="col-span-2">
|
<div class="col-span-2">
|
||||||
<div class="rounded border border-neutral-800 bg-neutral-900/50 p-6">
|
|
||||||
<div class="mb-6 flex items-start">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-xl font-semibold text-neutral-100">Display Name</h2>
|
<h2 class="text-xl font-semibold text-neutral-100">Display Name</h2>
|
||||||
<p class="mt-1 text-sm text-neutral-400">
|
<p class="mb-1 text-sm text-neutral-400">
|
||||||
{isOwner
|
{isOwner
|
||||||
? 'Your display name is shown publicly on your profile and pastes.'
|
? 'Your display name is shown publicly on your profile and pastes.'
|
||||||
: "This user's display name is shown publicly on their profile and pastes."}
|
: "This user's display name is shown publicly on their profile and pastes."}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-3">
|
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-3">
|
||||||
{#if isEditingDisplayName}
|
{#if isEditingDisplayName}
|
||||||
<div class="flex w-full items-center gap-2">
|
<div class="flex w-full items-center gap-2">
|
||||||
@@ -752,56 +848,50 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{:else if isOwner && activeSubTab === 'settings:security'}
|
||||||
|
<div class="col-span-2">
|
||||||
{#if isOwner}
|
|
||||||
<div class="col-span-2 md:col-span-1">
|
|
||||||
<div class="h-full rounded border border-neutral-800 bg-neutral-900/50 p-6">
|
|
||||||
<div class="mb-6 flex items-start">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-xl font-semibold text-neutral-100">Security</h2>
|
|
||||||
<p class="mt-1 text-sm text-neutral-400">
|
|
||||||
Manage your account security settings.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-3">
|
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-4">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span class="text-sm font-medium text-neutral-200"
|
<span class=" font-medium text-neutral-200">Two-Factor Authentication</span>
|
||||||
>Two-Factor Authentication</span
|
<span class="text-sm text-neutral-500"
|
||||||
>
|
|
||||||
<span class="text-xs text-neutral-500"
|
|
||||||
>{totpEnabled ? 'Enabled' : 'Disabled'}</span
|
>{totpEnabled ? 'Enabled' : 'Disabled'}</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onclick={openTotpSetup}
|
onclick={openTotpSetup}
|
||||||
class="rounded bg-neutral-700 px-3 py-1.5 text-xs font-medium transition-colors hover:bg-neutral-600"
|
class="rounded bg-neutral-700 px-3 py-1.5 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||||
>
|
>
|
||||||
{totpEnabled ? 'Manage' : 'Enable'}
|
{totpEnabled ? 'Manage' : 'Enable'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#if isOwner}
|
||||||
|
<div class="col-span-2">
|
||||||
|
<div class="flex items-center justify-between rounded bg-red-900/20 p-4">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-red-200">Delete Account</h3>
|
||||||
|
<p class="pr-0.5 text-sm text-red-200/60">
|
||||||
|
Permanently delete this account and all associated data.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onclick={openDeleteAccount}
|
||||||
|
class="rounded border border-red-500/50 bg-red-500/10 px-4 py-2 text-sm font-medium whitespace-nowrap text-red-400 transition-colors hover:bg-red-500 hover:text-white"
|
||||||
|
>
|
||||||
|
Delete Account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else if $user?.roles && hasRole($user.roles, roles.Admin) && activeSubTab === 'settings:admin'}
|
||||||
{#if $user?.roles && hasRole($user.roles, roles.Admin)}
|
<div class="col-span-2">
|
||||||
<div class="col-span-2 {isOwner ? 'md:col-span-1' : ''}">
|
|
||||||
<div class="h-full rounded border border-neutral-800 bg-neutral-900/50 p-6">
|
|
||||||
<div class="mb-6 flex items-start">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-xl font-semibold text-neutral-100">Administration</h2>
|
|
||||||
<p class="mt-1 text-sm text-neutral-400">Manage user roles and permissions.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-3">
|
<div class="flex items-center justify-between rounded bg-neutral-800/50 p-4">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span class="text-sm font-medium text-neutral-200">User Roles</span>
|
<span class="font-medium text-neutral-200">User Roles</span>
|
||||||
<span class="text-xs text-neutral-500"
|
<span class="text-sm text-neutral-500"
|
||||||
>{(() => {
|
>{(() => {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
if (data.user?.roles) {
|
if (data.user?.roles) {
|
||||||
@@ -817,27 +907,41 @@
|
|||||||
onclick={openEditRoles}
|
onclick={openEditRoles}
|
||||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||||
>
|
>
|
||||||
|
<Pencil class="h-4 w-4" />
|
||||||
|
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#if !isOwner && data.user?.roles && !hasRole(data.user.roles, roles.Admin)}
|
||||||
|
<div class="col-span-2">
|
||||||
|
<div class="flex items-center justify-between rounded bg-red-900/20 p-4">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-medium text-red-200">Delete Account</h3>
|
||||||
|
<p class="pr-0.5 text-sm text-red-200/60">
|
||||||
|
Permanently delete this account and all associated data.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onclick={openDeleteAccount}
|
||||||
|
class="rounded border border-red-500/50 bg-red-500/10 px-4 py-2 text-sm font-medium whitespace-nowrap text-red-400 transition-colors hover:bg-red-500 hover:text-white"
|
||||||
|
>
|
||||||
|
Delete Account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else if isOwner && activeSubTab === 'settings:developer'}
|
||||||
{#if isOwner}
|
|
||||||
<div class="col-span-2">
|
<div class="col-span-2">
|
||||||
<div class="rounded border border-neutral-800 bg-neutral-900/50 p-6">
|
<div class="mb-2 flex flex-col items-start justify-between">
|
||||||
<div class="mb-6 flex items-start justify-between">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-xl font-semibold text-neutral-100">
|
<h2 class="text-xl font-semibold text-neutral-100">
|
||||||
API Keys ({apiKeys.length}/10)
|
API Keys ({apiKeys.length}/10)
|
||||||
</h2>
|
</h2>
|
||||||
<p class="mt-1 text-sm text-neutral-400">
|
<p class="text-sm text-neutral-400">
|
||||||
Manage API keys for accessing Sharpbin programmatically.
|
Manage API keys for accessing Sharpbin programmatically.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if apiKeyError}
|
{#if apiKeyError}
|
||||||
<div
|
<div
|
||||||
@@ -965,37 +1069,6 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if isOwner || ($user?.roles && hasRole($user.roles, roles.Admin))}
|
|
||||||
<div class="col-span-2">
|
|
||||||
<div class="rounded border border-red-900/30 bg-red-900/10 p-6">
|
|
||||||
<div class="flex items-start">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-xl font-semibold text-red-400">Danger Zone</h2>
|
|
||||||
<p class="mt-1 text-sm text-red-200/70">
|
|
||||||
Irreversible actions related to this account.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-6 flex items-center justify-between rounded bg-red-900/20 p-4">
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium text-red-200">Delete Account</h3>
|
|
||||||
<p class="pr-0.5 text-sm text-red-200/60">
|
|
||||||
Permanently delete this account and all associated data.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onclick={openDeleteAccount}
|
|
||||||
class="rounded border border-red-500/50 bg-red-500/10 px-4 py-2 text-sm font-medium whitespace-nowrap text-red-400 transition-colors hover:bg-red-500 hover:text-white"
|
|
||||||
>
|
|
||||||
Delete Account
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else if activeTab === 'pastes'}
|
{:else if activeTab === 'pastes'}
|
||||||
|
|||||||
Reference in New Issue
Block a user