diff --git a/client/src/Components/HostedEvent/graphql.js b/client/src/Components/HostedEvent/graphql.js new file mode 100644 index 000000000..83b5882ce --- /dev/null +++ b/client/src/Components/HostedEvent/graphql.js @@ -0,0 +1,20 @@ +import gql from 'graphql-tag' + +const fragments = ` + name +` + +export const HOSTS_HOSTEVENT = gql` + mutation Hosts_HostEvent($name: String!, $description: String!, $startDatetime: Int!, $finishDatetime: Int!) { + hosts_HostEvent(name: $name, description: $description, startDatetime: $startDatetime, finishDatetime: $finishDatetime) { + ${fragments} + } + } +` +export const HOSTS_EVENTSBYHOST = gql` + query Hosts_EventsByHost{ + hosts_EventsByHost { + ${fragments} + } + } +` diff --git a/client/src/Components/HostedEvent/index.js b/client/src/Components/HostedEvent/index.js new file mode 100644 index 000000000..323687de8 --- /dev/null +++ b/client/src/Components/HostedEvent/index.js @@ -0,0 +1,86 @@ +import React from 'react' +import { Query } from 'react-apollo' +import { HOSTS_EVENTSBYHOST } from './graphql' + +import { + Button, + Dialog, + DialogContent, + DialogContentText, + DialogTitle +} from '@material-ui/core' + +import { withStyles } from '@material-ui/core/styles' +import styles from './styles' + +import New from './new' + +class HostedEvent extends React.Component { + constructor (props) { + super(props) + this.state = { + isNewEventOpen: false + } + } + + handleNewEventOpen = () => { + this.setState({ isNewEventOpen: true }) + }; + + handleNewEventClose = () => { + this.setState({ isNewEventOpen: false }) + }; + + render () { + const { classes } = this.props + return ( + + + {({ loading, error, data }) => { + if (loading) return 'Loading...' + if (error) return `Error! ${error.message}` + const list = data.hosts_EventsByHost.map((event, index) => { + return ( +
+ {event.name} +
+ ) + }) + return ( + + { list } + + ) + }} +
+ + + + + + Host an event + + + + Here you will add just the minimal information, will be settable in the edit page of your event. + + + + + +
+ ) + } +} + +export default withStyles(styles)(HostedEvent) diff --git a/client/src/Components/HostedEvent/new.js b/client/src/Components/HostedEvent/new.js new file mode 100644 index 000000000..ad95e7bcf --- /dev/null +++ b/client/src/Components/HostedEvent/new.js @@ -0,0 +1,77 @@ +import React from 'react' +import { Mutation } from 'react-apollo' +import { HOSTS_HOSTEVENT, HOSTS_EVENTSBYHOST } from './graphql' + +/* +import classNames from 'classnames' +import { + Button, + TextField +} from '@material-ui/core' +*/ + +class New extends React.Component { + render () { + let name + let description + let startDatetime + let finishDatetime + // const { classes } = this.props + return ( + { + const { hosts_EventsByHost: hostedEvents } = store.readQuery({ query: HOSTS_EVENTSBYHOST }) + store.writeQuery({ + query: HOSTS_EVENTSBYHOST, + data: { hosts_EventsByHost: hostedEvents.concat([data.hosts_HostEvent]) } + }) + } + } + > + {(hostEvent, { data }) => ( +
+
{ + e.preventDefault() + hostEvent({ variables: { + name: name.value, + description: description.value, + startDatetime: parseInt(startDatetime.value, 10), + finishDatetime: parseInt(finishDatetime.value, 10) + } }) + this.props.handleNewEventClose() + }} + > + { + name = node + }} + /> + { + description = node + }} + /> + { + startDatetime = node + }} + /> + { + finishDatetime = node + }} + /> + +
+
this.clearTempStates()} /> +
+ )} + + ) + } +} + +export default New diff --git a/client/src/Components/HostedEvent/styles.js b/client/src/Components/HostedEvent/styles.js new file mode 100644 index 000000000..382437a4b --- /dev/null +++ b/client/src/Components/HostedEvent/styles.js @@ -0,0 +1,10 @@ + +const styles = theme => ({ + centered: { + display: 'block', + marginLeft: 'auto', + marginRight: 'auto' + } +}) + +export default styles diff --git a/client/src/Components/TopBar/data.js b/client/src/Components/TopBar/data.js index 2f58b632b..37d33c471 100644 --- a/client/src/Components/TopBar/data.js +++ b/client/src/Components/TopBar/data.js @@ -3,9 +3,9 @@ import SearchIcon from '@material-ui/icons/Search' import LibraryAddIcon from '@material-ui/icons/LibraryAdd' const data = [ - { title: 'Look for competitions', to: '/', icon: SearchIcon, text: '' }, - { title: 'Competitions you applied for', to: '/competitions', icon: GamesIcon, text: '' }, - { title: 'Host your own competition', to: '/host-your-own', icon: LibraryAddIcon, text: '' } + { title: 'Look for an event', to: '/', icon: SearchIcon, text: '' }, + { title: 'Events you are enrolled in', to: '/events', icon: GamesIcon, text: '' }, + { title: 'Host your own competition', to: '/hosted-events', icon: LibraryAddIcon, text: '' } ] export default data diff --git a/client/src/index.js b/client/src/index.js index fc8bc3d64..2e4c0c8b6 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,26 +1,11 @@ import React, { Component } from 'react' import { Route, BrowserRouter, Switch } from 'react-router-dom' -import { MessageCard } from '@advancedalgos/web-components' import { getItem } from './utils/local-storage' import TopBar from './Components/TopBar' import Search from './Components/Search' - -const Base = () => ( -
-

Base component

- -
Loading...
-
-
-) - -const Added = () => ( -

- Added component -

-) +import HostedEvent from './Components/HostedEvent' class App extends Component { constructor (props) { @@ -35,7 +20,7 @@ class App extends Component { if (user !== null && user !== undefined && user !== 'undefined') { user = JSON.parse(user) - this.setState({ user: user }) + this.setState({ user }) } } @@ -52,7 +37,7 @@ class App extends Component { {loggedIn} - +