mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 20:27:13 +01:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWXTUM9dpnCS2wtFkx4
2.9 KiB
2.9 KiB
Migrate screen-locker/web to Astro (no React)
what
The status page in web/ (now/health/why cards, polling /api/status)
becomes one Astro 7 static page. Its <script> polls and renders in vanilla
TS. python -m screen_locker._web_server keeps serving web/dist on
127.0.0.1:8770.
steps
- Do
~/src/utils/web_ui/TODO-astro-port.mdfirst. Then add@kuhyx/web-uiat the new tag, fortokens.cssonly. This repo does not use it yet. - Use a single page,
src/pages/index.astro. There is no routing today, so_web_server.pyand its SPA fallback need no change. - Rewrite the four React files:
App.tsxbecomesindex.astropluslayouts/Base.astro.components/NowCard.tsx,HealthCard.tsxandWhyTable.tsxbecome.astroshells withdata-*slots, filled by a renderer insrc/render.ts.- Hook
useStatusPoll.tsbecomessrc/poll.ts, a plain poller class withstart(),stop()and a callback. It stops onvisibilitychangehidden, as now. api.ts,format.tsandtypes.tsstay as they are.
- The
<script>inindex.astroonly wirespoll.tstorender.ts. The logic stays in.tsfiles so the coverage thresholds still apply. - Dependencies, from
web/, exact pins via pnpm:- Add
astro@7.4.4,@astrojs/check@0.9.12andeslint-plugin-astro@3.2.1. - Remove
react,react-dom,@vitejs/plugin-react,@testing-library/react,eslint-plugin-react-hooksandeslint-plugin-react-refresh. - Drop direct
vite(Astro brings^8.3.5). - Fold
tsconfig.app.json,tsconfig.node.jsonandtsconfig.test.jsoninto Astro'stsconfigpreset where possible.
- Add
- Tests. Use vitest 5.0.5 with
getViteConfig():render.tsandpoll.tsare tested in jsdom with@testing-library/domand fake timers.src/test/factories.tsstays.- One Container API test checks that the page shell renders.
buildbecomesastro check && astro build, outputweb/dist.- There is no
[agent_ready]table. It is a loopback status page, so skip AgentReady.
done
Run from web/:
pnpm install --frozen-lockfile && pnpm lint && pnpm coverage && pnpm build
Then:
! grep -q '"react"' package.json && ! grep -qE '"(react-dom|@vitejs/plugin-react)"' package.json && ! find src -name '*.tsx' | grep -q .
Both exit 0. The Python web-server tests still pass:
python -m pytest -q screen_locker/tests/test_web_server.py screen_locker/tests/test_web_server_part2.py
verify
Run systemctl --user restart screen-locker-web.service. Then:
curl -s http://127.0.0.1:8770/ | grep -q '<h1'- Use a headless chromium at 4K and at mobile size. All three cards fill within one poll, and there are no console errors.
read first
~/src/utils/web_ui/TODO-astro-port.md(do it first)web/src/App.tsx,web/src/useStatusPoll.ts,web/src/api.tsscreen_locker/_web_server.py,screen-locker-web.service
REMOVE ME AFTER FINISH