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
4 changes: 3 additions & 1 deletion client/components/user-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import moment from 'moment-timezone'
import AddToCalendar from './calendar-add'
import {Calendar, momentLocalizer} from 'react-big-calendar'
import 'react-big-calendar/lib/css/react-big-calendar.css'
// import 'react-big-calendar/lib/sass/styles';
// import 'react-big-calendar/lib/addons/dragAndDrop/styles';
// a localizer for BigCalendar
const localizer = momentLocalizer(moment)
import {loadEvents} from '../store'
Expand Down Expand Up @@ -40,7 +42,7 @@ export class UserHome extends Component {
<h3>Welcome, {firstName}!</h3>
{events && (
<Calendar
showMultiDayTimes
//showMultiDayTimes
localizer={localizer}
startAccessor="start"
endAccessor="end"
Expand Down
26 changes: 26 additions & 0 deletions client/store/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import axios from 'axios'
*/
const INSERT_EVENT = 'INSERT_EVENT'
const GET_EVENTS = 'GET_EVENTS'
const DELETE_EVENT = 'DELETE_EVENT'
const UPDATE_EVENT = 'UPDATE_EVENT'
/**
* INITIAL STATE
*/
Expand All @@ -15,6 +17,8 @@ const defaultEvents = []
*/
const insertEvent = (event) => ({type: INSERT_EVENT, event})
const getEvents = (events) => ({type: GET_EVENTS, events})
const deleteEvent = (id) => ({type: DELETE_EVENT, id})
const updateEvent = (id, event) => ({type: UPDATE_EVENT, id, event})
/**
* THUNK CREATORS
*/
Expand All @@ -39,6 +43,22 @@ export const loadEvents = () => async (dispatch) => {
console.log(e)
}
}
export const removeEvent = (id) => async (dispatch) => {
try {
await axios.delete('/auth/event', id)
dispatch(deleteEvent(id || defaultEvents))
} catch (e) {
console.log(e)
}
}
export const putEvent = (event) => async (dispatch) => {
try {
const res = await axios.put('/auth/event', event)
dispatch(updateEvent(res.data || defaultEvents))
} catch (e) {
console.log(e)
}
}

/**
* REDUCER
Expand All @@ -49,6 +69,12 @@ export default function (state = defaultEvents, action) {
return action.events
case INSERT_EVENT:
return [...state, action.event]
case DELETE_EVENT:
return state.filter((event) => event.id !== action.id)
case UPDATE_EVENT:
return state.forEach((event) => {
if (event.id === action.id) event = action.event
})
default:
return state
}
Expand Down
26 changes: 26 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Update with your config settings.
const pkg = require('./package.json')
const path = require('path')
const databaseName = pkg.name + (process.env.NODE_ENV === 'test' ? '-test' : '')

module.exports = {
development: {
client: 'pg',
connection: `postgres://localhost:5432/${databaseName}`,
migrations: {
directory: path.join(__dirname, './server/db/models/migrations'),
extention: 'sql',
},
},
production: {
client: 'pg',
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10,
},
migrations: {
directory: path.join(__dirname, './server/db/models/migrations'),
},
},
}
Loading