feat: Resource

This commit is contained in:
cha0s 2021-01-23 23:03:39 -06:00
parent ad771329d2
commit b7e50bc6f3
6 changed files with 50 additions and 3 deletions

View File

@ -14,6 +14,7 @@ import {
import Dashboard from 'components/dashboard'; import Dashboard from 'components/dashboard';
import ProjectRoute from 'components/project/route'; import ProjectRoute from 'components/project/route';
import ResourceRoute from 'components/resource/route';
const Persea = React.memo(({history}) => { const Persea = React.memo(({history}) => {
const isLoggedIn = useSelector(userIdSelector); const isLoggedIn = useSelector(userIdSelector);
@ -24,6 +25,7 @@ const Persea = React.memo(({history}) => {
{isLoggedIn ? <Redirect to="/" /> : Login} {isLoggedIn ? <Redirect to="/" /> : Login}
</Route> </Route>
<Route path="/dashboard" component={Dashboard} /> <Route path="/dashboard" component={Dashboard} />
<Route path="/project/:uuid:uri(/.*)" component={ResourceRoute} />
<Route path="/project/:uuid" component={ProjectRoute} /> <Route path="/project/:uuid" component={ProjectRoute} />
</Switch> </Switch>
<Route exact path="/"> <Route exact path="/">

View File

@ -1,15 +1,18 @@
import './index.scss'; import './index.scss';
import {PropTypes, React} from '@latus/react'; import {join} from 'path';
const Project = ({project: {label, resourcePaths}}) => ( import {PropTypes, React} from '@latus/react';
import {Link} from 'react-router-dom';
const Project = ({project: {label, resourcePaths}, uuid}) => (
<div className="project"> <div className="project">
<h2 className="project__title">{label}</h2> <h2 className="project__title">{label}</h2>
<ul> <ul>
{resourcePaths.map(([isFile, resourcePath]) => ( {resourcePaths.map(([isFile, resourcePath]) => (
<li key={resourcePath}> <li key={resourcePath}>
{isFile ? 'File: ' : 'Directory: '} {isFile ? 'File: ' : 'Directory: '}
{resourcePath} <Link to={join('/project', uuid, resourcePath)}>{resourcePath}</Link>
</li> </li>
))} ))}
</ul> </ul>

View File

@ -0,0 +1,22 @@
import './index.scss';
import {PropTypes, React} from '@latus/react';
import {useSelector} from '@latus/redux';
import {projectsSelector} from '@persea/core';
const Resource = ({uri, uuid}) => {
const {resources} = useSelector(projectsSelector);
const buffer = Buffer.from(resources[`${uuid}${uri}`], 'base64');
return (
<div className="resource">
<h2 className="resource__title">{buffer.toString()}</h2>
</div>
);
};
Resource.propTypes = {
uri: PropTypes.string.isRequired,
uuid: PropTypes.string.isRequired,
};
export default Resource;

View File

@ -0,0 +1,20 @@
import './index.scss';
import {PropTypes, React} from '@latus/react';
import Resource from '../index';
const ResourceRoute = ({match: {params: {uri, uuid}}}) => (
<Resource uri={uri} uuid={uuid} />
);
ResourceRoute.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
uri: PropTypes.string,
uuid: PropTypes.string,
}),
}).isRequired,
};
export default ResourceRoute;