-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from huilensolis/227-feat-add-entry-list-to-s…
…idebar 227 feat add entry list to sidebar
- Loading branch information
Showing
13 changed files
with
211 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function cleanCache( | ||
path: string, | ||
type: "layout" | "page" = "page", | ||
) { | ||
console.log("cleaning cache of ", path); | ||
revalidatePath(path, type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 13 additions & 79 deletions
92
apps/client/src/components/feature/aside-nav/aside-nav.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/client/src/components/feature/aside-nav/components/entry-list/entry-item.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
|
||
import { ClientRoutingService } from "@/models/routing/client"; | ||
import type { Entry } from "@/types/entry"; | ||
import Link from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export function EntryItem({ entry }: { entry: Entry }) { | ||
const [isActive, setIsActive] = useState<boolean>(false); | ||
|
||
const pathName = usePathname(); | ||
|
||
useEffect(() => { | ||
if (pathName === ClientRoutingService.app.entries.readById(entry.id)) { | ||
setIsActive(true); | ||
return; | ||
} | ||
|
||
setIsActive(false); | ||
}, [pathName, entry.id]); | ||
|
||
return ( | ||
<Link href={ClientRoutingService.app.entries.readById(entry.id)}> | ||
<article | ||
className={`flex flex-col p-2 hover:bg-zinc-200 ${isActive ? "bg-zinc-200" : ""} rounded-sm transition-all duration-150`} | ||
> | ||
<span className="font-semibold">{entry.title}</span> | ||
<span className="text-sm"> | ||
{new Date(entry.updated_at).toLocaleString()} | ||
</span> | ||
</article> | ||
</Link> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
apps/client/src/components/feature/aside-nav/components/entry-list/entry-list.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { EntryService } from "@/models/api/entry"; | ||
import { EntryItem } from "./entry-item.component"; | ||
import { getCookie } from "@/utils/getCookies"; | ||
|
||
export async function EntryList() { | ||
const { cookie } = getCookie(); | ||
|
||
if (!cookie) return <p>something went wrong</p>; | ||
|
||
const { entryList, error } = await EntryService.getUserEntyList({ cookie }); | ||
console.log(entryList); | ||
|
||
return ( | ||
<ul className="w-full flex flex-col gap-2"> | ||
{!error && | ||
entryList && | ||
entryList.length > 0 && | ||
entryList | ||
.sort((entry, nextEntry) => | ||
new Date(entry.updated_at).getTime() > | ||
new Date(nextEntry.updated_at).getTime() | ||
? -1 | ||
: 1, | ||
) | ||
.map((entry) => ( | ||
<li key={entry.id}> | ||
<EntryItem entry={entry} /> | ||
</li> | ||
))} | ||
{error && <p>something went wrong</p>} | ||
</ul> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
apps/client/src/components/feature/aside-nav/components/entry-list/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./entry-list.component"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/client/src/components/feature/aside-nav/views/desktop/desktop.view.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Hr } from "@/components/ui/hr"; | ||
import { type ReactNode } from "react"; | ||
import { EntryList } from "../../components/entry-list"; | ||
|
||
export function DesktopAsideView({ children }: { children: ReactNode }) { | ||
return ( | ||
<> | ||
<aside className="max-w-80 w-full h-full min-h-screen p-2 flex gap-2 flex-col items-center border-r border-neutral-300"> | ||
{children} | ||
<Hr orientation="horizontal" className="my-1" /> | ||
<EntryList /> | ||
</aside> | ||
</> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
apps/client/src/components/feature/aside-nav/views/desktop/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./desktop.view.component"; |
1 change: 1 addition & 0 deletions
1
apps/client/src/components/feature/aside-nav/views/mobile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./mobile.view.component"; |
82 changes: 82 additions & 0 deletions
82
apps/client/src/components/feature/aside-nav/views/mobile/mobile.view.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"use client"; | ||
|
||
import { Menu, X } from "lucide-react"; | ||
import { | ||
Drawer, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerFooter, | ||
DrawerHeader, | ||
DrawerTrigger, | ||
} from "../../../drawer"; | ||
import { Button } from "@/components/ui/button"; | ||
import { useAsideNavStore } from "../../store"; | ||
import { type ReactNode, useEffect, useState } from "react"; | ||
|
||
export function MobileAsideView({ children }: { children: ReactNode }) { | ||
const [isDrawerOpen, setIsDrawerOpen] = useState<boolean>(false); | ||
|
||
const canDrawerOpen = useAsideNavStore((state) => state.canDrawerOpen); | ||
const closeDrawer = useAsideNavStore((state) => state.closeDrawer); | ||
const openDrawer = useAsideNavStore((state) => state.openDrawer); | ||
|
||
function handleDrawerOpenChange(open: boolean) { | ||
setIsDrawerOpen(open); | ||
} | ||
|
||
function handleFocusOnDrawerBackground() { | ||
closeDrawer(); | ||
|
||
setTimeout(() => { | ||
openDrawer(); | ||
}, 500); | ||
} | ||
|
||
useEffect(() => { | ||
if (!isDrawerOpen) return; | ||
|
||
document.getElementsByTagName("body")[0].style.overflowY = "hidden"; | ||
|
||
return () => { | ||
document.getElementsByTagName("body")[0].style.overflowY = "auto"; | ||
}; | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isDrawerOpen]); | ||
|
||
return ( | ||
<> | ||
{isDrawerOpen && ( | ||
<div | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
|
||
handleFocusOnDrawerBackground(); | ||
}} | ||
className="h-screen w-full bg-black/40 absolute top-0 left-0 z-40" | ||
></div> | ||
)} | ||
<Drawer | ||
open={canDrawerOpen ? undefined : false} | ||
modal={false} | ||
onOpenChange={handleDrawerOpenChange} | ||
> | ||
<DrawerTrigger asChild> | ||
<Button variant="ghost" className="hover:bg-zinc-200 px-1.5"> | ||
<Menu className="h-8 w-8" /> | ||
</Button> | ||
</DrawerTrigger> | ||
<DrawerContent hidden={!canDrawerOpen}> | ||
<DrawerHeader className="flex items-center justify-start"> | ||
<DrawerClose asChild> | ||
<Button variant="ghost" className="px-1.5"> | ||
<X className="h-8 w-8" /> | ||
</Button> | ||
</DrawerClose> | ||
</DrawerHeader> | ||
<DrawerFooter>{children}</DrawerFooter> | ||
</DrawerContent> | ||
</Drawer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters