Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Dispatcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Dispatcher } from 'flux';

export default new Dispatcher;
43 changes: 43 additions & 0 deletions src/actions/CreateEventAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import dispatcher from '../Dispatcher';
import axios from 'axios';


const axiosConfig = () => {
return axios.create({
headers: {'Content-Type': "application/json; charset=utf-8"}
});
}


const createFormData = (form) => {

let body = form.filter(el => el.name)
.reduce((a, b) => ({...a, [b.name]: b.value}), {});

body["timestamp"] = new Date().toISOString();
body["event_time"] = new Date().toISOString();
body["address"] = body["address"] + " - " + body["addressNumber"];
return JSON.stringify(body);
}


export function createEventAction(event) {
var url = "https://solidarize-dev.herokuapp.com/event";
let data = createFormData(event);
dispatcher.dispatch({
type: 'CREATE_EVENT'
});
console.log(data);
axiosConfig().post(url, data)
.then(res => {
dispatcher.dispatch({
type: 'CREATE_EVENT_SUCCESS'
})
});
}

export function successConfirm() {
dispatcher.dispatch({
type: 'CREATE_EVENT_SUCCESS_CONFIRM'
});
}
15 changes: 15 additions & 0 deletions src/actions/EventDetailsAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dispatcher from '../Dispatcher';
import axios from 'axios';

export function eventDetailListAction(eventId) {
dispatcher.dispatch({
type: 'EVENT_DETAIL_COMPONENT_VISIBLE'
});
axios.get('https://solidarize-dev.herokuapp.com/event/' + eventId)
.then(res => {
dispatcher.dispatch({
type: 'EVENT_DETAIL_DATA',
events: [res.data]
})
});
}
54 changes: 54 additions & 0 deletions src/actions/HeaderActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import dispatcher from '../Dispatcher';
import axios from 'axios';

export function aboutAction() {
dispatcher.dispatch({
type: 'ABOUT_COMPONENT_VISIBLE'
})
}

export function createEventAction() {
dispatcher.dispatch({
type: 'CREATE_EVENT_COMPONENT_VISIBLE'
})
}

export function createInstitutionAction() {
dispatcher.dispatch({
type: 'CREATE_INSTITUTION_COMPONENT_VISIBLE'
})
}

export function eventListAction() {
dispatcher.dispatch({
type: 'EVENT_LIST_COMPONENT_VISIBLE'
});
axios.get(`https://solidarize-dev.herokuapp.com/events?offset=10&order=desc`)
.then(res => {
dispatcher.dispatch({
type: 'EVENT_LIST_DATA',
events: res.data
})
});
}

export function homeAction() {
dispatcher.dispatch({
type: 'HOME_COMPONENT_VISIBLE'
});
axios.get(`https://solidarize-dev.herokuapp.com/events/rank?offset=3&order=desc`)
.then(res => {
dispatcher.dispatch({
type: 'EVENT_LIST_DATA',
events: res.data
})
});
}

export function authAction(data) {
dispatcher.dispatch({
type: 'IS_AUTH',
facebookData: data
});
homeAction();
}
Binary file added src/image/facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/image/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 31 additions & 125 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
import registerServiceWorker from './registerServiceWorker';
import DefaultLayout from './views/layout/master'
import FooterLayout from './views/layout/footer'
Expand All @@ -11,9 +10,11 @@ import EventList from './views/eventList'
import IndexBody from './views/indexBody'
import EventDetailComponent from './views/eventDetail'
import CreateInstitutionComponent from './views/createInstituction'
import './views/layout/solidarize.css'
import './style/background.png'

import HeaderStore from './stores/HeaderStore'
import EventDetailsStore from './stores/EventDetailsStore'
import * as HeaderActions from './actions/HeaderActions'
const refreshReact = () => {
ReactDOM.render(<IndexComponent/>, document.getElementById('root'));
registerServiceWorker();
Expand All @@ -25,142 +26,47 @@ class IndexComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
indexBodyVisible: true,
sobreComponentVisible: false,
eventListComponentVisible: true,
createEventVisible: false,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'home',
events: []
header: HeaderStore.getAll(),
eventDetails: EventDetailsStore.getAll()
}
}

componentDidMount() {
this.fetchEventListByRank();
HeaderActions.homeAction();
}

fetchEventList() {
axios.get(`https://solidarize-dev.herokuapp.com/events?offset=10&order=desc`)
.then(res => {
this.setState({events: res.data});
refreshReact();
});
componentWillMount() {
HeaderStore.on('change', () => {
this.setState({
header: HeaderStore.getAll(),
eventDetails: EventDetailsStore.setDefaultEventDetails()
})
})

EventDetailsStore.on('change', () => {
this.setState({
header: HeaderStore.setHeaderToDefault(),
eventDetails: EventDetailsStore.getAll()
})
})
}

fetchEventListByRank() {
axios.get(`https://solidarize-dev.herokuapp.com/events/rank?offset=3&order=desc`)
.then(res => {
this.setState({events: res.data});
refreshReact();
});
}

fetchEventById(eventId) {
axios.get('https://solidarize-dev.herokuapp.com/event/' + eventId)
.then(res => {
this.setState({events: [res.data]});
refreshReact();
});
}

onClickEvenListHeader() {
this.setState({
indexBodyVisible: false,
sobreComponentVisible: false,
eventListComponentVisible: true,
createEventVisible: false,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'event'
});
this.fetchEventList();
}

onClickHomeHeader() {
this.setState({
indexBodyVisible: true,
sobreComponentVisible: false,
eventListComponentVisible: true,
createEventVisible: false,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'home'
});
this.fetchEventListByRank();
}

onClickSobreHeader() {
this.setState({
indexBodyVisible: false,
sobreComponentVisible: true,
eventListComponentVisible: false,
createEventVisible: false,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'sobre'
});
refreshReact();
}

onClickCreateEventHeader() {
this.setState({
indexBodyVisible: false,
sobreComponentVisible: false,
eventListComponentVisible: false,
createEventVisible: true,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'createEvent'
});
refreshReact();
}

onClickCreateInstitutionHeader() {
this.setState({
indexBodyVisible: false,
sobreComponentVisible: false,
eventListComponentVisible: false,
createEventVisible: false,
eventDetailVisible: false,
institutionComponentVisible: true,
active: 'createInstitution'
});
refreshReact();
}


onClickLeiaMais(eventId) {
this.setState({
indexBodyVisible: false,
sobreComponentVisible: false,
eventListComponentVisible: false,
createEventVisible: false,
eventDetailVisible: true,
institutionComponentVisible: true,
active: 'eventDetail'
});

this.fetchEventById(eventId);
}

render() {
return (
<DefaultLayout name={this.props.name}>
<HeaderLayout
active={this.state.active}
onClickEventList={this.onClickEvenListHeader.bind(this)}
onClickHome={this.onClickHomeHeader.bind(this)}
onClickSobre={this.onClickSobreHeader.bind(this)}
onClickCreateEvent={this.onClickCreateEventHeader.bind(this)}
onClickCreateInstitution={this.onClickCreateInstitutionHeader.bind(this)}/>
{this.state.indexBodyVisible ? <IndexBody/> : null}
{this.state.eventListComponentVisible ?
<EventList events={this.state.events} onClickLeiaMais={this.onClickLeiaMais.bind(this)}/> : null}
{this.state.sobreComponentVisible ? <SobreComponent/> : null}
{this.state.createEventVisible ? <CreateEventComponent/> : null}
{this.state.eventDetailVisible ? <EventDetailComponent events={this.state.events}/> : null}
{this.state.institutionComponentVisible ? <CreateInstitutionComponent/> : null}
name={this.state.header.user.name}
auth={this.state.header.auth}
active={this.state.header.active}/>
{this.state.header.indexBodyVisible ? <IndexBody/> : null}
{this.state.header.eventListComponentVisible ?
<EventList events={this.state.header.events}/> : null}
{this.state.header.sobreComponentVisible ? <SobreComponent/> : null}
{this.state.header.createEventVisible ? <CreateEventComponent/> : null}
{this.state.eventDetails.eventDetailVisible ?
<EventDetailComponent events={this.state.eventDetails.events}/> : null}
{this.state.header.institutionComponentVisible ? <CreateInstitutionComponent/> : null}
<FooterLayout/>
</DefaultLayout>
)
Expand Down
50 changes: 50 additions & 0 deletions src/stores/CreateEventStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {EventEmitter} from 'events';
import dispatcher from '../Dispatcher';

class CreateEventStore extends EventEmitter {

constructor() {
super()
this.event = {
loading: false,
success: false
};
}

getAll() {
return this.event;
}

setDefaultState() {
this.event.success = false;
this.event.loading = false;

return this.event;
}

handleAction(action) {
switch (action.type) {
case 'CREATE_EVENT' : {
this.event.loading = true;
this.emit('change');
break;
}
case 'CREATE_EVENT_SUCCESS' : {
this.event.loading = false;
this.event.success = true;
this.emit('change');
break;
}
case 'CREATE_EVENT_SUCCESS_CONFIRM' : {
this.setDefaultState();
this.emit('change');
break;
}
}
}
}

const createEventStore = new CreateEventStore();
dispatcher.register(createEventStore.handleAction.bind(createEventStore));

export default createEventStore;
Loading