Spaces:
Sleeping
Sleeping
File size: 1,039 Bytes
3b81d2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
"use client"
import { useEffect, useState } from "react"
import { useSearchParams } from "next/navigation"
import { useStore } from "@/app/store"
import { LayoutName, defaultLayout, nonRandomLayouts } from "@/app/layouts"
import { useIsBusy } from "@/lib/useIsBusy"
import { SelectLayout } from "../select-layout"
export function SelectGlobalLayout() {
const searchParams = useSearchParams()
const requestedLayout = (searchParams?.get('layout') as LayoutName) || defaultLayout
const layout = useStore(s => s.layout)
const setLayout = useStore(s => s.setLayout)
const isBusy = useIsBusy()
const [draftLayout, setDraftLayout] = useState<LayoutName>(requestedLayout)
useEffect(() => {
const layoutChanged = draftLayout !== layout
if (layoutChanged && !isBusy) {
setLayout(draftLayout)
}
}, [layout, draftLayout, isBusy])
return (
<SelectLayout
defaultValue={defaultLayout}
onLayoutChange={setDraftLayout}
disabled={isBusy}
layouts={nonRandomLayouts}
/>
)
} |