update state sidebar
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import {
|
||||
createCookie,
|
||||
Outlet,
|
||||
type ShouldRevalidateFunctionArgs
|
||||
} from 'react-router'
|
||||
import * as cookie from 'cookie'
|
||||
import { Outlet, type ShouldRevalidateFunctionArgs } from 'react-router'
|
||||
|
||||
import { AppSidebar } from '@/components/app-sidebar'
|
||||
import { request as req } from '@/lib/request'
|
||||
@@ -22,10 +19,11 @@ import {
|
||||
export const middleware: Route.MiddlewareFunction[] = [authMiddleware]
|
||||
|
||||
export async function loader({ params, context, request }: Route.ActionArgs) {
|
||||
const rawCookie = request.headers.get('cookie')
|
||||
const user = context.get(userContext)
|
||||
const rawCookie = request.headers.get('cookie')
|
||||
const parsedCookies = cookie.parse(rawCookie)
|
||||
const { sidebar_state } = parsedCookies
|
||||
|
||||
const sidebarState = await createCookie('sidebar_state').parse(rawCookie)
|
||||
const r = await req({
|
||||
url: `/users/${user.sub}/orgs?limit=25`,
|
||||
request,
|
||||
@@ -44,7 +42,7 @@ export async function loader({ params, context, request }: Route.ActionArgs) {
|
||||
const exists = orgs.some(({ id }) => id === params.orgid)
|
||||
|
||||
if (exists) {
|
||||
return { user, orgs, sidebarState }
|
||||
return { user, orgs, sidebar_state }
|
||||
}
|
||||
|
||||
throw new Response(null, { status: 401 })
|
||||
@@ -58,11 +56,10 @@ export function shouldRevalidate({
|
||||
}
|
||||
|
||||
export default function Route({ loaderData }: Route.ComponentProps) {
|
||||
const { user, orgs, sidebarState } = loaderData
|
||||
console.log(sidebarState)
|
||||
const { user, orgs, sidebar_state } = loaderData
|
||||
|
||||
return (
|
||||
<SidebarProvider defaultOpen={sidebarState === 'true'} className="flex">
|
||||
<SidebarProvider defaultOpen={sidebar_state === 'true'} className="flex">
|
||||
<AppSidebar orgs={orgs} />
|
||||
|
||||
<SidebarInset className="relative flex flex-col flex-1 min-w-0">
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"@repo/auth": "*",
|
||||
"@repo/ui": "*",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"cookie": "^1.0.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"fuse.js": "^7.1.0",
|
||||
"http-status-codes": "^2.3.0",
|
||||
|
||||
1
package-lock.json
generated
1
package-lock.json
generated
@@ -29,6 +29,7 @@
|
||||
"@repo/auth": "*",
|
||||
"@repo/ui": "*",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"cookie": "^1.0.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"fuse.js": "^7.1.0",
|
||||
"http-status-codes": "^2.3.0",
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@rollup/rollup-linux-x64-gnu": "^4.52.5",
|
||||
"lightningcss-linux-x64-gnu": "^1.30.2",
|
||||
"@tailwindcss/oxide-linux-x64-gnu": "^4.1.16"
|
||||
"@tailwindcss/oxide-linux-x64-gnu": "^4.1.16",
|
||||
"lightningcss-linux-x64-gnu": "^1.30.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
||||
Reference in New Issue
Block a user