Skip to content

Commit

Permalink
feat: fetch nav menu data
Browse files Browse the repository at this point in the history
  • Loading branch information
TinsFox committed Nov 2, 2024
1 parent 60be317 commit b1be784
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from "@/components/ui/sidebar"

import { menus } from "./layout/sidebar/data"
import { useNavMenu } from "@/hooks/query/user-memu"

const navSecondary = [
{
Expand All @@ -36,6 +35,8 @@ const navSecondary = [
]

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
const { data: menus } = useNavMenu()

return (
<Sidebar variant="inset" {...props}>
<SidebarHeader>
Expand Down
4 changes: 2 additions & 2 deletions src/components/nav-breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from "react"
import { useTranslation } from "react-i18next"
import { Link, useLocation } from "react-router-dom"

import { menus } from "@/components/layout/sidebar/data"
import {
Breadcrumb,
BreadcrumbItem,
Expand All @@ -11,6 +10,7 @@ import {
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { useNavMenu } from "@/hooks/query/user-memu"
import { cn } from "@/lib/utils"
import type { IMenu } from "@/models/menu"

Expand All @@ -23,7 +23,7 @@ interface Breadcrumb {
export function NavBreadcrumb({ className }: { className?: string }) {
const location = useLocation()
const { t } = useTranslation("navigation")

const { data: menus } = useNavMenu()
const findMenuPath = (
pathname: string,
items: IMenu[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { queryOptions, useSuspenseQuery } from "@tanstack/react-query"
import {
Archive,
ArchiveX,
Expand All @@ -23,6 +24,23 @@ import {

import type { IMenu } from "@/models/menu"

export const queryNavMenu = () => queryOptions({
queryKey: ["nav-menu"],
queryFn: async () => mockMenu(),
})

export function useNavMenu() {
return useSuspenseQuery(queryNavMenu())
}

async function mockMenu(): Promise<IMenu[]> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(menus)
}, 1000)
})
}

export const menus: IMenu[] = [
{
title: "dashboard",
Expand Down

0 comments on commit b1be784

Please sign in to comment.