From a9445dfcca8d7770cea5272bb26a8fe30405b4ce Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sat, 24 Dec 2022 21:56:38 +0530 Subject: [PATCH] refactor(dev-only): file list item style --- .../ContentListView/ContentList.tsx | 7 +- .../ContentListView/ContentListItem.tsx | 13 +- .../ContentListView/FileListItem.tsx | 62 +++------ .../ContentListView/FileListItemCard.tsx | 131 ++++++++++++++++++ .../ContentListView/ListItemFlagIcons.tsx | 14 +- 5 files changed, 181 insertions(+), 46 deletions(-) create mode 100644 packages/web/src/javascripts/Components/ContentListView/FileListItemCard.tsx diff --git a/packages/web/src/javascripts/Components/ContentListView/ContentList.tsx b/packages/web/src/javascripts/Components/ContentListView/ContentList.tsx index 323d8606e..1b0773242 100644 --- a/packages/web/src/javascripts/Components/ContentListView/ContentList.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/ContentList.tsx @@ -13,6 +13,7 @@ import { NotesController } from '@/Controllers/NotesController/NotesController' import { ElementIds } from '@/Constants/ElementIDs' import { classNames } from '@standardnotes/utils' import { ContentType, SNTag } from '@standardnotes/snjs' +import { featureTrunkEnabled, FeatureTrunkName } from '@/FeatureTrunk' type Props = { application: WebApplication @@ -97,6 +98,8 @@ const ContentList: FunctionComponent = ({ const hasNotes = items.some((item) => item.content_type === ContentType.Note) + const isFilesTableViewEnabled = featureTrunkEnabled(FeatureTrunkName.FilesTableView) + return (
= ({ onSelect={selectItem} tags={getTagsForItem(item)} notesController={notesController} - isPreviousItemTiled={previousItem?.content_type === ContentType.File} - isNextItemTiled={nextItem?.content_type === ContentType.File} + isPreviousItemTiled={previousItem?.content_type === ContentType.File && !isFilesTableViewEnabled} + isNextItemTiled={nextItem?.content_type === ContentType.File && !isFilesTableViewEnabled} /> ) })} diff --git a/packages/web/src/javascripts/Components/ContentListView/ContentListItem.tsx b/packages/web/src/javascripts/Components/ContentListView/ContentListItem.tsx index 4221f67df..93ba67396 100644 --- a/packages/web/src/javascripts/Components/ContentListView/ContentListItem.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/ContentListItem.tsx @@ -1,16 +1,25 @@ +import { featureTrunkEnabled, FeatureTrunkName } from '@/FeatureTrunk' import { ContentType, FileItem, SNNote } from '@standardnotes/snjs' import React, { FunctionComponent } from 'react' import FileListItem from './FileListItem' +import FileListItemCard from './FileListItemCard' import NoteListItem from './NoteListItem' import { AbstractListItemProps, doListItemPropsMeritRerender } from './Types/AbstractListItemProps' import { ListableContentItem } from './Types/ListableContentItem' const ContentListItem: FunctionComponent> = (props) => { + const isFilesTableViewEnabled = featureTrunkEnabled(FeatureTrunkName.FilesTableView) + switch (props.item.content_type) { case ContentType.Note: return - case ContentType.File: - return + case ContentType.File: { + if (isFilesTableViewEnabled) { + return + } + + return + } default: return null } diff --git a/packages/web/src/javascripts/Components/ContentListView/FileListItem.tsx b/packages/web/src/javascripts/Components/ContentListView/FileListItem.tsx index 1b25b33ec..f02993e75 100644 --- a/packages/web/src/javascripts/Components/ContentListView/FileListItem.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/FileListItem.tsx @@ -9,13 +9,12 @@ import { DisplayableListItemProps } from './Types/DisplayableListItemProps' import { useResponsiveAppPane } from '../Panes/ResponsivePaneProvider' import { useContextMenuEvent } from '@/Hooks/useContextMenuEvent' import { classNames } from '@standardnotes/utils' -import { formatSizeToReadableString } from '@standardnotes/filepicker' import { getIconForFileType } from '@/Utils/Items/Icons/getIconForFileType' import { useApplication } from '../ApplicationProvider' -import Icon from '../Icon/Icon' import { PaneLayout } from '@/Controllers/PaneController/PaneLayout' +import ListItemFlagIcons from './ListItemFlagIcons' -const FileListItem: FunctionComponent> = ({ +const FileListItemCard: FunctionComponent> = ({ filesController, hideDate, hideIcon, @@ -75,57 +74,38 @@ const FileListItem: FunctionComponent> = ({ }, [file, onSelect, setPaneLayout]) const IconComponent = () => - getFileIconComponent(getIconForFileType((file as FileItem).mimeType), 'w-10 h-10 flex-shrink-0') + getFileIconComponent(getIconForFileType((file as FileItem).mimeType), 'w-5 h-5 flex-shrink-0') useContextMenuEvent(listItemRef, openContextMenu) return (
-
-
- {!hideIcon ? ( -
- -
- ) : ( -
- )} -
-
-
{file.title}
-
- - - -
+ {!hideIcon ? ( +
+
-
-
- {formatSizeToReadableString(file.decryptedSize)} - {backupInfo && ( -
- -
- )} -
+ ) : ( +
+ )} +
+
+
{file.title}
+ + +
+
) } -export default observer(FileListItem) +export default observer(FileListItemCard) diff --git a/packages/web/src/javascripts/Components/ContentListView/FileListItemCard.tsx b/packages/web/src/javascripts/Components/ContentListView/FileListItemCard.tsx new file mode 100644 index 000000000..c80bdcc0a --- /dev/null +++ b/packages/web/src/javascripts/Components/ContentListView/FileListItemCard.tsx @@ -0,0 +1,131 @@ +import { FileItem, FileBackupRecord } from '@standardnotes/snjs' +import { observer } from 'mobx-react-lite' +import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' +import { getFileIconComponent } from '../FilePreview/getFileIconComponent' +import ListItemConflictIndicator from './ListItemConflictIndicator' +import ListItemTags from './ListItemTags' +import ListItemMetadata from './ListItemMetadata' +import { DisplayableListItemProps } from './Types/DisplayableListItemProps' +import { useResponsiveAppPane } from '../Panes/ResponsivePaneProvider' +import { useContextMenuEvent } from '@/Hooks/useContextMenuEvent' +import { classNames } from '@standardnotes/utils' +import { formatSizeToReadableString } from '@standardnotes/filepicker' +import { getIconForFileType } from '@/Utils/Items/Icons/getIconForFileType' +import { useApplication } from '../ApplicationProvider' +import Icon from '../Icon/Icon' +import { PaneLayout } from '@/Controllers/PaneController/PaneLayout' + +const FileListItemCard: FunctionComponent> = ({ + filesController, + hideDate, + hideIcon, + hideTags, + item: file, + onSelect, + selected, + sortBy, + tags, +}) => { + const { setPaneLayout } = useResponsiveAppPane() + const application = useApplication() + + const [backupInfo, setBackupInfo] = useState(undefined) + + useEffect(() => { + void application.fileBackups?.getFileBackupInfo(file).then(setBackupInfo) + }, [application, file]) + + const listItemRef = useRef(null) + + const openFileContextMenu = useCallback( + (posX: number, posY: number) => { + filesController.setShowFileContextMenu(false) + filesController.setFileContextMenuLocation({ + x: posX, + y: posY, + }) + filesController.setShowFileContextMenu(true) + }, + [filesController], + ) + + const openContextMenu = useCallback( + async (posX: number, posY: number) => { + let shouldOpenContextMenu = selected + + if (!selected) { + const { didSelect } = await onSelect(file) + if (didSelect) { + shouldOpenContextMenu = true + } + } + + if (shouldOpenContextMenu) { + openFileContextMenu(posX, posY) + } + }, + [selected, onSelect, file, openFileContextMenu], + ) + + const onClick = useCallback(async () => { + const { didSelect } = await onSelect(file, true) + if (didSelect) { + setPaneLayout(PaneLayout.Editing) + } + }, [file, onSelect, setPaneLayout]) + + const IconComponent = () => + getFileIconComponent(getIconForFileType((file as FileItem).mimeType), 'w-10 h-10 flex-shrink-0') + + useContextMenuEvent(listItemRef, openContextMenu) + + return ( +
+
+
+ {!hideIcon ? ( +
+ +
+ ) : ( +
+ )} +
+
+
{file.title}
+
+ + + +
+
+
+
+ {formatSizeToReadableString(file.decryptedSize)} + {backupInfo && ( +
+ +
+ )} +
+
+
+
+ ) +} + +export default observer(FileListItemCard) diff --git a/packages/web/src/javascripts/Components/ContentListView/ListItemFlagIcons.tsx b/packages/web/src/javascripts/Components/ContentListView/ListItemFlagIcons.tsx index 63beb562a..d8ba436ee 100644 --- a/packages/web/src/javascripts/Components/ContentListView/ListItemFlagIcons.tsx +++ b/packages/web/src/javascripts/Components/ContentListView/ListItemFlagIcons.tsx @@ -12,10 +12,17 @@ type Props = { } hasFiles?: boolean hasBorder?: boolean + isFileBackedUp?: boolean className?: string } -const ListItemFlagIcons: FunctionComponent = ({ item, hasFiles = false, hasBorder = true, className }) => { +const ListItemFlagIcons: FunctionComponent = ({ + item, + hasFiles = false, + hasBorder = true, + isFileBackedUp = false, + className, +}) => { return (
{item.locked && ( @@ -48,6 +55,11 @@ const ListItemFlagIcons: FunctionComponent = ({ item, hasFiles = false, h )} + {isFileBackedUp && ( + + + + )}
) }