From ace0d6eeccc65c96275a24c8a96e63988cf76134 Mon Sep 17 00:00:00 2001 From: MAZE Date: Sun, 1 Sep 2024 13:07:19 +0430 Subject: [PATCH] feat: add confetti --- package-lock.json | 6 ++++++ package.json | 1 + src/lib/confetti.ts | 18 ++++++++++++++++++ src/stores/todo.ts | 6 ++++++ 4 files changed, 31 insertions(+) create mode 100644 src/lib/confetti.ts diff --git a/package-lock.json b/package-lock.json index 1ef4a10..c5c82c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "focus-trap-react": "10.2.3", "framer-motion": "10.16.4", "howler": "2.2.4", + "js-confetti": "0.12.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hotkeys-hook": "3.2.1", @@ -18316,6 +18317,11 @@ "node": ">=8" } }, + "node_modules/js-confetti": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/js-confetti/-/js-confetti-0.12.0.tgz", + "integrity": "sha512-1R0Akxn3Zn82pMqW65N1V2NwKkZJ75bvBN/VAb36Ya0YHwbaSiAJZVRr/19HBxH/O8x2x01UFAbYI18VqlDN6g==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index e06dfcf..38b46f6 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "focus-trap-react": "10.2.3", "framer-motion": "10.16.4", "howler": "2.2.4", + "js-confetti": "0.12.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hotkeys-hook": "3.2.1", diff --git a/src/lib/confetti.ts b/src/lib/confetti.ts new file mode 100644 index 0000000..f462c23 --- /dev/null +++ b/src/lib/confetti.ts @@ -0,0 +1,18 @@ +import JSConfetti from 'js-confetti'; + +export const addConfetti = () => { + const jsConfetti = new JSConfetti(); + + jsConfetti.addConfetti({ + confettiColors: [ + '#6366f1', + '#8b5cf6', + '#a855f7', + '#ec4899', + '#f43f5e', + '#fb923c', + '#eab308', + '#22c55e', + ], + }); +}; diff --git a/src/stores/todo.ts b/src/stores/todo.ts index 397fb20..ed98537 100644 --- a/src/stores/todo.ts +++ b/src/stores/todo.ts @@ -3,6 +3,8 @@ import { createJSONStorage, persist } from 'zustand/middleware'; import merge from 'deepmerge'; import { v4 as uuid } from 'uuid'; +import { addConfetti } from '@/lib/confetti'; + interface TodoStore { addTodo: (todo: string) => void; deleteTodo: (id: string) => void; @@ -71,6 +73,10 @@ export const useTodoStore = create()( }; }), }); + + if (get().doneCount() === get().todos.length) { + addConfetti(); + } }, }), {