Skip to content

Commit

Permalink
Fix more eslints and change file names
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeG committed Sep 27, 2018
1 parent 6f44852 commit b883fd8
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 68 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
setEvents, createEvent, updateEvent, deleteEvent,
DELETE_EVENT, CREATE_EVENT, UPDATE_EVENT, SET_EVENTS
} from './eventsActions';
} from './events';

describe('events Actions', () => {
let event, events, expectDefault;
Expand Down
4 changes: 2 additions & 2 deletions eventol/front/src/components/TitleList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class TitleList extends React.Component {
}
return {
event_slug, title, attendees, overview, backdrop, place, tags,
key: event_slug, url: `/events/${event_slug}/`
key: event_slug, url: `/events/${event_slug}/` //TODO: move to utils
};
}

Expand All @@ -62,7 +62,7 @@ export default class TitleList extends React.Component {
itemsData = results.map(this.parseItem);
}
if (!itemsData || itemsData.length === 0) {
if (!this.props.hasOwnProperty('showEmpty') || !this.props.showEmpty) return null;
if (!this.props.hasOwnProperty('showEmpty') || !this.props.showEmpty) return null; //TODO: move to HOC
const emptyItem = {
key: 'not_found',
title: gettext('Event not found'),
Expand Down
8 changes: 4 additions & 4 deletions eventol/front/src/containers/EventHome/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class EventHome extends React.Component {
const {tagSlug} = this.props;
const {searchTerm} = this.state;
if (searchTerm !== '') {
const searchUrl = `?search=${searchTerm}&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}`;
const searchUrl = `?search=${searchTerm}&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}`; // TODO: move to utils
this.setState({searchUrl, searched: true});
}
}
Expand All @@ -49,17 +49,17 @@ export default class EventHome extends React.Component {
<TitleList
id='my_events'
title={gettext('My Events')}
url={`?my_events=true&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}`}
url={`?my_events=true&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='next'
title={gettext('Upcoming Events')}
url={`?registration_is_open=true&ordering=last_date&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}`}
url={`?registration_is_open=true&ordering=last_date&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='finished'
title={gettext('Finished Events')}
url={`?registration_is_open=false&ordering=-attendees_count&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}`}
url={`?registration_is_open=false&ordering=-attendees_count&tags__slug=${tagSlug}&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
</div>
);
Expand Down
19 changes: 10 additions & 9 deletions eventol/front/src/containers/Home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import Hero from '../../components/Hero';
import React from 'react';

import Header from '../../components/Header';
import Hero from '../../components/Hero';
import Search from '../../components/Search';
import TitleList from '../../components/TitleList';
import {HOME_REQUIRED_FIELDS} from '../../utils/constants';
Expand All @@ -27,7 +28,7 @@ export default class Home extends React.Component {
handleOnEnter = () => {
const {searchTerm} = this.state;
if (searchTerm !== '') {
const searchUrl = `?search=${searchTerm}&fields=${HOME_REQUIRED_FIELDS}`;
const searchUrl = `?search=${searchTerm}&fields=${HOME_REQUIRED_FIELDS}`; /*TODO: move to utils*/
this.setState({searchUrl, searched: true});
}
}
Expand All @@ -47,32 +48,32 @@ export default class Home extends React.Component {
<TitleList
id='my_events'
title={gettext('My Events')}
url={`?my_events=true&fields=${HOME_REQUIRED_FIELDS}`}
url={`?my_events=true&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='recent'
title={gettext('Recent Events')}
url={`?ordering=-created_at&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}`}
url={`?ordering=-created_at&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='featured'
title={gettext('Featured Events')}
url={`?ordering=-attendees_count&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}`}
url={`?ordering=-attendees_count&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='next'
title={gettext('Upcoming Events')}
url={`?registration_is_open=true&ordering=last_date&fields=${HOME_REQUIRED_FIELDS}`}
url={`?registration_is_open=true&ordering=last_date&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='schedule_confirmed'
title={gettext('Events with Confirmed Schedule')}
url={`?schedule_confirmed=true&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}`}
url={`?schedule_confirmed=true&registration_is_open=true&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
<TitleList
id='finished'
title={gettext('Finished Events')}
url={`?registration_is_open=false&ordering=-attendees_count&fields=${HOME_REQUIRED_FIELDS}`}
url={`?registration_is_open=false&ordering=-attendees_count&fields=${HOME_REQUIRED_FIELDS}` /*TODO: move to utils*/}
/>
</div>
);
Expand Down
51 changes: 21 additions & 30 deletions eventol/front/src/reducers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,34 @@ import {
UPDATE_EVENT,
DELETE_EVENT,
CREATE_EVENT
} from '../actions/eventsActions';
} from '../actions/events';
import {getEvent} from '../utils/events';

const initState = {
events: []
};

const updateEvent = (state, {pk, data}) => {
return {
...state,
events: [...state.events].map(event => {
if (event.pk === pk) {
return getEvent(pk, data);
}
return event;
})
};
};
const setEvents = (state, events) => ({...state, events});
const createEvent = (state, {pk, data}) => ({...state, events: [...state.events, getEvent(pk, data)]});
const deleteEvent = (state, {pk}) => ({...state, events: [...state.events].filter(event => event.pk !== pk)});

export default (state = initState, action) => {
const {events} = state;
switch (action.type) {
case SET_EVENTS:
return {
...state,
events: action.events
};
case UPDATE_EVENT:
return {
...state,
events: events.map(event => {
if (event.pk === action.event.pk) {
return getEvent(action.event.pk, action.event.data);
}
return event;
})
};
case CREATE_EVENT:
return {
...state,
events: [...events, getEvent(action.event.pk, action.event.data)]
};
case DELETE_EVENT:
return {
...state,
events: events.filter(event => event.pk !== action.event.pk)
};
default:
return state;
case SET_EVENTS: return setEvents(state, action.events);
case UPDATE_EVENT: return updateEvent(state, action.event);
case CREATE_EVENT: return createEvent(state, action.event);
case DELETE_EVENT: return deleteEvent(state, action.event);
default: return state;
}
};
//TODO: move case to functions
22 changes: 13 additions & 9 deletions eventol/front/src/reducers/events.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import eventsReducer from './events';
import {
SET_EVENTS, UPDATE_EVENT,
CREATE_EVENT, DELETE_EVENT
} from '../actions/events';

const initState = {
events: []
Expand Down Expand Up @@ -43,21 +47,21 @@ describe('events Reducer', () => {
expect(result).toEqual(initState);
});

describe('when dispatch SET_EVENTS', () => {
describe(`when dispatch ${SET_EVENTS}`, () => {
test('when set events return correct events list', () => {
const action = {
type: 'SET_EVENTS',
type: SET_EVENTS,
events
};
const result = eventsReducer(initState, action);
expect(result.events).toEqual(events);
});
});

describe('when dispatch UPDATE_EVENT', () => {
describe(`when dispatch ${UPDATE_EVENT}`, () => {
test('when update event update original event', () => {
const action = {
type: 'UPDATE_EVENT',
type: UPDATE_EVENT,
event: {
...event,
data: {name: 'new name'}
Expand All @@ -70,7 +74,7 @@ describe('events Reducer', () => {

test('when update event update only original event', () => {
const action = {
type: 'UPDATE_EVENT',
type: UPDATE_EVENT,
event: {
...event,
data: {name: 'new name'}
Expand All @@ -82,21 +86,21 @@ describe('events Reducer', () => {
});
});

describe('when dispatch DELETE_EVENT', () => {
describe(`when dispatch ${DELETE_EVENT}`, () => {
test('when delete event return empty events list', () => {
const action = {
type: 'DELETE_EVENT',
type: DELETE_EVENT,
event
};
const result = eventsReducer({events}, action);
expect(result.events).toEqual([]);
});
});

describe('when dispatch CREATE_EVENT', () => {
describe(`when dispatch ${CREATE_EVENT}`, () => {
test('when create event return correct events list', () => {
const action = {
type: 'CREATE_EVENT',
type: CREATE_EVENT,
event
};
const createdEvent = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Events store', () => {
let store, event, events;

beforeEach(() => {
const get_store = require('./eventsStore').default;
const get_store = require('./events').default;
store = get_store();
event = {
model: 'events.event',
Expand Down
10 changes: 4 additions & 6 deletions eventol/front/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export const addQueryString = (url, query) => {
const queryKeys = query ? Object.keys(query) : [];
if (queryKeys.length > 0) {
const params = queryKeys.map(k => `${k}=${encodeURIComponent(query[k])}`);
url += `?${params.join('&')}`;
return url;
return `${url}?${params.join('&')}`;
}
return url;
};
Expand Down Expand Up @@ -42,9 +41,9 @@ export const getUrl = (url, queryString) => {
};

export const postUrl = (url, data, queryString) => {
url = addQueryString(url, queryString);
const newUrl = addQueryString(url, queryString);
return fetch(
url, {
newUrl, {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
Expand All @@ -54,6 +53,5 @@ export const postUrl = (url, data, queryString) => {
body: JSON.stringify(data || {}),
credentials: 'same-origin'
})
.then(res => res.json())
.catch(err => console.error(err));
.then(res => res.json());
};
4 changes: 2 additions & 2 deletions eventol/front/src/utils/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Api utils', () => {
it('should add a queryString', async () => {
await getUrl(url, {test: true, name: 'Peter'});
expect(global.fetch).toBeCalled();
expect(getLastCall()[0]).toBe(url + '?test=true&name=Peter');
expect(getLastCall()[0]).toBe(`${url}?test=true&name=Peter`);
});
});

Expand All @@ -51,7 +51,7 @@ describe('Api utils', () => {
it('should add a queryString', async () => {
await postUrl(url, data, {test: true, name: 'Peter'});
expect(global.fetch).toBeCalled();
expect(getLastCall()[0]).toBe(url + '?test=true&name=Peter');
expect(getLastCall()[0]).toBe(`${url}?test=true&name=Peter`);
});
});
});
6 changes: 2 additions & 4 deletions eventol/front/src/utils/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export function getEvent(pk, fields){
return {pk, fields};
}
//TODO: move to arrow functions

export const getEvent = (pk, fields) => ({pk, fields});

0 comments on commit b883fd8

Please sign in to comment.