18 lines
629 B
TypeScript
18 lines
629 B
TypeScript
|
|
import useSWR from "swr"
|
|||
|
|
import type { SWRConfiguration } from "swr"
|
|||
|
|
|
|||
|
|
import { backendApi } from "../client"
|
|||
|
|
import type { AssetResponseDto } from "../generated/backend-api.generated"
|
|||
|
|
|
|||
|
|
export const getAssetKey = (publicId: string) => ["backend-api", "assets", "detail", publicId] as const
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Получение asset по publicId.
|
|||
|
|
*/
|
|||
|
|
export const useGetAsset = (publicId: string | null, config?: SWRConfiguration) => {
|
|||
|
|
const key = publicId !== null ? getAssetKey(publicId) : null
|
|||
|
|
const fetcher = () => backendApi.assets.getAsset({ publicId: publicId ?? "" })
|
|||
|
|
|
|||
|
|
return useSWR<AssetResponseDto>(key, fetcher, config)
|
|||
|
|
}
|