From 887eafef4d197a63f23817af1ab459f2c61ed5ec Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Mon, 29 Aug 2022 10:39:16 +0900 Subject: [PATCH] use 31bit random hex id --- app/src/app.tsx | 4 +++- app/src/helpers/random.ts | 2 +- app/src/pages/index.tsx | 2 +- app/src/pages/page.tsx | 6 +++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/app.tsx b/app/src/app.tsx index e01a788..a6ba7d8 100644 --- a/app/src/app.tsx +++ b/app/src/app.tsx @@ -38,7 +38,9 @@ export default () => { 📄 {routes[pathname()] ?? ( - + )} ); diff --git a/app/src/helpers/random.ts b/app/src/helpers/random.ts index 94f9e8e..34d9d0b 100644 --- a/app/src/helpers/random.ts +++ b/app/src/helpers/random.ts @@ -1,5 +1,5 @@ function random(): number { - return window.crypto.getRandomValues(new Uint16Array(1))[0]!; + return 0x7f_ff_ff_ff & window.crypto.getRandomValues(new Uint32Array(1))[0]!; } export default random; diff --git a/app/src/pages/index.tsx b/app/src/pages/index.tsx index 84590f9..ce669f3 100644 --- a/app/src/pages/index.tsx +++ b/app/src/pages/index.tsx @@ -20,7 +20,7 @@ export default () => { {(page) => ( - + )} diff --git a/app/src/pages/page.tsx b/app/src/pages/page.tsx index ccc1596..9cab838 100644 --- a/app/src/pages/page.tsx +++ b/app/src/pages/page.tsx @@ -44,7 +44,11 @@ export default (props: { id: number }) => { async (id: number, content: Pages.RequestContentPage) => { if (await (content.text ? updatePage(id, content) : deletePage(id))) { unblock(); - window.history.replaceState({}, "", `/${content.text ? id : "new"}`); + window.history.replaceState( + {}, + "", + `/${content.text ? id.toString(16) : "new"}` + ); } }, intervalMs