From 49b0adea7064b6b527bc75900fd7d3061e71eff9 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 24 Apr 2019 15:11:22 -0400 Subject: [PATCH] feat(projects): add base projects list --- src/components/MainCointainer.jsx | 4 ++ src/components/projects/Projects.jsx | 84 ++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/components/projects/Projects.jsx diff --git a/src/components/MainCointainer.jsx b/src/components/MainCointainer.jsx index 75961d9..061c541 100644 --- a/src/components/MainCointainer.jsx +++ b/src/components/MainCointainer.jsx @@ -18,11 +18,13 @@ import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import ListItemText from '@material-ui/core/ListItemText'; import InboxIcon from '@material-ui/icons/MoveToInbox'; +import ProjectIcon from '@material-ui/icons/Work'; import { ScaleLoader } from 'react-spinners' import FundsManagement from './FundsManagement' import ContractAdmin from './ContractAdmin' import TransferGraph from './TransfersGraph' import Dashboard from './Dashboard' +import Projects from './projects/Projects' import Project from './projects/Project' import BackProject from './projects/BackProject' import CreateProject from './projects/CreateProject' @@ -165,6 +167,7 @@ class PersistentDrawerLeft extends React.Component { }/> + }/> }/> }/> }/> @@ -183,6 +186,7 @@ class PersistentDrawerLeft extends React.Component { } /> + } /> diff --git a/src/components/projects/Projects.jsx b/src/components/projects/Projects.jsx new file mode 100644 index 0000000..fa19c0f --- /dev/null +++ b/src/components/projects/Projects.jsx @@ -0,0 +1,84 @@ +import React from 'react' +import { withStyles } from '@material-ui/core/styles' +import {withDatabase} from "@nozbe/watermelondb/DatabaseProvider"; +import withObservables from "@nozbe/with-observables"; +import {Q} from "@nozbe/watermelondb"; +import PropTypes from 'prop-types' +import {useProjectData} from "./hooks"; +import Loading from "../base/Loading"; +import Grid from '@material-ui/core/Grid'; +import {Link} from "react-router-dom"; + +const styles = theme => ({ + root: { + margin: '1.75rem 4.5rem', + ...theme.typography.body1 + }, + link: { + textDecoration: 'none', + ...theme.typography.body1, + '&:hover': { + textDecoration: 'underline', + cursor: 'pointer' + } + } +}) + +// function sortByTitle(a, b) { +// if (!a.manifest || !b.manifest) { +// return 0; +// } +// return a.manifest.title.localeCompare(b.manifest.title) +// } + +// No date field, but we can use the ID +function sortByDate(a, b) { + if (parseInt(a.projectId, 10) > parseInt(b.projectId, 10)) { + return -1; + } + return 1; +} + +function Projects({projectAddedEvents, classes}) { + const projects = projectAddedEvents.map(event => { + return Object.assign({projectId: event.returnValues.idProject}, useProjectData(event.returnValues.idProject, '', projectAddedEvents)); + }) + + projects.sort(sortByDate) + + return (
+

Projects

+ {projects.length === 0 && } + {projects.length > 0 && + + {projects.map((project, index) => { + if (!project.manifest) { + return '' + } + return ( + + +

{project.manifest.title}

+

{project.manifest.subtitle}

+

{project.manifest.description}

+

{project.manifest.avatar && + avatar}{project.manifest.creator}

+ +
+ ) + })} +
} +
) +} + +Projects.propTypes = { + projectAddedEvents: PropTypes.array, + classes: PropTypes.object +} + +const StyledProject = withStyles(styles)(Projects) +export default withDatabase(withObservables([], ({ database }) => ({ + projectAddedEvents: database.collections.get('lp_events').query( + Q.where('event', 'ProjectAdded') + ).observe() +}))(StyledProject))