Commit 23addb05 authored by Theo Gjini's avatar Theo Gjini

Creating widget route and WidgeEventsContainer

parent 459ed0da
CALIGRAM_API_URL=http://api.caligram.local
CALIGRAM_API_KEY=Your client key!!!
CALIGRAM_API_SECRET=Your client secret!!!
CALENDAR_ID=1
......@@ -2,5 +2,7 @@ import { CaligramReact } from 'caligram-react';
import { Link } from 'react-router';
CaligramReact.config({
// This configuration object will be passed to caligram-react.
// See https://gitlab.com/territoires/caligram-react/blob/master/src/config.js
linkComponent: Link,
});
......@@ -38,16 +38,21 @@ export default class App extends Component {
phrases,
});
const homeRoute = routes.find((r) => r.id === 'index' && r.locale === locale);
const widget = location.pathname.slice(0, 7) === '/widget';
const routeIdToFind = widget ? 'widget' : 'index';
const homeRoute = routes.find((r) => r.id === routeIdToFind && r.locale === locale);
const homePath = homeRoute ? homeRoute.path : '/';
// eslint-disable-next-line no-console
console.log('widget', location.pathname);
return (
<div className="App">
<Header homePath={homePath} locale={locale} polyglot={polyglot}
{!widget && (<Header homePath={homePath} locale={locale} polyglot={polyglot}
query={location.query}
translations={translations.filter((t) => t.locale !== locale)}/>
translations={translations.filter((t) => t.locale !== locale)} />)}
{React.cloneElement(children, { setPageTitle })}
<Footer />
{!widget && (<Footer />)}
</div>
);
}
......
......@@ -38,7 +38,7 @@ module.exports = Object.assign({
id: 'your-google-analytics-id',
},
googleMaps: {
apiKey: 'AIzaSyC7w1RIpIiVl_YToZ7yTv8LrYQZS1wuKKA',
apiKey: 'your-google-maps-api-key',
},
googleTagManager: {
id: null,
......
import React, { Component } from 'react';
import BodyClassName from 'react-body-classname';
import { EventListContainer } from '.';
import {
index as eventIndex,
selectRange,
isNewQuery,
setMapView,
setRecurrences,
} from 'redux/modules/events';
import { setLocale, setTranslations } from 'redux/modules/ui';
import connectData from 'helpers/connectData';
import moment from 'moment';
import { routes } from '../routes';
function fetchData(getState, dispatch, location) {
const promises = [];
const state = getState();
const localRoutes = routes.filter((r) => r.id === 'widget');
promises.push(dispatch(setTranslations(localRoutes)));
const currentRoute = localRoutes.find((r) => r.path === location.pathname);
promises.push(dispatch(setLocale(currentRoute.locale)));
const query = {
lang: currentRoute.locale,
...location.query,
};
if (query.range) {
const range = query.range.split(',').map((time) => { return moment(time); });
if (range.length) {
const start = range[0] ? range[0].format('YYYY-MM-DD HH:mm:ss') : null;
const end = range[1] ? range[1].format('YYYY-MM-DD HH:mm:ss') : null;
promises.push(dispatch(selectRange({ start: start, end: end })));
}
} else {
promises.push(dispatch(selectRange({ start: null, end: null })));
}
if (query.recurrences) {
promises.push(dispatch(setRecurrences(query.recurrences === 'true')));
} else {
query.recurrences = state.events.recurrences;
}
if (query.mapView) {
promises.push(dispatch(setMapView(query.mapView === 'true')));
} else {
query.mapView = state.events.mapView;
}
query.order = 'start_date';
// force reload events with back and next browser buttons
if (query.mapView === 'false' || !query.mapView) {
if (isNewQuery(getState(), query)) {
promises.push(dispatch(eventIndex(query)));
}
}
return Promise.all(promises);
}
@connectData(fetchData)
export default class WidgetEventsContainer extends Component {
render() {
return (
<BodyClassName className="events">
<EventListContainer />
</BodyClassName>
);
}
}
// enlever les filtres qui s'affichent;
......@@ -9,6 +9,7 @@ export EventsContainer from './EventsContainer';
export EventsMapContainer from './EventsMapContainer';
export FiltersContainer from './FiltersContainer';
export HomeContainer from './HomeContainer';
export WidgetEventsContainer from './WidgetEventsContainer';
export OrganizationsContainer from './OrganizationsContainer';
export RecurrencesButtonContainer from './RecurrencesButtonContainer';
export SearchBarContainer from './SearchBarContainer';
......
......@@ -7,6 +7,7 @@ import {
EventPageContainer,
EventsContainer,
HomeContainer,
WidgetEventsContainer,
OrganizationsContainer,
TagsContainer,
TypesContainer,
......@@ -14,6 +15,7 @@ import {
} from 'containers';
const { fr: baseFr, en: baseEn } = config.app.i18n.basePaths;
export const routes = [
{
id: 'index',
......@@ -53,6 +55,18 @@ export const routes = [
match: /\/events\//,
component: EventPageContainer,
},
{
id: 'widget',
locale: 'fr',
path: baseFr + '/widget',
component: WidgetEventsContainer,
},
{
id: 'widget',
locale: 'en',
path: baseEn + '/widget',
component: WidgetEventsContainer,
},
{
id: 'about',
locale: 'fr',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment