diff --git a/examples/share-notes/.gitignore b/examples/flush-notes/.gitignore similarity index 100% rename from examples/share-notes/.gitignore rename to examples/flush-notes/.gitignore diff --git a/examples/share-notes/README.md b/examples/flush-notes/README.md similarity index 100% rename from examples/share-notes/README.md rename to examples/flush-notes/README.md diff --git a/examples/share-notes/next.config.js b/examples/flush-notes/next.config.js similarity index 100% rename from examples/share-notes/next.config.js rename to examples/flush-notes/next.config.js diff --git a/examples/share-notes/package-lock.json b/examples/flush-notes/package-lock.json similarity index 99% rename from examples/share-notes/package-lock.json rename to examples/flush-notes/package-lock.json index b9fb282..0cda551 100644 --- a/examples/share-notes/package-lock.json +++ b/examples/flush-notes/package-lock.json @@ -1,11 +1,11 @@ { - "name": "flush-notes", + "name": "share-notes", "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "flush-notes", + "name": "share-notes", "version": "0.1.0", "dependencies": { "@waku/interfaces": "^0.0.20", diff --git a/examples/share-notes/package.json b/examples/flush-notes/package.json similarity index 96% rename from examples/share-notes/package.json rename to examples/flush-notes/package.json index 89e83ef..63029cd 100644 --- a/examples/share-notes/package.json +++ b/examples/flush-notes/package.json @@ -1,5 +1,5 @@ { - "name": "share-notes", + "name": "flush-notes", "version": "0.1.0", "private": true, "scripts": { diff --git a/examples/share-notes/postcss.config.js b/examples/flush-notes/postcss.config.js similarity index 100% rename from examples/share-notes/postcss.config.js rename to examples/flush-notes/postcss.config.js diff --git a/examples/share-notes/src/app/Loading.tsx b/examples/flush-notes/src/app/Loading.tsx similarity index 100% rename from examples/share-notes/src/app/Loading.tsx rename to examples/flush-notes/src/app/Loading.tsx diff --git a/examples/share-notes/src/app/WakuProvider.tsx b/examples/flush-notes/src/app/WakuProvider.tsx similarity index 100% rename from examples/share-notes/src/app/WakuProvider.tsx rename to examples/flush-notes/src/app/WakuProvider.tsx diff --git a/examples/share-notes/src/app/favicon.ico b/examples/flush-notes/src/app/favicon.ico similarity index 100% rename from examples/share-notes/src/app/favicon.ico rename to examples/flush-notes/src/app/favicon.ico diff --git a/examples/share-notes/src/app/globals.css b/examples/flush-notes/src/app/globals.css similarity index 100% rename from examples/share-notes/src/app/globals.css rename to examples/flush-notes/src/app/globals.css diff --git a/examples/share-notes/src/app/layout.tsx b/examples/flush-notes/src/app/layout.tsx similarity index 100% rename from examples/share-notes/src/app/layout.tsx rename to examples/flush-notes/src/app/layout.tsx diff --git a/examples/share-notes/src/app/page.tsx b/examples/flush-notes/src/app/page.tsx similarity index 100% rename from examples/share-notes/src/app/page.tsx rename to examples/flush-notes/src/app/page.tsx diff --git a/examples/share-notes/src/app/view/page.tsx b/examples/flush-notes/src/app/view/page.tsx similarity index 70% rename from examples/share-notes/src/app/view/page.tsx rename to examples/flush-notes/src/app/view/page.tsx index f58308d..f198559 100644 --- a/examples/share-notes/src/app/view/page.tsx +++ b/examples/flush-notes/src/app/view/page.tsx @@ -3,23 +3,23 @@ import React from "react"; import Markdown from "react-markdown"; import { useRouter } from "next/navigation"; -import { useNoteHash } from "@/hooks/useNoteHash"; +import { useNoteURL } from "@/hooks/useNoteURL"; import { notes } from "@/services/notes"; import { Loading } from "../Loading"; const View = () => { const router = useRouter(); - const noteHash = useNoteHash(); + const { id, password } = useNoteURL(); const [note, setNote] = React.useState(""); React.useEffect(() => { - if (!noteHash) { + if (!id) { router.replace("/404"); return; } - notes.readNote(noteHash).then((note) => setNote(note || "")); - }, [noteHash, setNote]); + notes.readNote(id, password).then((note) => setNote(note || "")); + }, [id, password, setNote]); if (!note) { return ; diff --git a/examples/share-notes/src/const.ts b/examples/flush-notes/src/const.ts similarity index 100% rename from examples/share-notes/src/const.ts rename to examples/flush-notes/src/const.ts diff --git a/examples/flush-notes/src/hooks/useNoteURL.ts b/examples/flush-notes/src/hooks/useNoteURL.ts new file mode 100644 index 0000000..b8e8989 --- /dev/null +++ b/examples/flush-notes/src/hooks/useNoteURL.ts @@ -0,0 +1,15 @@ +"use client"; +import { usePathname } from "next/navigation"; + +export const useNoteURL = (): undefined | string => { + const pathname = usePathname(); + const urlParams = new URLSearchParams(window.location.search); + const segments = pathname.split("/"); + const viewIndex = segments.indexOf("view"); + const password = urlParams.get("password"); + + return { + password, + id: segments[viewIndex + 1] || undefined, + }; +}; diff --git a/examples/share-notes/src/services/notes.ts b/examples/flush-notes/src/services/notes.ts similarity index 92% rename from examples/share-notes/src/services/notes.ts rename to examples/flush-notes/src/services/notes.ts index f9fd074..b8a7846 100644 --- a/examples/share-notes/src/services/notes.ts +++ b/examples/flush-notes/src/services/notes.ts @@ -54,7 +54,10 @@ export class Notes { return note.id; } - public async readNote(id: string): Promise { + public async readNote( + id: string, + password?: string + ): Promise { await this.initMessages(); const message = this.messages @@ -75,14 +78,15 @@ export class Notes { return message?.content; } - const password = window.prompt("This note is encrypted, need password:"); + const passwordReceived = + password || window.prompt("This note is encrypted, need password:"); - if (!password) { + if (!passwordReceived) { console.log("No password was provided, stopping reading a note."); return; } - return this.decryptNote(message, password); + return this.decryptNote(message, passwordReceived); } private async initMessages() { diff --git a/examples/share-notes/src/services/waku.ts b/examples/flush-notes/src/services/waku.ts similarity index 100% rename from examples/share-notes/src/services/waku.ts rename to examples/flush-notes/src/services/waku.ts diff --git a/examples/share-notes/src/utils.ts b/examples/flush-notes/src/utils.ts similarity index 100% rename from examples/share-notes/src/utils.ts rename to examples/flush-notes/src/utils.ts diff --git a/examples/share-notes/tsconfig.json b/examples/flush-notes/tsconfig.json similarity index 100% rename from examples/share-notes/tsconfig.json rename to examples/flush-notes/tsconfig.json diff --git a/examples/share-notes/src/hooks/useNoteHash.ts b/examples/share-notes/src/hooks/useNoteHash.ts deleted file mode 100644 index cbdca40..0000000 --- a/examples/share-notes/src/hooks/useNoteHash.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { usePathname } from "next/navigation"; - -export const useNoteHash = (): undefined | string => { - const pathname = usePathname(); - const segments = pathname.split("/"); - const viewIndex = segments.indexOf("view"); - - return segments[viewIndex + 1] || undefined; -};