import { createAsset as createAssetRedux , getAssets , useDispatch , useSelector } from '@store' ; import { ExtendedAsset , TUuid } from '@types' ; import { getAssetByUUID as getAssetByUUIDFunc } from './helpers' ; export interface IAssetContext { assets : ExtendedAsset [ ] ; createAsset ( assetData , id ) : void ; getAssetByUUID ( uuid ) : ExtendedAsset | undefined ; addAssetsFromAPI ( newAssets ) : void ; } function useAssets ( ) { const assets = useSelector ( getAssets ) ; const dispatch = useDispatch ( ) ; const createAsset = ( asset ) => dispatch ( createAssetRedux ( asset ) ) ; const getAssetByUUID = ( uuid ) => getAssetByUUIDFunc ( assets ) ( uuid ) ; return { assets , createAsset , getAssetByUUID } ; } export default useAssets ;