mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 18:53:06 +00:00
- Reorder drawer so handle sits at the screen bottom (snap shows bottom band) - Hide dock content when collapsed instead of clipping through search - Attach scroll-collapse listener directly on campaign-content-scroll ref
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { usePathname } from 'next/navigation'
|
|
import {
|
|
createContext,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
type Dispatch,
|
|
type ReactNode,
|
|
type SetStateAction,
|
|
} from 'react'
|
|
|
|
import {
|
|
QUICK_ACTIONS_SNAP_DOCK,
|
|
quickActionsSnapIsDock,
|
|
type QuickActionsSnapPoint,
|
|
} from '@/lib/campaignQuickActionSnap'
|
|
|
|
type CampaignQuickActionsSnapContextValue = {
|
|
snapPoint: QuickActionsSnapPoint | null
|
|
setSnapPoint: Dispatch<SetStateAction<QuickActionsSnapPoint | null>>
|
|
isDock: boolean
|
|
}
|
|
|
|
const CampaignQuickActionsSnapContext = createContext<CampaignQuickActionsSnapContextValue | null>(
|
|
null,
|
|
)
|
|
|
|
export const CampaignQuickActionsSnapProvider = ({ children }: { children: ReactNode }) => {
|
|
const pathname = usePathname()
|
|
const [snapPoint, setSnapPoint] = useState<QuickActionsSnapPoint | null>(QUICK_ACTIONS_SNAP_DOCK)
|
|
|
|
useEffect(() => {
|
|
setSnapPoint(QUICK_ACTIONS_SNAP_DOCK)
|
|
}, [pathname])
|
|
|
|
const value = useMemo(
|
|
(): CampaignQuickActionsSnapContextValue => ({
|
|
snapPoint,
|
|
setSnapPoint,
|
|
isDock: quickActionsSnapIsDock(snapPoint),
|
|
}),
|
|
[snapPoint],
|
|
)
|
|
|
|
return (
|
|
<CampaignQuickActionsSnapContext.Provider value={value}>
|
|
{children}
|
|
</CampaignQuickActionsSnapContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useCampaignQuickActionsSnap = (): CampaignQuickActionsSnapContextValue => {
|
|
const value = useContext(CampaignQuickActionsSnapContext)
|
|
if (!value) {
|
|
throw new Error('CampaignQuickActionsSnapProvider is required')
|
|
}
|
|
return value
|
|
}
|