115 lines
3.3 KiB
Svelte
115 lines
3.3 KiB
Svelte
<script lang="ts">
|
|
import FilesIcon from '@lucide/svelte/icons/files';
|
|
import SearchIcon from '@lucide/svelte/icons/search';
|
|
import SettingsIcon from '@lucide/svelte/icons/settings';
|
|
import SunIcon from '@lucide/svelte/icons/sun';
|
|
import MoonIcon from '@lucide/svelte/icons/moon';
|
|
import RefreshIcon from '@lucide/svelte/icons/refresh-cw';
|
|
import CloudOffIcon from '@lucide/svelte/icons/cloud-off';
|
|
import { settings } from '$lib/state/settings.svelte';
|
|
import { workspace, type Panel } from '$lib/state/workspace.svelte';
|
|
import { sync } from '$lib/sync/sync.svelte';
|
|
|
|
function toggle(p: Panel) {
|
|
workspace.panel = workspace.panel === p ? null : p;
|
|
}
|
|
|
|
const syncTitle = $derived.by(() => {
|
|
switch (sync.status) {
|
|
case 'disabled':
|
|
return 'Sync not set up — open settings';
|
|
case 'offline':
|
|
return `Offline · ${sync.pending} change(s) waiting`;
|
|
case 'syncing':
|
|
return 'Syncing…';
|
|
case 'error':
|
|
return `Sync failed: ${sync.error}`;
|
|
default:
|
|
return sync.pending
|
|
? `${sync.pending} unpushed change(s) — sync now`
|
|
: `Synced${sync.lastSync ? ' ' + new Date(sync.lastSync).toLocaleTimeString() : ''}`;
|
|
}
|
|
});
|
|
|
|
function onSync() {
|
|
if (sync.status === 'disabled') workspace.settingsOpen = true;
|
|
else void sync.syncNow();
|
|
}
|
|
</script>
|
|
|
|
<nav class="ribbon" aria-label="Ribbon">
|
|
<div class="group">
|
|
<button class="icon-btn" class:active={workspace.panel === 'files'} title="Files" onclick={() => toggle('files')}>
|
|
<FilesIcon size={18} strokeWidth={1.75} />
|
|
</button>
|
|
<button class="icon-btn" class:active={workspace.panel === 'search'} title="Search (Ctrl+Shift+F)" onclick={() => toggle('search')}>
|
|
<SearchIcon size={18} strokeWidth={1.75} />
|
|
</button>
|
|
</div>
|
|
<div class="group">
|
|
<button class="icon-btn sync" title={syncTitle} onclick={onSync} data-status={sync.status}>
|
|
{#if sync.status === 'disabled' || sync.status === 'offline'}
|
|
<CloudOffIcon size={18} strokeWidth={1.75} />
|
|
{:else}
|
|
<span class:spin={sync.status === 'syncing'}><RefreshIcon size={18} strokeWidth={1.75} /></span>
|
|
{/if}
|
|
{#if sync.status === 'error'}
|
|
<i class="dot error"></i>
|
|
{:else if sync.pending > 0 && sync.status !== 'disabled'}
|
|
<i class="dot pending"></i>
|
|
{/if}
|
|
</button>
|
|
<button class="icon-btn" title={settings.dark ? 'Light theme' : 'Dark theme'} onclick={() => settings.toggleTheme()}>
|
|
{#if settings.dark}<SunIcon size={18} strokeWidth={1.75} />{:else}<MoonIcon size={18} strokeWidth={1.75} />{/if}
|
|
</button>
|
|
<button class="icon-btn" title="Settings (Ctrl+,)" onclick={() => (workspace.settingsOpen = true)}>
|
|
<SettingsIcon size={18} strokeWidth={1.75} />
|
|
</button>
|
|
</div>
|
|
</nav>
|
|
|
|
<style>
|
|
.ribbon {
|
|
width: 44px;
|
|
flex: none;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 8px 0 10px;
|
|
background: var(--bg-2);
|
|
border-right: 1px solid var(--border);
|
|
z-index: 21;
|
|
}
|
|
.group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
.sync {
|
|
position: relative;
|
|
}
|
|
.dot {
|
|
position: absolute;
|
|
top: 5px;
|
|
right: 5px;
|
|
width: 6px;
|
|
height: 6px;
|
|
border-radius: 50%;
|
|
}
|
|
.dot.pending {
|
|
background: var(--warn);
|
|
}
|
|
.dot.error {
|
|
background: var(--danger);
|
|
}
|
|
.spin {
|
|
display: inline-grid;
|
|
animation: spin 1s linear infinite;
|
|
}
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
</style>
|