68ecd881d9
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 1m9s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m39s
The deliberate offline mode is now visible: an installed web-PWA user with a confirmed email can switch to offline in Settings, and the header turns blue with an "Offline" chip. (Network gating, the dict preload, the offline lobby + local-game creation, and the service-worker precache follow in later Phase C steps.) - offline.ts / offline.svelte.ts: a sticky, device-scoped reactive offline flag (offlineMode), distinct from connection.svelte's transient reachability signal, with the pure persistence + readiness helpers (offlineReady / missingDicts) unit-tested. - Settings.svelte: an Online / Offline toggle, shown only for an installed web PWA with a confirmed email (the SW-launch + durable-account preconditions). - Header.svelte: a blue-tinted nav (color-mix from the accent, so it tracks light/dark and a Telegram theme override) + an "Offline" chip while offline; the deliberate mode suppresses the transient "Connecting…" indicator. Behaviour-preserving online (the toggle is hidden and offlineMode is false there; e2e 196 green). App entry stays within its size budget (111.6 / 112 KB gzip).
148 lines
4.1 KiB
Svelte
148 lines
4.1 KiB
Svelte
<script lang="ts">
|
|
import {
|
|
app,
|
|
setBoardLabels,
|
|
setLocalePref,
|
|
setReduceMotion,
|
|
setTheme,
|
|
} from '../lib/app.svelte';
|
|
import { t, type Locale, type MessageKey } from '../lib/i18n/index.svelte';
|
|
import type { ThemePref } from '../lib/theme';
|
|
import type { BoardLabelMode } from '../lib/boardlabels';
|
|
import { insideTelegram } from '../lib/telegram';
|
|
import { insideVK } from '../lib/vk';
|
|
import { offlineMode, setOfflineMode } from '../lib/offline.svelte';
|
|
import { isStandalone } from '../lib/pwa';
|
|
import InstallApp from '../components/InstallApp.svelte';
|
|
|
|
// The offline toggle is for the installed web PWA with a confirmed email only: the service worker
|
|
// that lets the app launch with no network runs only in a standalone web install (not a mini-app),
|
|
// and a durable account (email) anchors the device-local games. Elsewhere the control is hidden.
|
|
const offlineEligible = $derived(
|
|
isStandalone() && !insideTelegram() && !insideVK() && !!app.profile?.email,
|
|
);
|
|
|
|
const themes: ThemePref[] = ['auto', 'light', 'dark'];
|
|
const themeLabel: Record<ThemePref, MessageKey> = {
|
|
auto: 'settings.themeAuto',
|
|
light: 'settings.themeLight',
|
|
dark: 'settings.themeDark',
|
|
};
|
|
const locales: Locale[] = ['en', 'ru'];
|
|
const labelModes: BoardLabelMode[] = ['beginner', 'classic', 'none'];
|
|
const labelModeKey: Record<BoardLabelMode, MessageKey> = {
|
|
beginner: 'settings.labelsBeginner',
|
|
classic: 'settings.labelsClassic',
|
|
none: 'settings.labelsNone',
|
|
};
|
|
</script>
|
|
|
|
<div class="page">
|
|
{#if !insideTelegram()}
|
|
<section>
|
|
<h3>{t('settings.theme')}</h3>
|
|
<div class="seg">
|
|
{#each themes as th (th)}
|
|
<button class="opt" class:active={app.theme === th} onclick={() => setTheme(th)}>
|
|
{t(themeLabel[th])}
|
|
</button>
|
|
{/each}
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
<section>
|
|
<h3>{t('settings.language')}</h3>
|
|
<div class="seg">
|
|
{#each locales as lc (lc)}
|
|
<button class="opt" class:active={app.locale === lc} onclick={() => setLocalePref(lc)}>
|
|
{t(lc === 'en' ? 'lang.en' : 'lang.ru')}
|
|
</button>
|
|
{/each}
|
|
</div>
|
|
</section>
|
|
|
|
<section>
|
|
<h3>{t('settings.boardStyle')}</h3>
|
|
<div class="sub">{t('settings.boardLabels')}</div>
|
|
<div class="seg">
|
|
{#each labelModes as lm (lm)}
|
|
<button class="opt" class:active={app.boardLabels === lm} onclick={() => setBoardLabels(lm)}>
|
|
{t(labelModeKey[lm])}
|
|
</button>
|
|
{/each}
|
|
</div>
|
|
</section>
|
|
|
|
<section>
|
|
<label class="row">
|
|
<span>{t('settings.reduceMotion')}</span>
|
|
<input
|
|
type="checkbox"
|
|
checked={app.reduceMotion}
|
|
onchange={(e) => setReduceMotion(e.currentTarget.checked)}
|
|
/>
|
|
</label>
|
|
</section>
|
|
|
|
{#if offlineEligible}
|
|
<section>
|
|
<h3>{t('settings.offlineMode')}</h3>
|
|
<div class="seg">
|
|
<button class="opt" class:active={!offlineMode.active} onclick={() => setOfflineMode(false)}>
|
|
{t('settings.online')}
|
|
</button>
|
|
<button class="opt" class:active={offlineMode.active} onclick={() => setOfflineMode(true)}>
|
|
{t('settings.offline')}
|
|
</button>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
<!-- Web-only install call-to-action at the bottom of Settings (renders nothing unless the app
|
|
is installable here — see components/InstallApp.svelte / lib/pwa). -->
|
|
<InstallApp />
|
|
</div>
|
|
|
|
<style>
|
|
.page {
|
|
padding: var(--pad);
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
h3 {
|
|
margin: 0 0 8px;
|
|
font-size: 0.95rem;
|
|
color: var(--text-muted);
|
|
}
|
|
.sub {
|
|
font-size: 0.85rem;
|
|
color: var(--text-muted);
|
|
margin-bottom: 6px;
|
|
}
|
|
.seg {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
.opt {
|
|
flex: 1;
|
|
padding: 10px;
|
|
border: 1px solid var(--border);
|
|
background: var(--surface);
|
|
color: var(--text);
|
|
border-radius: var(--radius-sm);
|
|
user-select: none;
|
|
}
|
|
.opt.active {
|
|
background: var(--accent);
|
|
color: var(--accent-text);
|
|
border-color: var(--accent);
|
|
}
|
|
.row {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
</style>
|