file-view.ts 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { FileRef } from '../../../../../types/file-ref'
  2. import { BinaryFile } from '@/features/file-view/types/binary-file'
  3. export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
  4. return {
  5. _id: fileRef._id,
  6. name: fileRef.name,
  7. id: fileRef._id,
  8. type: 'file',
  9. selected: true,
  10. linkedFileData: fileRef.linkedFileData,
  11. created: fileRef.created ? new Date(fileRef.created) : new Date(),
  12. }
  13. }
  14. // `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
  15. // `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
  16. // into which `FileViewHeader` passes its BinaryFile, expects a file object with
  17. // `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
  18. // is the only one making runtime complaints and it seems that other uses of
  19. // `FileViewHeader` pass in a string for `created`, so that's what this function
  20. // does too.
  21. export function fileViewFile(fileRef: FileRef) {
  22. return {
  23. ...convertFileRefToBinaryFile(fileRef),
  24. created: fileRef.created,
  25. }
  26. }