diff --git a/package.json b/package.json index b1816312..7abe8b35 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@uiw/react-codemirror": "4.19.6", "@urql/core": "3.1.1", "axios": "1.2.2", + "canvas-confetti": "^1.6.0", "clsx": "1.2.1", "crossbell.js": "0.16.1", "dayjs": "1.11.7", @@ -110,6 +111,7 @@ "@next/bundle-analyzer": "13.1.2", "@playwright/test": "1.29.2", "@tailwindcss/line-clamp": "^0.4.2", + "@types/canvas-confetti": "^1.6.0", "@types/cookie": "0.5.1", "@types/hast": "2.3.4", "@types/js-yaml": "4.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 077a7734..be349d07 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,6 +33,7 @@ specifiers: '@tanstack/react-query': 4.22.0 '@tanstack/react-query-devtools': 4.22.0 '@tanstack/react-query-persist-client': 4.22.0 + '@types/canvas-confetti': ^1.6.0 '@types/cookie': 0.5.1 '@types/hast': 2.3.4 '@types/js-yaml': 4.0.5 @@ -53,6 +54,7 @@ specifiers: '@urql/core': 3.1.1 autoprefixer: 10.4.13 axios: 1.2.2 + canvas-confetti: ^1.6.0 clsx: 1.2.1 cross-spawn: 7.0.3 crossbell.js: 0.16.1 @@ -151,6 +153,7 @@ dependencies: '@uiw/react-codemirror': 4.19.6_hyb5to5u4twfhgokb4qeeija2e '@urql/core': 3.1.1 axios: 1.2.2 + canvas-confetti: 1.6.0 clsx: 1.2.1 crossbell.js: 0.16.1 dayjs: 1.11.7 @@ -216,6 +219,7 @@ devDependencies: '@next/bundle-analyzer': 13.1.2 '@playwright/test': 1.29.2 '@tailwindcss/line-clamp': 0.4.2_tailwindcss@3.2.4 + '@types/canvas-confetti': 1.6.0 '@types/cookie': 0.5.1 '@types/hast': 2.3.4 '@types/js-yaml': 4.0.5 @@ -2653,6 +2657,10 @@ packages: '@types/node': 18.11.18 dev: false + /@types/canvas-confetti/1.6.0: + resolution: {integrity: sha512-Yq6rIccwcco0TLD5SMUrIM7Fk7Fe/C0jmNRxJJCLtAF6gebDkPuUjK5EHedxecm69Pi/aA+It39Ux4OHmFhjRw==} + dev: true + /@types/chai-subset/1.3.3: resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} dependencies: diff --git a/src/lib/confetti.ts b/src/lib/confetti.ts new file mode 100644 index 00000000..edbba7a9 --- /dev/null +++ b/src/lib/confetti.ts @@ -0,0 +1,35 @@ +import confetti from "canvas-confetti" + +export function showConfetti() { + if (typeof window !== "undefined") { + const end = Date.now() + 100 + const config: confetti.Options = { + particleCount: 25, + startVelocity: 90, + angle: 60, + spread: 60, + origin: { x: 0, y: 1 }, + zIndex: 300, + gravity: 1.5, + colors: ["#6AD991", "#F6C549", "#E65040", "#5B89F7", "#9688F2"], + } + + ;(function frame() { + confetti({ + ...config, + angle: 60, + origin: { x: 0, y: 1 }, + }) + + confetti({ + ...config, + angle: 120, + origin: { x: 1, y: 1 }, + }) + + if (Date.now() < end) { + requestAnimationFrame(frame) + } + })() + } +} diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index aea0a60b..d3cbd22e 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -35,6 +35,9 @@ import type { EditorView } from "@codemirror/view" import { Editor } from "~/components/ui/Editor" import { renderPageContent } from "~/markdown" import { Button } from "~/components/ui/Button" +import { Modal } from "~/components/ui/Modal" +import { CSB_SCAN } from "~/lib/env" +import { showConfetti } from "~/lib/confetti" const getInputDatetimeValue = (date: Date | string) => { const str = dayjs(date).format() @@ -158,16 +161,11 @@ export default function SubdomainEditor() { } } + const [isCheersOpen, setIsCheersOpen] = useState(false) + useEffect(() => { if (createOrUpdatePage.isSuccess) { if (createOrUpdatePage.data?.code === 0) { - if (values.published) { - toast.success("Updated!") - } else { - toast.success( - "Published!\nPlease wait a few seconds for the blockchain indexing to complete.", - ) - } if (draftKey) { delStorage(draftKey) queryClient.invalidateQueries(["getPagesBySite", subdomain]) @@ -184,6 +182,9 @@ export default function SubdomainEditor() { `/dashboard/${subdomain}/editor?id=${site.data?.metadata?.proof}-${createOrUpdatePage.data.data}&type=${router.query.type}`, ) } + + setIsCheersOpen(true) + showConfetti() } else { toast.error("Error: " + createOrUpdatePage.data?.message) } @@ -566,6 +567,63 @@ export default function SubdomainEditor() { )} + +
+ Your post has been permanently stored on the blockchain. Now you may + want to + +
+
+ +
+
) }