From 5c139be17a369039dde9033ebb0ec2de20f4c6fc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 Jul 2023 17:47:10 -0500 Subject: implement deletes --- src/web/src/components/System/Files/Explorer.js | 111 ++++++++++++++++++------ 1 file changed, 84 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Files/Explorer.js b/src/web/src/components/System/Files/Explorer.js index adc8d3bf..aa2ae784 100644 --- a/src/web/src/components/System/Files/Explorer.js +++ b/src/web/src/components/System/Files/Explorer.js @@ -3,58 +3,115 @@ import React, { useState, useEffect } from 'react'; import { Table, Icon, - Message + Message, + Modal, + Header, } from 'semantic-ui-react'; -import { list } from '../../../lib/files'; +import { list, deleteDirectory, deleteFile } from '../../../lib/files'; import { formatBytes, formatDate } from '../../../lib/util'; import { LoaderSegment } from '../../Shared'; -const Explorer = ({ root, isActive }) => { +const Explorer = ({ root }) => { const [directory, setDirectory] = useState({ files: [], directories: [] }); const [subdirectory, setSubdirectory] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { - setLoading(true); - - console.log('fetching...', subdirectory); - const fetch = async () => { - const dir = await list({ root, subdirectory: subdirectory.join('/') }); - console.log(dir) - setDirectory(dir); - setLoading(false); - }; - fetch(); - }, [isActive, subdirectory]); + }, [subdirectory]); // eslint-disable-line react-hooks/exhaustive-deps + + useEffect(() => { + setSubdirectory([]); + }, [root]); + + const fetch = async () => { + setLoading(true); + const dir = await list({ root, subdirectory: subdirectory.join('/') }); + setDirectory(dir); + setLoading(false); + }; const select = ({ path }) => { setSubdirectory([...subdirectory, path]); - console.log(path) }; - const row = (icon, { name, fullName, modifiedAt, length }, onClick = () => { }) => - onClick({ path: name })} - >{name} + const upOneSubdirectory = () => { + const copy = [...subdirectory]; + copy.pop(); + setSubdirectory(copy); + }; + + const FileRow = ({ name, fullName, modifiedAt, length }) => + {name} {modifiedAt ? formatDate(modifiedAt) : ''} {length ? formatBytes(length) : ''} - console.log(fullName)} style={{ cursor: 'pointer' }}/> + + } + centered + size='small' + header={
} + content={`Are you sure you want to delete file '${fullName}'?`} + actions={[ + 'Cancel', + { + key: 'done', + content: 'Delete', + negative: true, + onClick: async () => { + await deleteFile({ root, path: `${subdirectory.join('/')}/${fullName}`}); + fetch(); + }, + }, + ]} + /> ; + const DirectoryRow = ({ name, fullName, modifiedAt, onClick = () => {} }) => + {name} + {modifiedAt ? formatDate(modifiedAt) : ''} + + + + } + centered + size='small' + header={
} + content={`Are you sure you want to delete directory '${fullName}'?`} + actions={[ + 'Cancel', + { + key: 'done', + content: 'Delete', + negative: true, + onClick: async () => { + await deleteDirectory({ root, path: `${subdirectory.join('/')}/${fullName}`}); + fetch(); + }, + }, + ]} + /> + + ; + if (loading) { return ; } return ( <> - {!!subdirectory && - {root + '/' + subdirectory} - } + + {'/' + root + '/' + subdirectory.join('/')} + @@ -65,9 +122,9 @@ const Explorer = ({ root, isActive }) => { - {!!subdirectory && row('folder', { name: '..', fullName: '..' })} - {directory?.directories?.map((d => row('folder', d, select)))} - {directory?.files?.map(f => row('file outline', f))} + {subdirectory.length > 0 && } + {directory?.directories?.map(d => select({ path: d.name })} {...d}/>)} + {directory?.files?.map(f => )}
-- cgit v1.2.3