Run the SPA without a backend (local mode)

The app can now operate backend-agnostically: a production build still
asks on first start, but /setup also offers 'Continue without a backend'
(stored as the sentinel 'none'), and the shell adapts:

- Local mode shows only the e621-facing pages: Online (search, post view,
  favorites, blacklist editor, direct downloads) and Pools. Library,
  uploads, duplicates, stats, users, follows and similarity are hidden
  from the nav and palette and render a 'backend needed' state when
  reached directly; /detail/<e621 id> still works while /detail/J-x asks
  for a backend.
- e621 credentials are stored in this browser (j621.e621) and the
  Account page becomes a credentials-only screen; the store reads/writes
  locally instead of /api/auth/e621/.
- The header replaces the status pill and login/user area with an e621
  credentials button and a 'Setup Backend' button; the footer shows
  'Local mode — e621 features only' with the same entry point.
- In-library lookups (badges/browse markers) are skipped without a
  backend; 'Download to client' links straight to the e621 file instead
  of the backend proxy; follow buttons and palette follow toggles are
  hidden; api() fails fast with a clear message if something slips
  through.

Mode logic lives in lib/backend.ts (URL / '' same-origin / 'none') with
its matrix verified in Node; tsc, oxlint and the build are clean.
This commit is contained in:
2026-09-18 00:00:48 -05:00
parent 3bd5bc73dd
commit a904abdf20
19 changed files with 412 additions and 155 deletions
+45 -21
View File
@@ -1,5 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import {
Cable,
Copy,
ExternalLink,
FolderOpen,
@@ -25,6 +26,7 @@ import { useNavigate } from "react-router-dom";
import { TagChip } from "@/components/TagChip";
import { Spinner } from "@/components/ui";
import { TagFollowToggle } from "@/features/follows/TagFollowToggle";
import { hasBackend } from "@/lib/backend";
import { cn } from "@/lib/cn";
import {
effectiveCredentials,
@@ -112,13 +114,18 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
});
const commands = useMemo<Command[]>(() => {
const backend = hasBackend();
const list: Command[] = [
{
id: "library",
label: "Go to Library",
icon: FolderOpen,
run: () => navigate("/"),
},
...(backend
? [
{
id: "library",
label: "Go to Library",
icon: FolderOpen,
run: () => navigate("/"),
},
]
: []),
{
id: "online",
label: "Go to Online browser",
@@ -131,7 +138,7 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
icon: Layers,
run: () => navigate("/pools"),
},
...(user
...(backend && user
? [
{
id: "followed",
@@ -147,7 +154,7 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
},
]
: []),
...(user?.can_upload
...(backend && user?.can_upload
? [
{
id: "upload",
@@ -176,20 +183,30 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
icon: Menu,
run: toggleSidebar,
},
...(backend
? [
{
id: "search",
label: "Focus library search",
hint: "/",
icon: Search,
run: () => {
navigate("/");
window.requestAnimationFrame(() => {
document.getElementById("library-search")?.focus();
});
},
},
]
: []),
{
id: "search",
label: "Focus library search",
hint: "/",
icon: Search,
run: () => {
navigate("/");
window.requestAnimationFrame(() => {
document.getElementById("library-search")?.focus();
});
},
id: "setup",
label: backend ? "Change backend" : "Set up a backend",
icon: Cable,
run: () => navigate("/setup"),
},
];
if (user) {
if (backend && user) {
list.push({
id: "account",
label: "Account settings",
@@ -210,13 +227,20 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
icon: LogOut,
run: () => void logout(),
});
} else {
} else if (backend) {
list.push({
id: "login",
label: "Log in",
icon: LogIn,
run: () => navigate("/login"),
});
} else {
list.push({
id: "credentials",
label: "e621 credentials",
icon: Settings,
run: () => navigate("/account"),
});
}
return list;
}, [navigate, toggleSidebar, user, logout]);
@@ -326,7 +350,7 @@ function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
<span className="ml-auto font-mono text-[11px] text-ctp-overlay0">
{row.tag.post_count.toLocaleString()} posts
</span>
<TagFollowToggle tag={row.tag.name} />
{hasBackend() ? <TagFollowToggle tag={row.tag.name} /> : null}
<a
href={`https://e621.net/posts?tags=${encodeURIComponent(row.tag.name)}`}
target="_blank"