Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { useDocumentById } from '@/entities/documents'
import { useChangeLogFileById } from '../../model'
import { useTranslate } from '@/shared/lib'
import { File, Nullable } from '@tmk/ui-kit'
import Skeleton from 'react-loading-skeleton'
import { FCWithClassName } from '@/shared/@types'
import { FileModel } from '@/shared/@types'
export interface ChangeLogDocumentsProps {
//fileId или documentId
id: string
isNeedDocument?: boolean
containerClassName?: string
isFileFromParent?: boolean
fileFromParent?: Nullable<FileModel>
isLoadingFileFromParent?: boolean
}
export const DocumentFile: FCWithClassName<ChangeLogDocumentsProps> = ({
id,
className,
isNeedDocument = true,
isFileFromParent,
fileFromParent,
isLoadingFileFromParent,
}) => {
const { t } = useTranslate(['common'])
const { data: document, isLoading: isLoadingDocument } = useDocumentById(id, {
enabled: !!id && isNeedDocument && !fileFromParent && !isFileFromParent,
key: ['document', id],
})
const fileId = document?.file.id
const { data: file, isLoading: isLoadingFile } = useChangeLogFileById(fileId! || id, {
enabled: !!fileId || (!isNeedDocument && !!id && !fileFromParent && !isFileFromParent),
key: ['file', fileId!, id],
})
if (isLoadingFileFromParent || isLoadingDocument || isLoadingFile) {
return <Skeleton height={40} width={90} count={1} containerClassName='flex gap-4 flex-wrap w-full' />
}
//не очивидный факт, что если файла по ири в базе нет
//то по запросу с массивом бек ошибки не вернет, просто вернет меньше файлов
//поэтому проверяем, что файл грузился, но не загрузился
if (isFileFromParent && fileFromParent) {
return (
<File
file={fileFromParent}
t={t}
isPreviewImage={false}
truncateMaxWidth={170}
truncateClassName='truncate !line-clamp-none !block'
className={className}
/>
)
}
if (file) {
return (
<File
file={file}
t={t}
isPreviewImage={false}
truncateMaxWidth={170}
truncateClassName='truncate !line-clamp-none !block'
className={className}
/>
)
}
return null
}
|