32 lines
816 B
TypeScript
32 lines
816 B
TypeScript
|
|
'use client';
|
||
|
|
|
||
|
|
import { useUIStore } from '@/stores/ui-store';
|
||
|
|
import { usePortContext } from '@/providers/port-provider';
|
||
|
|
import type { Port } from '@/lib/db/schema/ports';
|
||
|
|
|
||
|
|
interface UsePortReturn {
|
||
|
|
currentPort: Port | null;
|
||
|
|
currentPortId: string | null;
|
||
|
|
currentPortSlug: string | null;
|
||
|
|
ports: Port[];
|
||
|
|
setPort: (portId: string, portSlug: string) => void;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Hook to get current port context from Zustand store and PortContext.
|
||
|
|
*/
|
||
|
|
export function usePort(): UsePortReturn {
|
||
|
|
const { currentPort, ports } = usePortContext();
|
||
|
|
const currentPortId = useUIStore((s) => s.currentPortId);
|
||
|
|
const currentPortSlug = useUIStore((s) => s.currentPortSlug);
|
||
|
|
const setPort = useUIStore((s) => s.setPort);
|
||
|
|
|
||
|
|
return {
|
||
|
|
currentPort,
|
||
|
|
currentPortId,
|
||
|
|
currentPortSlug,
|
||
|
|
ports,
|
||
|
|
setPort,
|
||
|
|
};
|
||
|
|
}
|