Completes M3 (SPEC §11 + §12 acceptance) on top of the backend platform (4e077f1).
Frontend host (§11.3):
- src/plugins/: manifest loader, runtime ESM bundle loader (framework-agnostic
mount contract), PluginSlot, PluginPage (app.page at /p/*), plugin context
(scoped api/events/i18n), capabilities hook. Wired slots into ThreadView
(message.actions/message.banner), MailLayout sidebar (sidebar.section + page nav)
and Settings→Accounts (settings.page); ws.ts fans out core + plugin.* events.
- plugin-ui.css: theme-aware .wm-* classes so bundles don't re-derive inline styles.
SDK additions:
- CurrentUserId + require_csrf (plugin-router auth), messages.envelope/header,
actions.set_flags/trash, sdk.enqueue.
Reference plugins (plugins/, installed via webmail.plugins entry points):
- hello: skeleton page-plugin (app.page + plg_hello_note w/ RLS + cron job) —
install→run→uninstall --drop-data leaves zero residue.
- labels: message.actions + sidebar.section slots, KV only, zero core diffs.
- filters: message.new hook -> match (subject/from/to) -> Mark read / Pin / Delete
(delete = move thread to Trash via the core path).
docs/plugins.md: full authoring guide + a complete "Unsubscribe button" worked
example (the §12 "writable from docs alone" bar).
Also: conftest resets the arq pool between tests (loop-bound global, like engine/redis).
Gates: backend ruff + mypy --strict (107) + full suite 337; frontend tsc + eslint
+ vitest (11) + vite build.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcj3TpydMTzTSmU7kunzf8
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import { useQueryClient } from "@tanstack/react-query";
|
|
import { useEffect } from "react";
|
|
import { Navigate, Route, Routes, useLocation } from "react-router-dom";
|
|
|
|
import { useMe } from "./lib/auth";
|
|
import { connectWs } from "./lib/ws";
|
|
import { PluginPage } from "./plugins/PluginPage";
|
|
import { ComposeWindow } from "./routes/ComposeWindow";
|
|
import { Login } from "./routes/Login";
|
|
import { MailLayout } from "./routes/MailLayout";
|
|
import { Register } from "./routes/Register";
|
|
import { Settings } from "./routes/settings/Settings";
|
|
import { AccountWizard } from "./routes/wizard/AccountWizard";
|
|
|
|
function RequireAuth({ children }: { children: JSX.Element }) {
|
|
const { data, isLoading, isError } = useMe();
|
|
const location = useLocation();
|
|
const queryClient = useQueryClient();
|
|
|
|
useEffect(() => {
|
|
if (!data) return;
|
|
return connectWs(queryClient);
|
|
}, [data, queryClient]);
|
|
|
|
if (isLoading) {
|
|
return <div className="p-8 text-gray-500">Loading…</div>;
|
|
}
|
|
if (isError || !data) {
|
|
return <Navigate to="/login" state={{ from: location }} replace />;
|
|
}
|
|
return children;
|
|
}
|
|
|
|
export function App() {
|
|
return (
|
|
<Routes>
|
|
<Route path="/login" element={<Login />} />
|
|
<Route path="/register" element={<Register />} />
|
|
<Route
|
|
path="/mail/*"
|
|
element={
|
|
<RequireAuth>
|
|
<MailLayout />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/compose/:draftId"
|
|
element={
|
|
<RequireAuth>
|
|
<ComposeWindow />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/p/*"
|
|
element={
|
|
<RequireAuth>
|
|
<PluginPage />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/settings/accounts/new"
|
|
element={
|
|
<RequireAuth>
|
|
<AccountWizard />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/settings/:section?"
|
|
element={
|
|
<RequireAuth>
|
|
<Settings />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route path="*" element={<Navigate to="/mail" replace />} />
|
|
</Routes>
|
|
);
|
|
}
|