{"size": 2397, "ext": "js", "max_stars_repo_path": "src/component/Event/eventReducer.js", "max_stars_repo_name": "fire123456746/react-mindmap-master-1.ren", "max_stars_repo_stars_event_min_datetime": "2020-07-24T12:31:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T12:31:50.000Z", "max_issues_repo_path": "src/component/Event/eventReducer.js", "max_issues_repo_name": "fire123456746/react-mindmap-master-1.ren", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/component/Event/eventReducer.js", "max_forks_repo_name": "fire123456746/react-mindmap-master-1.ren", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5394736842, "max_line_length": 206, "alphanum_fraction": 0.5536086775}
import {
    createReducer
} from '../../util/reducerUtils';
import {
    CREATE_EVENT,
    UPDATE_EVENT,
    DELETE_EVENT
} from "./eventConstants";

const initialState = [{
        id: "1",
        title: "Trip to Tower of London",
        date: "2018-03-27",
        category: "culture",
        description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sollicitudin ligula eu leo tincidunt, quis scelerisque magna dapibus. Sed eget ipsum vel arcu vehicula ullamcorper.",
        city: "London, UK",
        venue: "Tower of London, St Katharine's & Wapping, London",
        hostedBy: "Bob",
        hostPhotoURL: "https://randomuser.me/api/portraits/men/20.jpg",
        attendees: [{
                id: "a",
                name: "Bob",
                photoURL: "https://randomuser.me/api/portraits/men/20.jpg",
            },
            {
                id: "b",
                name: "Tom",
                photoURL: "https://randomuser.me/api/portraits/men/22.jpg",
            },
        ],
    },
    {
        id: "2",
        title: "Trip to Punch and Judy Pub",
        date: "2018-03-28",
        category: "drinks",
        description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sollicitudin ligula eu leo tincidunt, quis scelerisque magna dapibus. Sed eget ipsum vel arcu vehicula ullamcorper.",
        city: "London, UK",
        venue: "Punch & Judy, Henrietta Street, London, UK",
        hostedBy: "Tom",
        hostPhotoURL: "https://randomuser.me/api/portraits/men/22.jpg",
        attendees: [{
                id: "b",
                name: "Tom",
                photoURL: "https://randomuser.me/api/portraits/men/22.jpg",
            },
            {
                id: "a",
                name: "Bob",
                photoURL: "https://randomuser.me/api/portraits/men/20.jpg",
            },
        ],
    },
];

const createEvent = (state, payload) => {
    return [...state, payload.event]
}

const updateEvent = (state, payload) => {
    return [
        ...state.filter(event => event.id !== payload.event.id), payload.event
    ]
}

const deleteEvent = (state, payload) => {
    return [
        ...state.filter(event => event.id !== payload.eventId)
    ]
}

export default createReducer(initialState, {
    [CREATE_EVENT]: createEvent,
    [UPDATE_EVENT]: updateEvent,
    [DELETE_EVENT]: deleteEvent
})