From a9d0c58008d488387b40609ba184d00f17f3dac5 Mon Sep 17 00:00:00 2001 From: Carlos S Aldazosa Date: Tue, 21 May 2024 09:40:56 -0400 Subject: [PATCH] [UPDATE: frontend] unsave items from collections and logout --- packages/frontend/.gitignore | 1 + .../frontend/app/(core)/me/colors/page.tsx | 20 ++++++++++++++++ .../frontend/app/(core)/me/gradients/page.tsx | 23 +++++++++++++++++++ .../frontend/app/(core)/me/palettes/page.tsx | 20 ++++++++++++++++ .../app/components/header/UserArea.tsx | 8 +++++-- 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 packages/frontend/.gitignore diff --git a/packages/frontend/.gitignore b/packages/frontend/.gitignore new file mode 100644 index 0000000..e985853 --- /dev/null +++ b/packages/frontend/.gitignore @@ -0,0 +1 @@ +.vercel diff --git a/packages/frontend/app/(core)/me/colors/page.tsx b/packages/frontend/app/(core)/me/colors/page.tsx index dd561c7..bdcbc3f 100644 --- a/packages/frontend/app/(core)/me/colors/page.tsx +++ b/packages/frontend/app/(core)/me/colors/page.tsx @@ -5,6 +5,9 @@ import { getMainContrastColor } from "@/app/utils/createBaseColorObject"; import { useUserStore } from "@/store"; import { hexToRgb } from "colors-kit"; import Link from "next/link"; +import { BasicCollection } from "../action"; +import { dispatch } from "../../hooks/useStateHandler"; +import { handleUnsaveColor } from "../../handlers"; const variants = { hidden: { opacity: 0 }, @@ -13,6 +16,22 @@ const variants = { export default function Page() { const colors = useUserStore((state) => state.collections?.colors); + const token = useUserStore((state) => state.token); + const updateColors = useUserStore((state) => state.updateColors); + + const unsaveColor = async (color: BasicCollection) => { + await handleUnsaveColor( + token!, + color, + updateColors, + () => { + dispatch("custom:unsaveColor", { name: color.name }); + }, + () => { + dispatch("custom:saveColor", { name: color.name }); + } + ); + }; return (
@@ -47,6 +66,7 @@ export default function Page() {
); } +function dispatch(arg0: string, arg1: { name: any }) { + throw new Error("Function not implemented."); +} diff --git a/packages/frontend/app/(core)/me/palettes/page.tsx b/packages/frontend/app/(core)/me/palettes/page.tsx index f8369a6..2f2d655 100644 --- a/packages/frontend/app/(core)/me/palettes/page.tsx +++ b/packages/frontend/app/(core)/me/palettes/page.tsx @@ -5,6 +5,9 @@ import { getMainContrastColor } from "@/app/utils/createBaseColorObject"; import { useUserStore } from "@/store"; import { hexToRgb } from "colors-kit"; import Link from "next/link"; +import { handleUnsavePalette } from "../../handlers"; +import { PaletteCollection } from "../action"; +import { dispatch } from "../../hooks/useStateHandler"; const variants = { hidden: { opacity: 0 }, @@ -13,6 +16,22 @@ const variants = { export default function Page() { const palettes = useUserStore((state) => state.collections?.palettes); + const token = useUserStore((state) => state.token); + const updatePalettes = useUserStore((state) => state.updatePalettes); + + const unsavePalette = async (palette: PaletteCollection) => { + await handleUnsavePalette( + token!, + palette, + updatePalettes, + () => { + dispatch("custom:unsavePalette", { colors: palette.name }); + }, + () => { + dispatch("custom:savePalette", { colors: palette.name }); + } + ); + }; return (
@@ -62,6 +81,7 @@ export default function Page() {
+