-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to edit event groups (#151)
Closes: #24
- Loading branch information
Showing
31 changed files
with
3,019 additions
and
60 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/client/src/app/+state/events/actions/set-editing-event-instances.action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { inject } from '@angular/core'; | ||
import { on } from '@ngrx/store'; | ||
import { produce } from 'immer'; | ||
import { switchMap } from 'rxjs'; | ||
|
||
import { EventAdministrationService } from '../../../api/services'; | ||
import { AuthService } from '../../../services/auth.service'; | ||
import { createHttpAction, handleHttpAction, onHttpAction } from '../../action-state'; | ||
import { createFunctionalEffect } from '../../functional-effect'; | ||
import { Effects, Reducers } from '../../utils'; | ||
import { EVENTS_ACTION_SCOPE } from '../consts'; | ||
import { eventEntityAdapter, EventsFeatureState } from '../events.state'; | ||
|
||
export const setEditingEventInstancesAction = createHttpAction< | ||
{ eventId: string; isEditing: boolean }, | ||
{ userIdEditingInstances: string | null } | ||
>()(EVENTS_ACTION_SCOPE, 'Set Editing Event Instances'); | ||
|
||
export const setEditingEventInstancesReducers: Reducers<EventsFeatureState> = [ | ||
on(setEditingEventInstancesAction.success, (state, { props, response }) => | ||
eventEntityAdapter.mapOne( | ||
{ | ||
id: props.eventId, | ||
map: produce(draft => { | ||
draft.userIdEditingInstances = response.userIdEditingInstances; | ||
}), | ||
}, | ||
state | ||
) | ||
), | ||
handleHttpAction('setInstancesEditing', setEditingEventInstancesAction), | ||
]; | ||
|
||
export const setEditingEventInstancesEffects: Effects = { | ||
setEditingEventInstances$: createFunctionalEffect.dispatching( | ||
(api = inject(EventAdministrationService), authService = inject(AuthService)) => | ||
onHttpAction(setEditingEventInstancesAction).pipe( | ||
switchMap(({ props }) => setEditingEventInstances(api, props, authService)) | ||
) | ||
), | ||
}; | ||
|
||
async function setEditingEventInstances( | ||
api: EventAdministrationService, | ||
props: ReturnType<typeof setEditingEventInstancesAction>['props'], | ||
authService: AuthService | ||
) { | ||
const response = await api.setEventInstancesEditing({ | ||
eventId: props.eventId, | ||
body: { isEditing: props.isEditing }, | ||
}); | ||
return response.ok | ||
? setEditingEventInstancesAction.success(props, { | ||
userIdEditingInstances: props.isEditing ? (authService.user()?.id ?? null) : null, | ||
}) | ||
: setEditingEventInstancesAction.error(props, response); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/client/src/app/+state/events/actions/set-event-instances.action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { inject } from '@angular/core'; | ||
import { on } from '@ngrx/store'; | ||
import { produce, castDraft } from 'immer'; | ||
import { switchMap } from 'rxjs'; | ||
|
||
import { ApiEventTimeslotInstances } from '../../../api/models'; | ||
import { EventAdministrationService } from '../../../api/services'; | ||
import { createHttpAction, handleHttpAction, onHttpAction, toHttpAction } from '../../action-state'; | ||
import { createFunctionalEffect } from '../../functional-effect'; | ||
import { Effects, Reducers } from '../../utils'; | ||
import { EVENTS_ACTION_SCOPE } from '../consts'; | ||
import { eventEntityAdapter, EventsFeatureState } from '../events.state'; | ||
|
||
export const setEventInstancesAction = createHttpAction<{ | ||
eventId: string; | ||
instances: ApiEventTimeslotInstances[]; | ||
}>()(EVENTS_ACTION_SCOPE, 'Set Event Instances'); | ||
|
||
export const setEventInstancesReducers: Reducers<EventsFeatureState> = [ | ||
on(setEventInstancesAction.success, (state, { props }) => | ||
eventEntityAdapter.mapOne( | ||
{ | ||
id: props.eventId, | ||
map: produce(draft => { | ||
for (const timeslot of draft.timeslots) { | ||
timeslot.instances = castDraft( | ||
props.instances.find(x => x.timeslotId === timeslot.id)?.instances || [] | ||
); | ||
} | ||
}), | ||
}, | ||
state | ||
) | ||
), | ||
handleHttpAction('setInstances', setEventInstancesAction), | ||
]; | ||
|
||
export const setEventInstancesEffects: Effects = { | ||
setEventInstances$: createFunctionalEffect.dispatching( | ||
(api = inject(EventAdministrationService)) => | ||
onHttpAction(setEventInstancesAction).pipe( | ||
switchMap(({ props }) => | ||
toHttpAction(setEventInstances(api, props), setEventInstancesAction, props) | ||
) | ||
) | ||
), | ||
}; | ||
|
||
async function setEventInstances( | ||
api: EventAdministrationService, | ||
props: ReturnType<typeof setEventInstancesAction>['props'] | ||
) { | ||
const response = await api.putEventInstances({ | ||
eventId: props.eventId, | ||
body: { instances: props.instances }, | ||
}); | ||
return response.ok | ||
? setEventInstancesAction.success(props, undefined) | ||
: setEventInstancesAction.error(props, response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
export { addEventPreconfigAction } from './actions/add-event-preconfig.action'; | ||
export { addEventTimeslotAction } from './actions/add-event-timeslot.action'; | ||
export { addEventAction } from './actions/add-event.action'; | ||
export { updateEventAction } from './actions/update-event.action'; | ||
export { eventTimeslotRegistrationChangedAction } from './actions/event-timeslot-registration-changed.action'; | ||
export { addPlayerToEventPreconfigurationAction } from './actions/add-player-to-preconfig.action'; | ||
export { buildEventInstancesAction } from './actions/build-event-instances.action'; | ||
export { eventTimeslotRegistrationChangedAction } from './actions/event-timeslot-registration-changed.action'; | ||
export { loadEventAction } from './actions/load-event.action'; | ||
export { loadEventsAction } from './actions/load-events.action'; | ||
export { removeEventAction } from './actions/remove-event.action'; | ||
export { removeEventPreconfigAction } from './actions/remove-event-preconfig.action'; | ||
export { removeEventTimeslotAction } from './actions/remove-event-timeslot.action'; | ||
export { removeEventAction } from './actions/remove-event.action'; | ||
export { removePlayerFromPreconfigAction } from './actions/remove-player-from-preconfig.action'; | ||
export { resetEventsActionStateAction } from './actions/reset-events-action-state.action'; | ||
export { setEditingEventInstancesAction } from './actions/set-editing-event-instances.action'; | ||
export { setEventInstancesAction } from './actions/set-event-instances.action'; | ||
export { startEventAction } from './actions/start-event.action'; | ||
export { updateEventTimeslotAction } from './actions/update-event-timeslot.action'; | ||
export { updateEventAction } from './actions/update-event.action'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.