From a02bacca10ada969b9e306b1d7f88f606bad33a5 Mon Sep 17 00:00:00 2001 From: Priyanshu Date: Mon, 9 Sep 2024 14:30:49 +0530 Subject: [PATCH] Refactoring && Responsiveness --- app/document/components/Header/Header.tsx | 30 +++- .../Header/components/HeaderButtons.tsx | 54 +------ .../Header/components/ProfileBtn.tsx | 56 +++++++ .../Header/components/SearchBar.tsx | 6 +- app/writer/[id]/components/Header/Header.tsx | 2 + app/writer/[id]/editor/index.ts | 146 ++++++++++++++++-- app/writer/[id]/page.tsx | 138 +---------------- 7 files changed, 229 insertions(+), 203 deletions(-) create mode 100644 app/document/components/Header/components/ProfileBtn.tsx diff --git a/app/document/components/Header/Header.tsx b/app/document/components/Header/Header.tsx index 679d44e..95027c9 100644 --- a/app/document/components/Header/Header.tsx +++ b/app/document/components/Header/Header.tsx @@ -6,6 +6,7 @@ import logo from "@/public/logo.svg"; import SearchBar from "./components/SearchBar"; import HeaderButtons from "./components/HeaderButtons"; +import ProfileBtn from "./components/ProfileBtn"; const roboto = Montserrat({ weight: "500", @@ -16,14 +17,27 @@ const roboto = Montserrat({ type HeaderPropType = Pick; export default function Header({ image, name }: HeaderPropType) { return ( -
-
- logo -

DocX

- {/* logo */} + <> +
+
+ logo +

DocX

+
+ +
+ + +
- - -
+ +
+
+ logo +
+ + + +
+ ); } diff --git a/app/document/components/Header/components/HeaderButtons.tsx b/app/document/components/Header/components/HeaderButtons.tsx index 274a60a..8312853 100644 --- a/app/document/components/Header/components/HeaderButtons.tsx +++ b/app/document/components/Header/components/HeaderButtons.tsx @@ -3,19 +3,13 @@ import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; -import { CloudUpload, LogOut, PlusIcon } from "lucide-react"; +import { CloudUpload, PlusIcon } from "lucide-react"; -import { Avatar, AvatarImage } from "@/components/ui/avatar"; -import { CreateNewDocument, LogoutAction } from "../actions"; +import { CreateNewDocument } from "../actions"; import { Button } from "@/components/ui/button"; -import { SessionReturnType } from "@/lib/customHooks/ReturnType"; import LoaderButton from "@/components/LoaderButton"; -import getInitials from "@/helpers/getInitials"; -import { Popover } from "@/components/ui/popover"; -import { PopoverContent, PopoverTrigger } from "@radix-ui/react-popover"; -type HeaderBtnPropType = Pick; -export default function HeaderButtons({ image, name }: HeaderBtnPropType) { +export default function HeaderButtons() { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); @@ -34,22 +28,12 @@ export default function HeaderButtons({ image, name }: HeaderBtnPropType) { } }; - const logout = async () => { - const response = await LogoutAction(); - if (response.success) { - toast.success("Successfully logged out"); - router.push("/api/auth/signin"); - } else { - toast.error(response.error); - } - }; return ( -
-
+
{process.env.NODE_ENV === "development" ?
- - -
-

{getInitials(name ?? "X")}

-
- {image ? ( - - - - ) : (<>)} -
- - - -
-
); } diff --git a/app/document/components/Header/components/ProfileBtn.tsx b/app/document/components/Header/components/ProfileBtn.tsx new file mode 100644 index 0000000..4e10ae6 --- /dev/null +++ b/app/document/components/Header/components/ProfileBtn.tsx @@ -0,0 +1,56 @@ +"use client" + +import { useRouter } from "next/navigation"; +import { toast } from "sonner"; +import { LogOut } from "lucide-react"; +import { PopoverContent, PopoverTrigger } from "@radix-ui/react-popover"; + +import { Avatar, AvatarImage } from "@/components/ui/avatar"; +import { Popover } from "@/components/ui/popover"; +import { Button } from "@/components/ui/button"; +import { SessionReturnType } from "@/lib/customHooks/ReturnType"; +import getInitials from "@/helpers/getInitials"; + +import { LogoutAction } from "../actions"; + +type ProfileBtnPropType = Pick +export default function ProfileBtn({ name, image }: ProfileBtnPropType) { + const router = useRouter(); + + const logout = async () => { + const response = await LogoutAction(); + if (response.success) { + toast.success("Successfully logged out"); + router.push("/api/auth/signin"); + } else { + toast.error(response.error); + } + }; + return ( + + +
+

{getInitials(name ?? "X")}

+
+ {image ? ( + + + + ) : (<>)} +
+ + + +
+ ) +} diff --git a/app/document/components/Header/components/SearchBar.tsx b/app/document/components/Header/components/SearchBar.tsx index 04054c6..18b3938 100644 --- a/app/document/components/Header/components/SearchBar.tsx +++ b/app/document/components/Header/components/SearchBar.tsx @@ -62,7 +62,7 @@ export default function SearchBar() { return (