-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(FolderPicker): Use ListItem instead File
This decouples the display of the file table from that of the FolderPicker modal. This will allow you to change the lines as Link in the table in order to take advantage of the default mechanisms of browsers
- Loading branch information
Showing
10 changed files
with
249 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { FC } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
|
||
import { useClient } from 'cozy-client' | ||
import { useVaultClient } from 'cozy-keys-lib' | ||
import Divider from 'cozy-ui/transpiled/react/Divider' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import IconFolder from 'cozy-ui/transpiled/react/Icons/FileTypeFolder' | ||
import ListItem from 'cozy-ui/transpiled/react/ListItem' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert' | ||
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import FilenameInput from 'modules/filelist/FilenameInput' | ||
import { createFolder } from 'modules/navigation/duck' | ||
import IconEncryptedFolder from 'modules/views/Folder/EncryptedFolderIcon' | ||
|
||
interface FolderPickerAddFolderItemProps { | ||
isEncrypted: boolean | ||
currentFolderId: string | ||
visible: boolean | ||
afterSubmit: () => void | ||
afterAbort: () => void | ||
} | ||
|
||
const FolderPickerAddFolderItem: FC<FolderPickerAddFolderItemProps> = ({ | ||
isEncrypted, | ||
currentFolderId, | ||
visible, | ||
afterSubmit, | ||
afterAbort | ||
}) => { | ||
const { isMobile } = useBreakpoints() | ||
const gutters = isMobile ? 'default' : 'double' | ||
const dispatch = useDispatch() | ||
const { showAlert } = useAlert() | ||
const { t } = useI18n() | ||
const vaultClient = useVaultClient() | ||
const client = useClient() | ||
|
||
const handleSubmit = (name: string): void => { | ||
dispatch( | ||
createFolder(client, vaultClient, name, currentFolderId, { | ||
isEncryptedFolder: isEncrypted, | ||
showAlert, | ||
t | ||
}) | ||
) | ||
if (typeof afterSubmit === 'function') { | ||
afterSubmit() | ||
} | ||
} | ||
|
||
const handleAbort = (accidental: boolean): void => { | ||
if (accidental) { | ||
showAlert({ | ||
message: t('alert.folder_abort'), // | ||
severity: 'secondary' | ||
}) | ||
} | ||
if (typeof afterAbort === 'function') { | ||
afterAbort() | ||
} | ||
} | ||
|
||
if (visible) { | ||
return ( | ||
<> | ||
<ListItem gutters={gutters}> | ||
<ListItemIcon> | ||
<Icon | ||
icon={isEncrypted ? IconEncryptedFolder : IconFolder} | ||
size={32} | ||
/> | ||
</ListItemIcon> | ||
<FilenameInput onSubmit={handleSubmit} onAbort={handleAbort} /> | ||
</ListItem> | ||
<Divider /> | ||
</> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export { FolderPickerAddFolderItem } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/components/FolderPicker/FolderPickerContentExplorer.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { filesize } from 'filesize' | ||
import React, { FC } from 'react' | ||
|
||
import { isDirectory } from 'cozy-client/dist/models/file' | ||
import Divider from 'cozy-ui/transpiled/react/Divider' | ||
import ListItem from 'cozy-ui/transpiled/react/ListItem' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import type { File } from 'components/FolderPicker/types' | ||
import FileThumbnail from 'modules/filelist/icons/FileThumbnail' | ||
|
||
import styles from 'styles/folder-picker.styl' | ||
|
||
interface FolderPickerListItemProps { | ||
file: File | ||
disabled?: boolean | ||
onClick: (file: File) => void | ||
showDivider?: boolean | ||
} | ||
|
||
const FolderPickerListItem: FC<FolderPickerListItemProps> = ({ | ||
file, | ||
disabled = false, | ||
onClick, | ||
showDivider = false | ||
}) => { | ||
const { f, t } = useI18n() | ||
const { isMobile } = useBreakpoints() | ||
const gutters = isMobile ? 'default' : 'double' | ||
|
||
const handleClick = (): void => { | ||
onClick(file) | ||
} | ||
|
||
const formattedUpdatedAt = f(file.updated_at, t('table.row_update_format')) | ||
const formattedSize = file.size | ||
? filesize(file.size, { base: 10 }) | ||
: undefined | ||
const secondaryText = !isDirectory(file) | ||
? `${formattedUpdatedAt}${formattedSize ? ` - ${formattedSize}` : ''}` | ||
: undefined | ||
|
||
return ( | ||
<> | ||
<ListItem | ||
button | ||
onClick={handleClick} | ||
disabled={disabled} | ||
gutters={gutters} | ||
> | ||
<ListItemIcon className="u-pos-relative"> | ||
<FileThumbnail | ||
file={file} | ||
showSharedBadge | ||
componentsProps={{ | ||
sharedBadge: { | ||
className: styles['icon-shared'] | ||
} | ||
}} | ||
/> | ||
</ListItemIcon> | ||
<ListItemText primary={file.name} secondary={secondaryText} /> | ||
</ListItem> | ||
{showDivider && <Divider />} | ||
</> | ||
) | ||
} | ||
|
||
export { FolderPickerListItem } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.