Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar in browser #2

Merged
merged 36 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8ea1b7e
Fixed multi download not appearing correctly
MangoCubes Nov 22, 2022
f161936
Added caching for FileBrowser
MangoCubes Nov 22, 2022
870884f
Added separate sidebar for filebrowser
MangoCubes Nov 22, 2022
72457ef
Stateful cache
MangoCubes Nov 22, 2022
741977e
Cache is used as primary item storage instead
MangoCubes Nov 22, 2022
826a20f
Starting work on filebrowser tree
MangoCubes Nov 23, 2022
324edfe
Empty cache container is added for each child directories
MangoCubes Nov 23, 2022
179b11c
Items on sidebar loads if it is not already
MangoCubes Nov 23, 2022
ed2062c
Added optional controller to make sidebar tree independent from main …
MangoCubes Nov 23, 2022
adb529e
Cache will be used unless explicitly refreshed
MangoCubes Nov 23, 2022
1fa8f2a
Fixed cache being invalidated upon going to parent folder
MangoCubes Nov 23, 2022
934bb20
Moved code into the scope where it matters
MangoCubes Nov 23, 2022
65a90f8
Merged two boolean states into one enum
MangoCubes Nov 25, 2022
aee848f
Failsafe when items is empty
MangoCubes Nov 25, 2022
ed84c71
Concurrency handling
MangoCubes Nov 25, 2022
e7762ca
Moved types for reuse
MangoCubes Nov 25, 2022
d87a47d
Removed potential invalid states
MangoCubes Nov 25, 2022
d761aaf
Applied similar method to vault browser
MangoCubes Nov 25, 2022
d947396
Nonexistent record is correctly assumed as not started
MangoCubes Nov 25, 2022
f42640f
Starting work on vault sidebar
MangoCubes Nov 25, 2022
137a4c8
Added sidebar back into vault browser
MangoCubes Nov 25, 2022
271c72d
Loading dir id happens after loading screen is shown
MangoCubes Nov 26, 2022
d4782c5
Buttons are disabled properly during loading screen
MangoCubes Nov 26, 2022
0a29e1b
Applying similar approach on FileBrowser for simpler code
MangoCubes Nov 26, 2022
5d1abe5
Fixed contents going out of sidebar's intended size
MangoCubes Nov 26, 2022
55390f1
Experimental way of handling async id fetching
MangoCubes Nov 26, 2022
2ba62b7
Fixed wrong id being passed
MangoCubes Nov 26, 2022
1af5810
Decrypted name is displayed instead of placeholder
MangoCubes Nov 26, 2022
4133119
Added placeholder if there are no subdirs
MangoCubes Nov 27, 2022
a364c44
Fixed missing unique key
MangoCubes Nov 27, 2022
9537277
Fixed text going over sidebar
MangoCubes Nov 27, 2022
8325561
Reusing component for both sidebars
MangoCubes Nov 27, 2022
4806381
Browser control separated from querying
MangoCubes Nov 27, 2022
0f84220
Minor bug fixes
MangoCubes Nov 27, 2022
184966f
Previous items will not be discarded during query
MangoCubes Nov 27, 2022
ec45fb9
Functional reload button
MangoCubes Nov 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merged two boolean states into one enum
  • Loading branch information
MangoCubes committed Nov 25, 2022
commit 65a90f84d3052ec0077f1702f5cfd9b40025afcb
48 changes: 31 additions & 17 deletions src/web/fileBrowser/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import { ItemDownloader } from "../ItemDownloader";
import { FileSidebar } from "./FileSidebar";
import { VaultDialog } from "./VaultDialog";

enum Querying {
/**
* Disable nothing
*/
None,
/**
* Show items, but disallow changing dir and interacting with buttons
*/
Partial,
/**
* Hide items and show loading icon instead
*/
Full
}

export type DirCache = {[key: string]: {
child: Item[];
explored: ExpStatus;
Expand All @@ -32,10 +47,11 @@ export function FileBrowser(props: {
// Note to self: Uses of path notation through string array should be kept to minimum
const [dir, setDir] = useState<string[]>([]);
const [items, setItems] = useState<DirCache>({'/': {child: [], explored: ExpStatus.NotStarted}});
const [loading, setLoading] = useState(false);
const [sel, setSel] = useState<GridSelectionModel>([]);
const [open, setOpen] = useState(false);
const [querying, setQuerying] = useState(false);

// Controls button availability
const [querying, setQuerying] = useState<Querying>(Querying.None);

const columns = useMemo(() => [
{field: 'type', headerName: '', width: 24, renderCell: (params: GridRenderCellParams<string>) => {
Expand All @@ -51,15 +67,15 @@ export function FileBrowser(props: {
type: 'actions',
getActions: (params: GridRowParams) => {
const def = [];
if(params.row.type === 'f') def.push(<GridActionsCellItem icon={<Download/>} onClick={() => props.download([params.row.obj])} label='Download' disabled={querying}/>);
if(params.row.type !== 'parent') def.push(<GridActionsCellItem icon={<Delete/>} label='Delete' onClick={() => onDelete(params.row.obj)} showInMenu disabled={querying}/>);
if(params.row.type === 'f') def.push(<GridActionsCellItem icon={<Download/>} onClick={() => props.download([params.row.obj])} label='Download' disabled={querying !== Querying.None}/>);
if(params.row.type !== 'parent') def.push(<GridActionsCellItem icon={<Delete/>} label='Delete' onClick={() => onDelete(params.row.obj)} showInMenu disabled={querying !== Querying.None}/>);
return def;
}
}
], [props.download, dir, querying]);

useEffect(() => {
loadItems(dir);
loadItems([]);
}, []);

const getDirItems = (absDir?: string[]) => {
Expand All @@ -71,9 +87,8 @@ export function FileBrowser(props: {
const dir = '/' + absDir.join('/');
const temp = getDirItems(absDir);
try {

if (bypassCache || items[dir].explored !== ExpStatus.Ready) {
if (controlBrowser) setLoading(true);
if (controlBrowser) setQuerying(Querying.Full);
const stat = {...items};
stat[dir] = {
explored: ExpStatus.Querying,
Expand All @@ -95,20 +110,19 @@ export function FileBrowser(props: {
setItems(copy);
}
if (controlBrowser) setDir(absDir);

} catch(e) {
const copy = {...items};
copy[dir] = {
child: temp,
explored: ExpStatus.Error
}
} finally {
if (controlBrowser) setLoading(false);
if (controlBrowser) setQuerying(Querying.None);
}
}

const loadSubDir = async (subDir: string | null) => {
if (querying) return;
if (querying !== Querying.None) return;
if (subDir === null) await loadItems(dir.slice(0, -1), true);
else await loadItems([...dir, subDir], true);
}
Expand All @@ -129,15 +143,15 @@ export function FileBrowser(props: {
}

const onDelete = async (item?: Item) => {
setQuerying(true);
setQuerying(Querying.Partial);
if(item) await delItems(item);
else {
const targets = getSelectedItems();
const tasks: Promise<void>[] = [];
for(const t of targets) tasks.push(delItems(t));
await Promise.all(tasks);
}
setQuerying(false);
setQuerying(Querying.None);
await reload();
}

Expand All @@ -146,7 +160,7 @@ export function FileBrowser(props: {
}

const getRows = () => {
if (loading) return [];
if (querying === Querying.Full) return [];
else {
const rows = [];
if(dir.length){
Expand Down Expand Up @@ -192,14 +206,14 @@ export function FileBrowser(props: {
}

const toolbar = () => {
if(sel.length) return <SelectionToolbar selected={sel.length} del={onDelete} download={downloadSelected} disabled={querying}/>;
if(sel.length) return <SelectionToolbar selected={sel.length} del={onDelete} download={downloadSelected} disabled={querying !== Querying.None}/>;
else return (
<Toolbar>
<Typography variant='h5'>{dir.length === 0 ? 'Root' : dir[dir.length - 1]}</Typography>
<Box sx={{flex: 1}}/>
<Tooltip title='Refresh'>
<span>
<IconButton edge='end' onClick={reload} disabled={loading || querying}>
<IconButton edge='end' onClick={reload} disabled={querying !== Querying.None}>
<Refresh/>
</IconButton>
</span>
Expand Down Expand Up @@ -230,11 +244,11 @@ export function FileBrowser(props: {
isRowSelectable={(params: GridRowParams) => params.row.type !== 'parent'}
columns={columns}
rows={getRows()}
loading={loading}
loading={querying === Querying.Full}
checkboxSelection
selectionModel={sel}
onSelectionModelChange={items => {
if(!loading) setSel(items);
if(querying !== Querying.None) setSel(items);
}}
/>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions src/web/fileBrowser/FileSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export function FileSidebar(props: {
} else if(subDir.explored === ExpStatus.Error) {
return [
<TreeItem nodeId={dirKey + 'Error'} key={dirKey + 'Error'} label='Error loading'/>
]
];
} else {
return [
<TreeItem nodeId={dirKey + 'Loading'} key={dirKey + 'Loading'} label='Loading...'/>
]
];
}
}

Expand Down