Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad23bbfa43
|
||
|
|
36262770d0
|
No files matched your search
+13
-5
@@ -37,11 +37,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
|
||||
fine-tuned 0.75 / medium 0.5625); the weekly benchmark workflow now
|
||||
guards `small` **and** `medium`; regression-gate test updated to the
|
||||
committed baseline.
|
||||
- Dashboard dark mode: a sun/moon toggle in the header, defaulting to the OS
|
||||
preference until the user picks one (saved in localStorage, applied before
|
||||
first paint so there is no flash). Implemented by remapping the Tailwind
|
||||
palette under `html.dark` in `globals.css`, so existing pages needed no
|
||||
per-class changes.
|
||||
- Brand refresh: a hero banner in both READMEs (`docs/assets/banner.png`),
|
||||
a redesigned 1280x640 social preview (`docs/assets/social-preview.png` —
|
||||
upload it once in Settings → General → Social preview) and a 512px app
|
||||
@@ -79,6 +74,19 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
|
||||
pyproject.toml files, web/package.json, the landing site copy, the demo
|
||||
Space metadata and the fine-tuned model card.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Job progress now moves while a chunk is being transcribed, not only
|
||||
between 30-second chunks. A clip shorter than 30 s is a single chunk, so
|
||||
its progress sat at 0% for the whole job and then jumped to 100%. The
|
||||
Whisper engine reports how far into the chunk it is as each segment is
|
||||
decoded; the worker saves that at most once a second.
|
||||
- The archive page refreshes itself while any job is queued or processing;
|
||||
its progress bars never moved before. A job with no progress reported yet
|
||||
shows a moving bar and "Getting ready" instead of an empty, stuck-looking
|
||||
bar at 0%, and the job page shows the percentage with the right sign in
|
||||
English.
|
||||
|
||||
## [1.4.1] - 2026-11-26
|
||||
|
||||
### Security
|
||||
|
||||
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import math
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Protocol
|
||||
|
||||
@@ -36,15 +37,30 @@ class Segment:
|
||||
speaker: str | None = None
|
||||
|
||||
|
||||
# Called with the fraction (0..1) of the current chunk decoded so far.
|
||||
ProgressCallback = Callable[[float], None]
|
||||
|
||||
|
||||
class Transcriber(Protocol):
|
||||
def transcribe(
|
||||
self, samples: np.ndarray, sample_rate: int, language: str
|
||||
) -> list[Segment]: ...
|
||||
|
||||
|
||||
def reports_progress(engine: object) -> bool:
|
||||
"""Whether `engine.transcribe` accepts an `on_progress` callback.
|
||||
|
||||
Opt-in via a class attribute, so third-party engines and test doubles
|
||||
with the plain three-argument signature keep working unchanged.
|
||||
"""
|
||||
return bool(getattr(engine, "reports_progress", False))
|
||||
|
||||
|
||||
class FasterWhisperTranscriber:
|
||||
"""Chunk-local transcription with faster-whisper."""
|
||||
|
||||
reports_progress = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model_size: str | None = None,
|
||||
@@ -73,7 +89,11 @@ class FasterWhisperTranscriber:
|
||||
return self._model
|
||||
|
||||
def transcribe(
|
||||
self, samples: np.ndarray, sample_rate: int, language: str
|
||||
self,
|
||||
samples: np.ndarray,
|
||||
sample_rate: int,
|
||||
language: str,
|
||||
on_progress: ProgressCallback | None = None,
|
||||
) -> list[Segment]:
|
||||
model = self._load()
|
||||
settings = get_settings()
|
||||
@@ -86,8 +106,13 @@ class FasterWhisperTranscriber:
|
||||
if language and language != "auto":
|
||||
options["language"] = language
|
||||
segments_iter, _info = model.transcribe(samples, **options) # type: ignore[arg-type]
|
||||
chunk_seconds = len(samples) / sample_rate
|
||||
segments: list[Segment] = []
|
||||
# faster-whisper decodes lazily, segment by segment, so each step of
|
||||
# this loop is real work done: report how far into the chunk it is.
|
||||
for segment in segments_iter:
|
||||
if on_progress is not None and chunk_seconds > 0:
|
||||
on_progress(min(1.0, float(segment.end) / chunk_seconds))
|
||||
text = segment.text.strip()
|
||||
if not text:
|
||||
continue
|
||||
@@ -107,8 +132,14 @@ class FasterWhisperTranscriber:
|
||||
class FakeTranscriber:
|
||||
"""Deterministic engine for tests: one or two fixed Persian segments."""
|
||||
|
||||
reports_progress = True
|
||||
|
||||
def transcribe(
|
||||
self, samples: np.ndarray, sample_rate: int, language: str
|
||||
self,
|
||||
samples: np.ndarray,
|
||||
sample_rate: int,
|
||||
language: str,
|
||||
on_progress: ProgressCallback | None = None,
|
||||
) -> list[Segment]:
|
||||
duration = len(samples) / sample_rate
|
||||
segments: list[Segment] = []
|
||||
@@ -132,6 +163,9 @@ class FakeTranscriber:
|
||||
confidence=0.741,
|
||||
)
|
||||
)
|
||||
if on_progress is not None and duration > 0:
|
||||
for segment in segments:
|
||||
on_progress(min(1.0, segment.end / duration))
|
||||
return segments
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ never hold a transaction open.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import time
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import replace
|
||||
from typing import Any
|
||||
@@ -41,7 +42,7 @@ from sokhan.core.persian import normalize_for_search
|
||||
from sokhan.core.punctuation import restore_punctuation
|
||||
from sokhan.core.quota import record_usage
|
||||
from sokhan.core.summary import Summarizer, get_summarizer
|
||||
from sokhan.core.transcribe import Transcriber, get_transcriber
|
||||
from sokhan.core.transcribe import Transcriber, get_transcriber, reports_progress
|
||||
from sokhan.core.webhooks import build_payload, fire_job_callback
|
||||
from sokhan.db import session_scope
|
||||
from sokhan.diarization import Diarizer, SpeakerTurn, get_diarizer, label_segments
|
||||
@@ -50,6 +51,11 @@ from sokhan.models import Job, JobStatus, Segment, utcnow
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Clock for throttling progress writes; a module attribute so tests can
|
||||
# swap it without patching the process-wide `time.monotonic`.
|
||||
_progress_clock = time.monotonic
|
||||
|
||||
|
||||
def process_job(
|
||||
job_id: str,
|
||||
transcriber: Transcriber | None = None,
|
||||
@@ -123,11 +129,38 @@ def process_job(
|
||||
|
||||
chunk_segments = []
|
||||
chunk_starts = []
|
||||
last_saved_at = float("-inf")
|
||||
|
||||
def save_progress(value: float) -> None:
|
||||
"""Persist mid-chunk progress: monotonic, below 100, ~1/s."""
|
||||
nonlocal last_saved_at
|
||||
value = min(99.0, round(value, 1))
|
||||
now = _progress_clock()
|
||||
if value <= (job.progress or 0.0) or now - last_saved_at < 1.0:
|
||||
return
|
||||
job.progress = value
|
||||
session.commit()
|
||||
last_saved_at = now
|
||||
|
||||
for position, chunk in enumerate(chunk_source, start=1):
|
||||
chunk_starts.append(chunk.start)
|
||||
chunk_segments.append(
|
||||
engine.transcribe(chunk.samples, SAMPLE_RATE, job.language)
|
||||
)
|
||||
|
||||
def chunk_progress(
|
||||
fraction: float, position: int = position, chunk: Chunk = chunk
|
||||
) -> None:
|
||||
if chunk_total is not None:
|
||||
save_progress((position - 1 + fraction) / chunk_total * 100.0)
|
||||
elif estimated_duration:
|
||||
done = chunk.start + fraction * (chunk.end - chunk.start)
|
||||
save_progress(done / estimated_duration * 99.0)
|
||||
|
||||
if reports_progress(engine):
|
||||
segments = engine.transcribe( # type: ignore[call-arg]
|
||||
chunk.samples, SAMPLE_RATE, job.language, on_progress=chunk_progress
|
||||
)
|
||||
else:
|
||||
segments = engine.transcribe(chunk.samples, SAMPLE_RATE, job.language)
|
||||
chunk_segments.append(segments)
|
||||
if chunk_total is not None:
|
||||
job.progress = round(position / chunk_total * 100.0, 1)
|
||||
elif estimated_duration:
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
"""Job progress moves while a chunk is being decoded, not only between chunks.
|
||||
|
||||
A clip shorter than the 30 s window is a single chunk, so chunk-level
|
||||
progress alone sat at 0% for the whole job and then jumped to 100%.
|
||||
"""
|
||||
|
||||
import sokhan.db as db
|
||||
from sokhan.core.transcribe import FakeTranscriber, Segment, reports_progress
|
||||
from sokhan.models import Job
|
||||
|
||||
|
||||
class SlowEngine:
|
||||
"""Reports four steps through the chunk and records what the DB shows."""
|
||||
|
||||
reports_progress = True
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.seen: list[float] = []
|
||||
|
||||
def transcribe(self, samples, sample_rate, language, on_progress=None):
|
||||
for fraction in (0.25, 0.5, 0.75, 1.0):
|
||||
on_progress(fraction)
|
||||
with db.session_scope() as other:
|
||||
job = other.query(Job).one()
|
||||
self.seen.append(job.progress)
|
||||
return [Segment(start=0.0, end=1.0, text="سلام")]
|
||||
|
||||
|
||||
class PlainEngine:
|
||||
"""A third-party engine with the original three-argument signature."""
|
||||
|
||||
def transcribe(self, samples, sample_rate, language):
|
||||
return [Segment(start=0.0, end=1.0, text="سلام")]
|
||||
|
||||
|
||||
def _upload(client, auth, wav_bytes):
|
||||
response = client.post(
|
||||
"/jobs",
|
||||
files={"file": ("clip.wav", wav_bytes, "audio/wav")},
|
||||
data={"language": "fa"},
|
||||
headers=auth,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
return response.json()["id"]
|
||||
|
||||
|
||||
def test_progress_is_saved_inside_a_single_chunk(
|
||||
client, auth, wav_bytes, wait_for_job, monkeypatch
|
||||
):
|
||||
engine = SlowEngine()
|
||||
monkeypatch.setattr("sokhan.worker.pipeline.get_transcriber", lambda: engine)
|
||||
ticks = iter(range(0, 1000, 2)) # every call is 2 s later: never throttled
|
||||
monkeypatch.setattr("sokhan.worker.pipeline._progress_clock", lambda: float(next(ticks)))
|
||||
|
||||
job_id = _upload(client, auth, wav_bytes)
|
||||
wait_for_job(client, auth, job_id)
|
||||
|
||||
assert engine.seen == sorted(engine.seen)
|
||||
assert 0 < engine.seen[0] < engine.seen[-1] <= 99.0
|
||||
assert client.get(f"/jobs/{job_id}", headers=auth).json()["progress"] == 100.0
|
||||
|
||||
|
||||
def test_progress_writes_are_throttled(client, auth, wav_bytes, wait_for_job, monkeypatch):
|
||||
engine = SlowEngine()
|
||||
monkeypatch.setattr("sokhan.worker.pipeline.get_transcriber", lambda: engine)
|
||||
monkeypatch.setattr("sokhan.worker.pipeline._progress_clock", lambda: 5.0)
|
||||
|
||||
wait_for_job(client, auth, _upload(client, auth, wav_bytes))
|
||||
|
||||
# Same instant for every report: only the first one reaches the database.
|
||||
assert len(set(engine.seen)) == 1
|
||||
|
||||
|
||||
def test_engines_without_progress_support_still_work(
|
||||
client, auth, wav_bytes, wait_for_job, monkeypatch
|
||||
):
|
||||
assert not reports_progress(PlainEngine())
|
||||
monkeypatch.setattr("sokhan.worker.pipeline.get_transcriber", lambda: PlainEngine())
|
||||
|
||||
job_id = _upload(client, auth, wav_bytes)
|
||||
|
||||
assert wait_for_job(client, auth, job_id)["status"] == "completed"
|
||||
|
||||
|
||||
def test_fake_engine_reports_fractions_up_to_the_end():
|
||||
seen: list[float] = []
|
||||
import numpy as np
|
||||
|
||||
FakeTranscriber().transcribe(np.zeros(16000 * 4, dtype=np.float32), 16000, "fa", seen.append)
|
||||
|
||||
assert seen == sorted(seen) and seen[-1] == 1.0
|
||||
@@ -15,9 +15,7 @@
|
||||
"new": "New transcription",
|
||||
"archive": "Archive",
|
||||
"switchToEn": "English",
|
||||
"switchToFa": "فارسی",
|
||||
"themeToDark": "Switch to dark theme",
|
||||
"themeToLight": "Switch to light theme"
|
||||
"switchToFa": "فارسی"
|
||||
},
|
||||
"landing": {
|
||||
"headline": "From speech to text, in moments",
|
||||
@@ -102,6 +100,7 @@
|
||||
"statusFailed": "Failed",
|
||||
"progressLabel": "Processing progress",
|
||||
"percent": "{value}%",
|
||||
"preparing": "Getting ready…",
|
||||
"emptyTitle": "No transcriptions yet",
|
||||
"emptyDesc": "Upload your first file and it will show up here.",
|
||||
"emptyCta": "New transcription",
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
"new": "رونویسی تازه",
|
||||
"archive": "آرشیو",
|
||||
"switchToEn": "English",
|
||||
"switchToFa": "فارسی",
|
||||
"themeToDark": "تم تیره",
|
||||
"themeToLight": "تم روشن"
|
||||
"switchToFa": "فارسی"
|
||||
},
|
||||
"landing": {
|
||||
"headline": "از گفتار به متن، در چند لحظه",
|
||||
@@ -102,6 +100,7 @@
|
||||
"statusFailed": "ناموفق",
|
||||
"progressLabel": "پیشرفت پردازش",
|
||||
"percent": "{value}٪",
|
||||
"preparing": "در حال آمادهسازی…",
|
||||
"emptyTitle": "هنوز رونویسیای نداری",
|
||||
"emptyDesc": "اولین فایل را بارگذاری کن تا همینجا فهرست شود.",
|
||||
"emptyCta": "رونویسی تازه",
|
||||
|
||||
@@ -67,6 +67,7 @@ export default function JobDetailPage() {
|
||||
const { id: jobId } = useParams<{ id: string }>();
|
||||
const locale = useLocale();
|
||||
const t = useTranslations("jobDetail");
|
||||
const tj = useTranslations("jobs");
|
||||
const tc = useTranslations("common");
|
||||
const te = useTranslations("errors");
|
||||
const router = useRouter();
|
||||
@@ -275,12 +276,15 @@ export default function JobDetailPage() {
|
||||
<h2 className="font-bold text-stone-900">{t("processingTitle")}</h2>
|
||||
<p className="mt-1.5 text-sm leading-7 text-stone-600">{t("processingDesc")}</p>
|
||||
<div className="mt-4">
|
||||
<ProgressBar value={job.progress} label={t("metaDuration")} />
|
||||
<p className="mt-1.5 text-xs text-stone-500">
|
||||
{new Intl.NumberFormat(locale).format(
|
||||
Math.min(100, Math.max(0, Math.round(job.progress))),
|
||||
)}
|
||||
٪
|
||||
<ProgressBar value={job.progress} label={tj("progressLabel")} />
|
||||
<p className="mt-1.5 text-xs text-stone-500" aria-live="polite">
|
||||
{job.progress > 0
|
||||
? tj("percent", {
|
||||
value: new Intl.NumberFormat(locale).format(
|
||||
Math.min(100, Math.round(job.progress)),
|
||||
),
|
||||
})
|
||||
: tj("preparing")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,8 @@ function formatDate(iso: string, locale: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
const REFRESH_INTERVAL_MS = 3000;
|
||||
|
||||
export default function JobsPage() {
|
||||
const t = useTranslations("jobs");
|
||||
const tc = useTranslations("common");
|
||||
@@ -35,6 +37,8 @@ export default function JobsPage() {
|
||||
const [query, setQuery] = useState("");
|
||||
const [items, setItems] = useState<JobListItem[] | null>(null);
|
||||
const [listError, setListError] = useState<string | null>(null);
|
||||
// Bumped to re-fetch the list while any job is still queued or processing.
|
||||
const [refreshTick, setRefreshTick] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) router.replace("/login");
|
||||
@@ -72,7 +76,15 @@ export default function JobsPage() {
|
||||
cancelled = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [query]);
|
||||
}, [query, refreshTick]);
|
||||
|
||||
const hasRunningJobs =
|
||||
items?.some((job) => job.status === "queued" || job.status === "processing") ?? false;
|
||||
useEffect(() => {
|
||||
if (!hasRunningJobs) return;
|
||||
const timer = setTimeout(() => setRefreshTick((tick) => tick + 1), REFRESH_INTERVAL_MS);
|
||||
return () => clearTimeout(timer);
|
||||
}, [hasRunningJobs, items]);
|
||||
|
||||
const hasQuery = query.trim().length > 0;
|
||||
|
||||
@@ -169,13 +181,15 @@ export default function JobsPage() {
|
||||
<StatusBadge status={job.status} />
|
||||
</div>
|
||||
</div>
|
||||
{job.status === "processing" ? (
|
||||
{job.status === "queued" || job.status === "processing" ? (
|
||||
<div className="mt-4">
|
||||
<ProgressBar value={job.progress} label={t("progressLabel")} />
|
||||
<p className="mt-1.5 text-xs text-stone-500">
|
||||
{t("percent", {
|
||||
value: nf.format(Math.min(100, Math.max(0, job.progress))),
|
||||
})}
|
||||
{job.progress > 0
|
||||
? t("percent", {
|
||||
value: nf.format(Math.min(100, Math.round(job.progress))),
|
||||
})
|
||||
: t("preparing")}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { getTranslations, setRequestLocale } from "next-intl/server";
|
||||
import localFont from "next/font/local";
|
||||
import { routing } from "@/i18n/routing";
|
||||
import { SiteHeader } from "@/components/site-header";
|
||||
import { themeInitScript } from "@/lib/theme";
|
||||
import "../globals.css";
|
||||
|
||||
// Fonts are self-hosted (see src/fonts/README.txt): builds must never depend
|
||||
@@ -48,10 +47,7 @@ export async function generateMetadata({
|
||||
}
|
||||
|
||||
export const viewport: Viewport = {
|
||||
themeColor: [
|
||||
{ media: "(prefers-color-scheme: light)", color: "#0f766e" },
|
||||
{ media: "(prefers-color-scheme: dark)", color: "#134e4a" },
|
||||
],
|
||||
themeColor: "#0f766e",
|
||||
};
|
||||
|
||||
export default async function LocaleLayout({
|
||||
@@ -68,10 +64,7 @@ export default async function LocaleLayout({
|
||||
const t = await getTranslations("common");
|
||||
|
||||
return (
|
||||
<html lang={locale} dir={locale === "fa" ? "rtl" : "ltr"} suppressHydrationWarning>
|
||||
<head>
|
||||
<script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
|
||||
</head>
|
||||
<html lang={locale} dir={locale === "fa" ? "rtl" : "ltr"}>
|
||||
<body
|
||||
className={`${vazirmatn.variable} ${inter.variable} flex min-h-screen flex-col bg-stone-50 text-stone-900 antialiased`}
|
||||
>
|
||||
|
||||
+10
-74
@@ -1,10 +1,18 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
@theme {
|
||||
--font-vazir: var(--font-vazirmatn, Vazirmatn), var(--font-inter, Inter), ui-sans-serif,
|
||||
system-ui, sans-serif;
|
||||
--animate-progress-indeterminate: progress-indeterminate 1.4s ease-in-out infinite;
|
||||
|
||||
@keyframes progress-indeterminate {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(250%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
@@ -23,75 +31,3 @@ html[lang="en"] body {
|
||||
background-color: #99f6e4;
|
||||
color: #134e4a;
|
||||
}
|
||||
|
||||
html.dark {
|
||||
color-scheme: dark;
|
||||
|
||||
--color-stone-50: oklch(14.7% 0.004 49.25);
|
||||
--color-stone-100: oklch(26.8% 0.007 34.298);
|
||||
--color-stone-200: oklch(30% 0.007 34.298);
|
||||
--color-stone-300: oklch(40% 0.01 67.558);
|
||||
--color-stone-400: oklch(55.3% 0.013 58.071);
|
||||
--color-stone-500: oklch(70.9% 0.01 56.259);
|
||||
--color-stone-600: oklch(80% 0.005 56.366);
|
||||
--color-stone-700: oklch(86.9% 0.005 56.366);
|
||||
--color-stone-800: oklch(92.3% 0.003 48.717);
|
||||
--color-stone-900: oklch(97% 0.001 106.424);
|
||||
--color-stone-950: oklch(98.5% 0.001 106.423);
|
||||
|
||||
--color-teal-50: oklch(27.7% 0.046 192.524);
|
||||
--color-teal-100: oklch(32% 0.055 190);
|
||||
--color-teal-200: oklch(38.6% 0.063 188.416);
|
||||
--color-teal-800: oklch(85.5% 0.138 181.071);
|
||||
--color-teal-900: oklch(91% 0.096 180.426);
|
||||
--color-teal-950: oklch(95.3% 0.051 180.801);
|
||||
|
||||
--color-red-50: oklch(25.8% 0.092 26.042);
|
||||
--color-red-100: oklch(30% 0.11 26);
|
||||
--color-red-200: oklch(39.6% 0.141 25.723);
|
||||
--color-red-700: oklch(80.8% 0.114 19.571);
|
||||
--color-red-800: oklch(88.5% 0.062 18.334);
|
||||
--color-red-900: oklch(93.6% 0.032 17.717);
|
||||
|
||||
--color-amber-100: oklch(27.9% 0.077 45.635);
|
||||
--color-amber-800: oklch(92.4% 0.12 95.746);
|
||||
|
||||
--color-emerald-100: oklch(26.2% 0.051 172.552);
|
||||
--color-emerald-800: oklch(90.5% 0.093 164.15);
|
||||
|
||||
--sokhan-surface: oklch(19% 0.005 56);
|
||||
}
|
||||
|
||||
html.dark body {
|
||||
background-color: var(--color-stone-50);
|
||||
color: var(--color-stone-900);
|
||||
}
|
||||
|
||||
html.dark ::selection {
|
||||
background-color: #115e59;
|
||||
color: #f0fdfa;
|
||||
}
|
||||
|
||||
html.dark .bg-white {
|
||||
background-color: var(--sokhan-surface);
|
||||
}
|
||||
html.dark .bg-white\/90 {
|
||||
background-color: color-mix(in oklab, var(--sokhan-surface) 90%, transparent);
|
||||
}
|
||||
html.dark .supports-\[backdrop-filter\]\:bg-white\/75 {
|
||||
@supports (backdrop-filter: var(--tw)) {
|
||||
background-color: color-mix(in oklab, var(--sokhan-surface) 75%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
html.dark .text-teal-600,
|
||||
html.dark .text-teal-700 {
|
||||
color: oklch(77.7% 0.152 181.912);
|
||||
}
|
||||
html.dark .text-teal-700\/60 {
|
||||
color: color-mix(in oklab, oklch(77.7% 0.152 181.912) 60%, transparent);
|
||||
}
|
||||
|
||||
html.dark * {
|
||||
--tw-ring-offset-color: var(--sokhan-surface);
|
||||
}
|
||||
@@ -34,8 +34,14 @@ export function StatusBadge({ status }: { status: JobStatus }) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determinate bar once the worker reports progress. While nothing has been
|
||||
* reported yet (queued, model loading, first seconds of decoding) it shows
|
||||
* a moving bar instead of an empty track that looks stuck.
|
||||
*/
|
||||
export function ProgressBar({ value, label }: { value: number; label?: string }) {
|
||||
const clamped = Math.min(100, Math.max(0, value));
|
||||
const indeterminate = clamped <= 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -43,13 +49,18 @@ export function ProgressBar({ value, label }: { value: number; label?: string })
|
||||
role="progressbar"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={Math.round(clamped)}
|
||||
aria-valuenow={indeterminate ? undefined : Math.round(clamped)}
|
||||
aria-busy={indeterminate || undefined}
|
||||
aria-label={label}
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full bg-teal-700 transition-[width] duration-500 ease-out"
|
||||
style={{ width: `${clamped}%` }}
|
||||
/>
|
||||
{indeterminate ? (
|
||||
<div className="h-full w-2/5 rounded-full bg-teal-700/70 animate-progress-indeterminate motion-reduce:w-full motion-reduce:animate-pulse" />
|
||||
) : (
|
||||
<div
|
||||
className="h-full rounded-full bg-teal-700 transition-[width] duration-500 ease-out"
|
||||
style={{ width: `${clamped}%` }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { AudioLines } from "lucide-react";
|
||||
import { Link, usePathname, useRouter } from "@/i18n/navigation";
|
||||
import { ThemeToggle } from "@/components/theme-toggle";
|
||||
|
||||
export function SiteHeader() {
|
||||
const t = useTranslations("nav");
|
||||
@@ -61,7 +60,6 @@ export function SiteHeader() {
|
||||
>
|
||||
{otherLocale === "en" ? "EN" : "فا"}
|
||||
</button>
|
||||
<ThemeToggle />
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Moon, Sun } from "lucide-react";
|
||||
import { THEME_STORAGE_KEY, type Theme } from "@/lib/theme";
|
||||
|
||||
function applyTheme(theme: Theme) {
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
}
|
||||
|
||||
export function ThemeToggle() {
|
||||
const t = useTranslations("nav");
|
||||
const [theme, setTheme] = useState<Theme | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setTheme(document.documentElement.classList.contains("dark") ? "dark" : "light");
|
||||
|
||||
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const onChange = (event: MediaQueryListEvent) => {
|
||||
let saved: string | null = null;
|
||||
try {
|
||||
saved = window.localStorage.getItem(THEME_STORAGE_KEY);
|
||||
} catch {
|
||||
}
|
||||
if (saved === "light" || saved === "dark") return;
|
||||
const next: Theme = event.matches ? "dark" : "light";
|
||||
applyTheme(next);
|
||||
setTheme(next);
|
||||
};
|
||||
media.addEventListener("change", onChange);
|
||||
return () => media.removeEventListener("change", onChange);
|
||||
}, []);
|
||||
|
||||
const isDark = theme === "dark";
|
||||
|
||||
function toggle() {
|
||||
const next: Theme = isDark ? "light" : "dark";
|
||||
applyTheme(next);
|
||||
setTheme(next);
|
||||
try {
|
||||
window.localStorage.setItem(THEME_STORAGE_KEY, next);
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
const label = isDark ? t("themeToLight") : t("themeToDark");
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className="flex h-9 w-9 items-center justify-center rounded-lg border border-stone-300 text-stone-700 transition-colors hover:border-teal-700 hover:text-teal-800 focus-visible:ring-2 focus-visible:ring-teal-700"
|
||||
>
|
||||
{isDark ? (
|
||||
<Sun className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<Moon className="h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export const THEME_STORAGE_KEY = "sokhan-theme";
|
||||
|
||||
export type Theme = "light" | "dark";
|
||||
|
||||
export const themeInitScript = `(function(){try{var t=localStorage.getItem("${THEME_STORAGE_KEY}");if(t!=="light"&&t!=="dark"){t=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}document.documentElement.classList.toggle("dark",t==="dark")}catch(e){}})();`;
|
||||
Reference in new issue
Block a user