forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManagerContainer.tsx
More file actions
72 lines (68 loc) · 3.48 KB
/
Copy pathFileManagerContainer.tsx
File metadata and controls
72 lines (68 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useEffect, useState } from 'react';
import FlashMessageRender from '@/components/FlashMessageRender';
import { ServerContext } from '@/state/server';
import { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import { httpErrorToHuman } from '@/api/http';
import { CSSTransition } from 'react-transition-group';
import Spinner from '@/components/elements/Spinner';
import FileObjectRow from '@/components/server/files/FileObjectRow';
import FileManagerBreadcrumbs from '@/components/server/files/FileManagerBreadcrumbs';
export default () => {
const [ loading, setLoading ] = useState(true);
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
const { contents: files, directory } = ServerContext.useStoreState(state => state.files);
const { getDirectoryContents } = ServerContext.useStoreActions(actions => actions.files);
useEffect(() => {
setLoading(true);
clearFlashes();
getDirectoryContents(window.location.hash.replace(/^#(\/)*/, '/'))
.then(() => setLoading(false))
.catch(error => {
console.error(error.message, { error });
addError({ message: httpErrorToHuman(error), key: 'files' });
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ directory ]);
return (
<div className={'my-10 mb-6'}>
<FlashMessageRender byKey={'files'} className={'mb-4'}/>
<React.Fragment>
<FileManagerBreadcrumbs/>
{
loading ?
<Spinner size={'large'} centered={true}/>
:
!files.length ?
<p className={'text-sm text-neutral-600 text-center'}>
This directory seems to be empty.
</p>
:
<CSSTransition classNames={'fade'} timeout={250} appear={true} in={true}>
<div>
{files.length > 250 ?
<React.Fragment>
<div className={'rounded bg-yellow-400 mb-px p-3'}>
<p className={'text-yellow-900 text-sm text-center'}>
This directory is too large to display in the browser, limiting
the output to the first 250 files.
</p>
</div>
{
files.slice(0, 250).map(file => (
<FileObjectRow key={file.uuid} file={file}/>
))
}
</React.Fragment>
:
files.map(file => (
<FileObjectRow key={file.uuid} file={file}/>
))
}
</div>
</CSSTransition>
}
</React.Fragment>
</div>
);
};