Skip to content

Commit

Permalink
[UPDATE: frontend] unsave items from collections and logout
Browse files Browse the repository at this point in the history
  • Loading branch information
monoald committed May 21, 2024
1 parent f0a3960 commit a9d0c58
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
20 changes: 20 additions & 0 deletions packages/frontend/app/(core)/me/colors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 (
<div className="w-full min-h-[calc(100vh-80px)] bg-main text-secondary">
<main className="w-full max-w-5xl p-9 mx-auto flex flex-col gap-20">
Expand Down Expand Up @@ -47,6 +66,7 @@ export default function Page() {

<div className="w-fit h-fit px-5 py-2 mx-auto border border-primary-border rounded-full flex items-center gap-7 text-2xl">
<button
onClick={() => unsaveColor(clr)}
className="secondary-hover flex"
tooltip="true"
tooltip-content="Unsave"
Expand Down
23 changes: 23 additions & 0 deletions packages/frontend/app/(core)/me/gradients/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { MotionDiv } from "@/app/components/FramerMotion";
import { useUserStore } from "@/store";
import Link from "next/link";
import { handleUnsaveGradient } from "../../handlers";
import { GradientCollection } from "../action";

const variants = {
hidden: { opacity: 0 },
Expand All @@ -11,6 +13,23 @@ const variants = {

export default function Page() {
const gradients = useUserStore((state) => state.collections?.gradients);
const token = useUserStore((state) => state.token);
const updateGradients = useUserStore((state) => state.updateGradients);

const unsaveGradient = async (gradient: GradientCollection) => {
await handleUnsaveGradient(
token!,
gradient,
updateGradients,
() => {
dispatch("custom:unsaveGradient", { name: gradient.name });
},
() => {
dispatch("custom:saveGradient", { name: gradient.name });
}
);
};

return (
<div className="w-full min-h-[calc(100vh-80px)] bg-main text-secondary">
<main className="w-full max-w-5xl p-9 mx-auto flex flex-col gap-20">
Expand Down Expand Up @@ -39,6 +58,7 @@ export default function Page() {

<div className="w-fit h-fit px-5 py-2 mx-auto border border-primary-border rounded-full flex items-center gap-7 text-2xl">
<button
onClick={() => unsaveGradient(grad)}
className="secondary-hover flex"
tooltip="true"
tooltip-content="Unsave"
Expand Down Expand Up @@ -125,3 +145,6 @@ export default function Page() {
</div>
);
}
function dispatch(arg0: string, arg1: { name: any }) {
throw new Error("Function not implemented.");
}
20 changes: 20 additions & 0 deletions packages/frontend/app/(core)/me/palettes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 (
<div className="w-full min-h-[calc(100vh-80px)] bg-main text-secondary">
<main className="w-full max-w-5xl p-9 mx-auto flex flex-col gap-20">
Expand Down Expand Up @@ -62,6 +81,7 @@ export default function Page() {

<div className="w-fit h-fit px-5 py-2 mx-auto border border-primary-border rounded-full flex items-center gap-7 text-2xl">
<button
onClick={() => unsavePalette(palette)}
className="secondary-hover flex"
tooltip="true"
tooltip-content="Unsave"
Expand Down
8 changes: 6 additions & 2 deletions packages/frontend/app/components/header/UserArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useLayoutEffect } from "react";
import { usePathname } from "next/navigation";

type Props = {
handleToggleLogIn: () => void;
Expand All @@ -12,6 +13,7 @@ export default function UserArea({ handleToggleLogIn }: Props) {
const router = useRouter();
const user = useUserStore((state) => state.user);
const updateUser = useUserStore((state) => state.updateUser);
const pathname = usePathname();

useLayoutEffect(() => {
updateUser(
Expand All @@ -25,7 +27,9 @@ export default function UserArea({ handleToggleLogIn }: Props) {
localStorage.removeItem("user");
localStorage.removeItem("token");

router.push("/login");
if (pathname.includes("/me")) {
router.push("/");
}
};

return (
Expand Down Expand Up @@ -75,7 +79,7 @@ export default function UserArea({ handleToggleLogIn }: Props) {
<Link href="/me/font-icons">My Font Icons</Link>
</li>
<li className="primary-hover">
<button onClick={handleLogOut}>Sign out</button>
<button onClick={handleLogOut}>Log out</button>
</li>
</ul>
</div>
Expand Down

0 comments on commit a9d0c58

Please sign in to comment.