1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 08:28:09 +00:00

新しいページの作成に対応

This commit is contained in:
Nebel 2022-08-24 13:17:37 +09:00
parent 86afc69f56
commit 60c86f146e
3 changed files with 10 additions and 1 deletions

View file

@ -2,6 +2,7 @@ import "./app.css";
import { createSignal } from "solid-js"; import { createSignal } from "solid-js";
import Index from "./pages/index"; import Index from "./pages/index";
import Page from "./pages/page"; import Page from "./pages/page";
import random from "./helpers/random";
const routes = { const routes = {
"/": Index, "/": Index,
@ -36,7 +37,9 @@ export default () => {
</h1> </h1>
<a href="/new">📄</a> <a href="/new">📄</a>
</header> </header>
{routes[pathname()] ?? <Page id={Number(pathname().slice(1))} />} {routes[pathname()] ?? (
<Page id={Number(pathname().slice(1)) || random()} />
)}
</> </>
); );
}; };

View file

@ -0,0 +1,5 @@
function random(): number {
return window.crypto.getRandomValues(new Uint16Array(1))[0]!;
}
export default random;

View file

@ -37,6 +37,7 @@ export default (props: { id: number }) => {
if (await updatePage(id, content)) { if (await updatePage(id, content)) {
unblock(); unblock();
refetch(); refetch();
window.history.replaceState({}, "", `/${id}`);
} }
}, },
intervalMs intervalMs