|
|
@ -1,4 +1,4 @@ |
|
|
|
import { useState } from 'react'; |
|
|
|
import { useEffect, useState } from 'react'; |
|
|
|
import { Box, IconButton } from '@mui/material'; |
|
|
|
import { Box, IconButton } from '@mui/material'; |
|
|
|
import { Add as AddIcon, Edit as EditIcon } from '@mui/icons-material'; |
|
|
|
import { Add as AddIcon, Edit as EditIcon } from '@mui/icons-material'; |
|
|
|
import { styled } from '@mui/material/styles'; |
|
|
|
import { styled } from '@mui/material/styles'; |
|
|
@ -7,12 +7,12 @@ import EventEmitter from 'events'; |
|
|
|
import ICON_BUTTON_STYLE from '../../lib/consts/ICON_BUTTON_STYLE'; |
|
|
|
import ICON_BUTTON_STYLE from '../../lib/consts/ICON_BUTTON_STYLE'; |
|
|
|
|
|
|
|
|
|
|
|
import { Panel } from '../Panels'; |
|
|
|
import { Panel } from '../Panels'; |
|
|
|
import PeriodicFetch from '../../lib/fetchers/periodicFetch'; |
|
|
|
|
|
|
|
import Spinner from '../Spinner'; |
|
|
|
import Spinner from '../Spinner'; |
|
|
|
import { HeaderText } from '../Text'; |
|
|
|
import { HeaderText } from '../Text'; |
|
|
|
import FileList from './FileList'; |
|
|
|
import FileList from './FileList'; |
|
|
|
import FileUploadInfo from './FileUploadInfo'; |
|
|
|
import FileUploadForm from './FileUploadForm'; |
|
|
|
import FileEditForm from './FileEditForm'; |
|
|
|
import FileEditForm from './FileEditForm'; |
|
|
|
|
|
|
|
import fetchJSON from '../../lib/fetchers/fetchJSON'; |
|
|
|
|
|
|
|
|
|
|
|
const PREFIX = 'Files'; |
|
|
|
const PREFIX = 'Files'; |
|
|
|
|
|
|
|
|
|
|
@ -32,6 +32,11 @@ const StyledDiv = styled('div')(() => ({ |
|
|
|
const StyledIconButton = styled(IconButton)(ICON_BUTTON_STYLE); |
|
|
|
const StyledIconButton = styled(IconButton)(ICON_BUTTON_STYLE); |
|
|
|
|
|
|
|
|
|
|
|
const Files = (): JSX.Element => { |
|
|
|
const Files = (): JSX.Element => { |
|
|
|
|
|
|
|
const [rawFilesOverview, setRawFilesOverview] = useState<string[][]>([]); |
|
|
|
|
|
|
|
const [ |
|
|
|
|
|
|
|
isLoadingRawFilesOverview, |
|
|
|
|
|
|
|
setIsLoadingRawFilesOverview, |
|
|
|
|
|
|
|
] = useState<boolean>(false); |
|
|
|
const [isEditMode, setIsEditMode] = useState<boolean>(false); |
|
|
|
const [isEditMode, setIsEditMode] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
|
|
|
const openFilePickerEventEmitter: EventEmitter = new EventEmitter(); |
|
|
|
const openFilePickerEventEmitter: EventEmitter = new EventEmitter(); |
|
|
@ -44,10 +49,7 @@ const Files = (): JSX.Element => { |
|
|
|
setIsEditMode(!isEditMode); |
|
|
|
setIsEditMode(!isEditMode); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const buildFileList = ( |
|
|
|
const buildFileList = (): JSX.Element => { |
|
|
|
rawFilesOverview: string[][] = [], |
|
|
|
|
|
|
|
isLoadingRawFilesOverview: boolean, |
|
|
|
|
|
|
|
): JSX.Element => { |
|
|
|
|
|
|
|
let elements: JSX.Element; |
|
|
|
let elements: JSX.Element; |
|
|
|
if (isLoadingRawFilesOverview) { |
|
|
|
if (isLoadingRawFilesOverview) { |
|
|
|
elements = <Spinner />; |
|
|
|
elements = <Spinner />; |
|
|
@ -74,13 +76,22 @@ const Files = (): JSX.Element => { |
|
|
|
return elements; |
|
|
|
return elements; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const fetchRawFilesOverview = async () => { |
|
|
|
data: rawFilesOverview, |
|
|
|
setIsLoadingRawFilesOverview(true); |
|
|
|
isLoading: isLoadingRawFilesOverview, |
|
|
|
|
|
|
|
} = PeriodicFetch<string[][]>( |
|
|
|
const data = await fetchJSON<string[][]>( |
|
|
|
`${process.env.NEXT_PUBLIC_API_URL?.replace('/cgi-bin', '/api')}/files`, |
|
|
|
`${process.env.NEXT_PUBLIC_API_URL?.replace('/cgi-bin', '/api')}/files`, |
|
|
|
0, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
setRawFilesOverview(data); |
|
|
|
|
|
|
|
setIsLoadingRawFilesOverview(false); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (!isEditMode) { |
|
|
|
|
|
|
|
fetchRawFilesOverview(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [isEditMode]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Panel> |
|
|
|
<Panel> |
|
|
@ -100,10 +111,13 @@ const Files = (): JSX.Element => { |
|
|
|
</StyledIconButton> |
|
|
|
</StyledIconButton> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
<FileUploadInfo |
|
|
|
<FileUploadForm |
|
|
|
|
|
|
|
onFileUploadComplete={() => { |
|
|
|
|
|
|
|
fetchRawFilesOverview(); |
|
|
|
|
|
|
|
}} |
|
|
|
openFilePickerEventEmitter={openFilePickerEventEmitter} |
|
|
|
openFilePickerEventEmitter={openFilePickerEventEmitter} |
|
|
|
/> |
|
|
|
/> |
|
|
|
{buildFileList(rawFilesOverview, isLoadingRawFilesOverview)} |
|
|
|
{buildFileList()} |
|
|
|
</StyledDiv> |
|
|
|
</StyledDiv> |
|
|
|
</Panel> |
|
|
|
</Panel> |
|
|
|
); |
|
|
|
); |
|
|
|