import {reactive, watch} from "@peryl/react-compose"; import {iOvMeta} from "../$ov/ov.utils"; import $configuration from "../$configuration"; import {iOvPropsType} from "./ov.utils"; export function usePublicOv({ props }: { props: iOvPropsType }) { const service = props.service || $configuration.use('ov')!; const state = reactive({ type: null as null | undefined | string, ovMetas: [] as iOvMeta[], loading: false, }); watch(() => props.ov, async type => { if (state.type == type) { return; } state.type = type; if (!type) { if (!!state.ovMetas.length) { state.ovMetas = []; } } else { state.loading = true; try { state.ovMetas = await service.getOvByTypes(type); } finally { state.loading = false; } } }, { immediate: true }); return { service, state }; }