From fc6d28d1661527b5596604a9aa86400c01a00dc8 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sat, 24 Dec 2022 21:54:53 +0530 Subject: [PATCH] refactor(dev-only): show file local backup status in table --- .../FilesTableView/FilesTableView.tsx | 61 +++++++++++++------ .../Components/Icon/IconNameToSvgMapping.tsx | 1 + 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/packages/web/src/javascripts/Components/FilesTableView/FilesTableView.tsx b/packages/web/src/javascripts/Components/FilesTableView/FilesTableView.tsx index 67ca13727..e33cda5e3 100644 --- a/packages/web/src/javascripts/Components/FilesTableView/FilesTableView.tsx +++ b/packages/web/src/javascripts/Components/FilesTableView/FilesTableView.tsx @@ -4,7 +4,15 @@ import { FilesController } from '@/Controllers/FilesController' import { formatDateForContextMenu } from '@/Utils/DateUtils' import { getIconForFileType } from '@/Utils/Items/Icons/getIconForFileType' import { formatSizeToReadableString } from '@standardnotes/filepicker' -import { ContentType, FileItem, SortableItem, PrefKey, ApplicationEvent, naturalSort } from '@standardnotes/snjs' +import { + ContentType, + FileItem, + SortableItem, + PrefKey, + ApplicationEvent, + naturalSort, + FileBackupRecord, +} from '@standardnotes/snjs' import { useState, useEffect, useCallback, useMemo, useRef } from 'react' import { FileItemActionType } from '../AttachedFilesPopover/PopoverFileItemAction' import { getFileIconComponent } from '../FilePreview/getFileIconComponent' @@ -21,6 +29,7 @@ import LinkedItemsPanel from '../LinkedItems/LinkedItemsPanel' import { LinkingController } from '@/Controllers/LinkingController' import { FeaturesController } from '@/Controllers/FeaturesController' import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' +import { useApplication } from '../ApplicationProvider' const ContextMenuCell = ({ files, filesController }: { files: FileItem[]; filesController: FilesController }) => { const [contextMenuVisible, setContextMenuVisible] = useState(false) @@ -114,6 +123,37 @@ const FileLinksCell = ({ ) } +const FileNameCell = ({ file }: { file: FileItem }) => { + const application = useApplication() + const [backupInfo, setBackupInfo] = useState(undefined) + + useEffect(() => { + void application.fileBackups?.getFileBackupInfo(file).then(setBackupInfo) + }, [application, file]) + + return ( +
+ + {getFileIconComponent(getIconForFileType(file.mimeType), 'w-6 h-6 flex-shrink-0')} + {backupInfo && ( +
+ +
+ )} +
+ {file.title} + {file.protected && ( + + + + )} +
+ ) +} + type Props = { application: WebApplication filesController: FilesController @@ -162,24 +202,7 @@ const FilesTableView = ({ application, filesController, featuresController, link { name: 'Name', sortBy: 'title', - cell: (file) => { - return ( -
- {getFileIconComponent(getIconForFileType(file.mimeType), 'w-6 h-6 flex-shrink-0')} - {file.title} - {file.protected && ( - - - - )} -
- ) - }, + cell: (file) => , }, { name: 'Upload date', diff --git a/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx b/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx index 902ea18ec..34ff490d4 100644 --- a/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx +++ b/packages/web/src/javascripts/Components/Icon/IconNameToSvgMapping.tsx @@ -11,6 +11,7 @@ export const IconNameToSvgMapping = { 'attachment-file': icons.AttachmentFileIcon, 'check-bold': icons.CheckBoldIcon, 'check-circle': icons.CheckCircleIcon, + 'check-circle-filled': icons.CheckCircleFilledIcon, 'chevron-down': icons.ChevronDownIcon, 'chevron-left': icons.ChevronLeftIcon, 'chevron-right': icons.ChevronRightIcon,