mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 23:53:05 +00:00
- Add QUICK_ACTIONS_SNAP_FULL; drawer expands on search focus and hides action strip - Tighten dock bottom gap; restore dock/collapsed on blur per scroll position (B100) - Widen CampaignHomeActionButton to w-[5.5rem] for two-line labels - Client-side filter excludes current page entity from drawer search hits - Unit + e2e coverage for full snap, exclusion, and label readability
64 lines
1.6 KiB
TypeScript
64 lines
1.6 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,
|
|
quickActionsSnapIsFull,
|
|
type QuickActionsSnapPoint,
|
|
} from '@/lib/campaignQuickActionSnap'
|
|
|
|
type CampaignQuickActionsSnapContextValue = {
|
|
snapPoint: QuickActionsSnapPoint | null
|
|
setSnapPoint: Dispatch<SetStateAction<QuickActionsSnapPoint | null>>
|
|
isDock: boolean
|
|
isFull: 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),
|
|
isFull: quickActionsSnapIsFull(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
|
|
}
|