-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): Added support for file exploring
- Loading branch information
1 parent
81cff64
commit 96ec755
Showing
35 changed files
with
5,875 additions
and
13,652 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.files { | ||
display: flex; | ||
// justify-content: space-evenly; | ||
flex-flow: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import AppHeader from '../../components/molecules/AppHeader'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import FolderIcon from '@material-ui/icons/Folder'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import Collapse from '@material-ui/core/Collapse'; | ||
import ExpandLess from '@material-ui/icons/ExpandLess'; | ||
import ExpandMore from '@material-ui/icons/ExpandMore'; | ||
import InstanceBag from '../../InstanceBag'; | ||
import WasmFs from "@wasmer/wasmfs"; | ||
import Folder from './components/Folder'; | ||
import File from './components/File'; | ||
import Dirent from 'memfs/lib/Dirent'; | ||
const styles = require('./Explorer.scss'); | ||
|
||
export default function Explorer() { | ||
const [isLocationsOpen, setLocationsOpen] = React.useState(true); | ||
const [files, setFiles] = React.useState<Dirent[]>([]); | ||
const [path, setPath] = React.useState('/'); | ||
|
||
React.useEffect(() => { | ||
const wasmFs = InstanceBag.get<WasmFs>('fs'); | ||
const filesAndDirectories: any = wasmFs.fs.readdirSync(path, { | ||
encoding: "utf8", | ||
withFileTypes: true, | ||
}); | ||
|
||
setFiles(filesAndDirectories); | ||
}, [path]); | ||
|
||
function handleFileClick(file: Dirent) { | ||
// Directories should just navigate to the next page | ||
if (file.isDirectory()) { | ||
setPath(`${path}/${file.name}`); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<AppHeader title="Files" menu={ | ||
<List> | ||
<ListItem button onClick={() => setLocationsOpen(!isLocationsOpen)}> | ||
<ListItemText primary="Locations" /> | ||
{isLocationsOpen ? <ExpandLess /> : <ExpandMore />} | ||
</ListItem> | ||
<Collapse in={isLocationsOpen} unmountOnExit> | ||
<ListItem button onClick={() => setPath('/')}> | ||
<ListItemIcon> | ||
<FolderIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Main Drive" /> | ||
</ListItem> | ||
</Collapse> | ||
</List> | ||
}> | ||
<div className={styles.files}> | ||
{files.map((file) => { | ||
if (file.isDirectory()) { | ||
return <Folder key={file.name.toString()} folder={file} onClick={handleFileClick} /> | ||
} else if (file.isFile()) { | ||
return <File key={file.name.toString()} file={file} onClick={handleFileClick} /> | ||
} | ||
})} | ||
</div> | ||
</AppHeader> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.file { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 25%; | ||
} | ||
|
||
.icon { | ||
width: 100%; | ||
height: 60%; | ||
color: #94a9b3; | ||
cursor: pointer; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import Dirent from 'memfs/lib/Dirent'; | ||
import InsertDriveFileOutlinedIcon from '@material-ui/icons/InsertDriveFileOutlined'; | ||
const styles = require('./File.scss'); | ||
|
||
interface Props { | ||
file: Dirent; | ||
onClick?: (folder: Dirent) => void; | ||
} | ||
|
||
export default function File(props: Props) { | ||
return ( | ||
<div className={styles.file}> | ||
<InsertDriveFileOutlinedIcon className={styles.icon} onClick={() => props.onClick(props.file)} /> | ||
<span>{props.file.name}</span> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './File'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.appBar { | ||
// position: unset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
const styles = require('./FileHeader.scss'); | ||
|
||
export default function FileHeader() { | ||
return ( | ||
<AppBar position="static" className={styles.appBar}> | ||
<Typography variant="h3" color="inherit"> | ||
<Toolbar> | ||
Files | ||
</Toolbar> | ||
</Typography> | ||
</AppBar> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './FileHeader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.folder { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 25%; | ||
} | ||
|
||
.icon { | ||
width: 100%; | ||
height: 60%; | ||
color: #6accf9; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import Dirent from 'memfs/lib/Dirent'; | ||
import FolderIcon from '@material-ui/icons/Folder'; | ||
const styles = require('./Folder.scss'); | ||
|
||
interface Props { | ||
folder: Dirent | ||
onClick?: (folder: Dirent) => void; | ||
} | ||
|
||
export default function Folder(props: Props) { | ||
return ( | ||
<div className={styles.folder}> | ||
<FolderIcon className={styles.icon} onClick={() => props.onClick(props.folder)} /> | ||
<span>{props.folder.name}</span> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Folder'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react'; | ||
import * as Loadable from 'react-loadable'; | ||
|
||
function Loading() { | ||
return ( | ||
<div>Loading</div> | ||
); | ||
} | ||
|
||
const LoadableHomePage = Loadable({ | ||
loader: () => import('./Explorer'), | ||
loading: Loading, | ||
}); | ||
|
||
|
||
export default LoadableHomePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ function StoreApp() { | |
</ListItem> | ||
</List> | ||
} | ||
/> | ||
> | ||
Hello | ||
</AppHeader> | ||
</div> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,47 @@ | ||
$drawer-width: 240px; | ||
|
||
.root { | ||
display: flex; | ||
flex-grow: 1; | ||
height: 100%; | ||
} | ||
|
||
.menuButton { | ||
color: white !important; | ||
} | ||
|
||
.appBar { | ||
width: calc(100% - 240px) !important; | ||
float: right; | ||
position: absolute; | ||
background: linear-gradient(-135deg, #17EAD9 0%, #6078EA 100%); | ||
color: white; | ||
z-index: 9999; | ||
// width: calc(100% - #{drawer-width}) !important; | ||
// float: right; | ||
} | ||
|
||
.paper { | ||
width: $drawer-width; | ||
background: white; | ||
margin-top: 64px; | ||
height: calc(100% - 99px); | ||
position: relative; | ||
} | ||
|
||
.drawer { | ||
|
||
:global { | ||
.MuiPaper-root { | ||
width: 240px; | ||
width: $drawer-width; | ||
} | ||
} | ||
} | ||
|
||
.content { | ||
flex-grow: 1; | ||
background-color: #fafafa; | ||
padding: 8px; | ||
width: calc(100% - 16px); | ||
height: calc(100% - 80px); | ||
overflow-y: scroll; | ||
margin-top: 64px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.