Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion web/src/routes/admin/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import SettingsIcon from '@lucide/svelte/icons/settings';
import '../../app.css';
import { getToasts } from '$lib/toast.svelte';
import { page } from '$app/state';
import { checkSession, logout } from '$lib/api';
import { checkSession, logout, listAccounts } from '$lib/api';
import type { Account } from '$lib/types';
import { fetchTimezone, getTimezone } from '$lib/tz';
import { goto } from '$app/navigation';

Expand All @@ -22,6 +23,38 @@ import SettingsIcon from '@lucide/svelte/icons/settings';
let appVersion = $state('');
let tzLabel = $state('');

// Global account switcher: akun aktif dipakai sebagai default filter
// di Schedules/Posts/Calendar (halaman tetap bisa override).
let accounts = $state<Account[]>([]);
let accountsLoaded = $state(false);
let activeAccountId = $state<string>(
typeof localStorage !== 'undefined'
? localStorage.getItem('titen.activeAccount') || 'all'
: 'all'
);

function setActiveAccount(id: string) {
activeAccountId = id;
try {
localStorage.setItem('titen.activeAccount', id);
} catch {
/* private mode — ignore */
}
}

$effect(() => {
if (!authed || accountsLoaded) return;
(async () => {
try {
accounts = (await listAccounts()) ?? [];
} catch {
/* non-fatal — switcher stays empty */
} finally {
accountsLoaded = true; // guard against re-fetch loops
}
})();
});

$effect(() => {
if (authed) return;
(async () => {
Expand Down Expand Up @@ -158,6 +191,28 @@ import SettingsIcon from '@lucide/svelte/icons/settings';
</div>

<style>
.account-switcher {
display: flex;
flex-direction: column;
gap: 0.25rem;
margin-block-end: var(--space-sm);
}

.switcher-label {
font-size: var(--text-xs);
color: var(--color-muted);
}

.switcher-select {
width: 100%;
padding: 0.375rem 0.5rem;
background: var(--surface-raised);
border: var(--rule-default);
border-radius: var(--radius-md);
color: var(--color-ink);
font-size: var(--text-sm);
}

.mobile-menu-btn {
display: none;
position: fixed;
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/media/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<Button
variant="ghost"
size="sm"
onclick={() => copyUrl(item.s3_url)}
onclick={() => copyUrl(item.s3_url ?? '')}
title="Copy URL"
>
<Copy class="size-4" />
Expand Down Expand Up @@ -365,7 +365,7 @@
{previewItem.content_type} · {formatSize(previewItem.size_bytes)}
</p>
</div>
<Button size="sm" variant="outline" onclick={() => copyUrl(previewItem!.s3_url)}>
<Button size="sm" variant="outline" onclick={() => copyUrl(previewItem!.s3_url ?? '')}>
Copy URL
</Button>
</div>
Expand Down
Loading