2025-01-17 21:09:38 +01:00
|
|
|
import React from 'react'
|
2024-12-06 13:24:10 +01:00
|
|
|
import { Button, Menu, MenuItem } from '@mui/material'
|
2025-01-17 21:09:38 +01:00
|
|
|
import PopupState, { bindTrigger, bindMenu } from 'material-ui-popup-state'
|
2024-08-15 15:35:37 +03:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2025-01-20 19:41:14 +01:00
|
|
|
import {
|
|
|
|
faCheck,
|
|
|
|
faLock,
|
|
|
|
faTriangleExclamation
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
2025-01-17 21:09:38 +01:00
|
|
|
import { CurrentUserFile } from '../../types/file.ts'
|
|
|
|
import styles from './style.module.scss'
|
2024-08-13 12:48:52 +03:00
|
|
|
|
|
|
|
interface FileListProps {
|
|
|
|
files: CurrentUserFile[]
|
|
|
|
currentFile: CurrentUserFile
|
|
|
|
setCurrentFile: (file: CurrentUserFile) => void
|
2025-01-17 21:09:38 +01:00
|
|
|
handleExport?: () => void
|
2024-12-06 13:24:10 +01:00
|
|
|
handleEncryptedExport?: () => void
|
2024-08-13 12:48:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const FileList = ({
|
|
|
|
files,
|
|
|
|
currentFile,
|
|
|
|
setCurrentFile,
|
2024-12-06 13:24:10 +01:00
|
|
|
handleExport,
|
2024-12-09 22:37:27 +01:00
|
|
|
handleEncryptedExport
|
2024-08-13 12:48:52 +03:00
|
|
|
}: FileListProps) => {
|
|
|
|
const isActive = (file: CurrentUserFile) => file.id === currentFile.id
|
|
|
|
return (
|
2024-08-14 16:08:42 +03:00
|
|
|
<div className={styles.wrap}>
|
2024-08-30 17:58:40 +02:00
|
|
|
<ul className={styles.files}>
|
|
|
|
{files.map((currentUserFile: CurrentUserFile) => (
|
|
|
|
<li
|
|
|
|
key={currentUserFile.id}
|
|
|
|
className={`${styles.fileItem} ${isActive(currentUserFile) && styles.active}`}
|
|
|
|
onClick={() => setCurrentFile(currentUserFile)}
|
|
|
|
>
|
|
|
|
<div className={styles.fileNumber}>{currentUserFile.id}</div>
|
|
|
|
<div className={styles.fileInfo}>
|
|
|
|
<div className={styles.fileName}>{currentUserFile.file.name}</div>
|
|
|
|
</div>
|
2024-08-15 15:35:37 +03:00
|
|
|
|
2024-08-30 17:58:40 +02:00
|
|
|
<div className={styles.fileVisual}>
|
|
|
|
{currentUserFile.isHashValid && (
|
|
|
|
<FontAwesomeIcon icon={faCheck} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
2024-12-06 13:24:10 +01:00
|
|
|
|
2025-01-17 21:09:38 +01:00
|
|
|
{(typeof handleExport === 'function' ||
|
|
|
|
typeof handleEncryptedExport === 'function') && (
|
|
|
|
<PopupState variant="popover" popupId="download-popup-menu">
|
|
|
|
{(popupState) => (
|
|
|
|
<React.Fragment>
|
|
|
|
<Button variant="contained" {...bindTrigger(popupState)}>
|
|
|
|
Export files
|
|
|
|
</Button>
|
|
|
|
<Menu {...bindMenu(popupState)}>
|
2025-01-20 19:41:14 +01:00
|
|
|
{typeof handleEncryptedExport === 'function' && (
|
2025-01-17 21:09:38 +01:00
|
|
|
<MenuItem
|
|
|
|
onClick={() => {
|
|
|
|
popupState.close
|
2025-01-20 19:41:14 +01:00
|
|
|
handleEncryptedExport()
|
2025-01-17 21:09:38 +01:00
|
|
|
}}
|
|
|
|
>
|
2025-01-20 19:41:14 +01:00
|
|
|
<FontAwesomeIcon
|
|
|
|
color={'var(--mui-palette-primary-main)'}
|
|
|
|
icon={faLock}
|
|
|
|
/>
|
2025-01-20 21:24:18 +01:00
|
|
|
ENCRYPTED
|
2025-01-17 21:09:38 +01:00
|
|
|
</MenuItem>
|
|
|
|
)}
|
2025-01-20 19:41:14 +01:00
|
|
|
{typeof handleExport === 'function' && (
|
2025-01-17 21:09:38 +01:00
|
|
|
<MenuItem
|
|
|
|
onClick={() => {
|
|
|
|
popupState.close
|
2025-01-20 19:41:14 +01:00
|
|
|
handleExport()
|
2025-01-17 21:09:38 +01:00
|
|
|
}}
|
|
|
|
>
|
2025-01-20 19:41:14 +01:00
|
|
|
<FontAwesomeIcon
|
|
|
|
color={'var(--mui-palette-primary-main)'}
|
|
|
|
icon={faTriangleExclamation}
|
|
|
|
/>
|
2025-01-20 21:24:18 +01:00
|
|
|
UNENCRYPTED
|
2025-01-17 21:09:38 +01:00
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
</Menu>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
</PopupState>
|
|
|
|
)}
|
2024-08-13 12:48:52 +03:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileList
|