-
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: handle real time events for events
Refs: #26
- Loading branch information
Showing
49 changed files
with
490 additions
and
294 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/client/src/app/+state/events/actions/event-timeslot-registration-changed.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,34 @@ | ||
import { createAction, on, props } from '@ngrx/store'; | ||
import { produce } from 'immer'; | ||
|
||
import { PlayerEventTimeslotRegistrationChanged } from '../../../models/realtime-events'; | ||
import { Reducers } from '../../utils'; | ||
import { EVENTS_ACTION_SCOPE } from '../consts'; | ||
import { eventEntityAdapter, EventsFeatureState } from '../events.state'; | ||
|
||
export const eventTimeslotRegistrationChangedAction = createAction( | ||
`[${EVENTS_ACTION_SCOPE}] Event Timeslot Registration Changed`, | ||
props<PlayerEventTimeslotRegistrationChanged>() | ||
); | ||
|
||
export const eventTimeslotRegistrationChangedReducers: Reducers<EventsFeatureState> = [ | ||
on(eventTimeslotRegistrationChangedAction, (state, event) => | ||
eventEntityAdapter.mapOne( | ||
{ | ||
id: event.eventId, | ||
map: produce(draft => { | ||
const timeslot = draft.timeslots.find(t => t.id === event.eventTimeslotId); | ||
if (!timeslot) return; | ||
if (event.isRegistered) { | ||
if (!timeslot.playerIds.includes(event.userId)) { | ||
timeslot.playerIds.push(event.userId); | ||
} | ||
} else { | ||
timeslot.playerIds = timeslot.playerIds.filter(p => p !== event.userId); | ||
} | ||
}), | ||
}, | ||
state | ||
) | ||
), | ||
]; |
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
21 changes: 21 additions & 0 deletions
21
src/client/src/app/+state/events/actions/reset-events-action-state.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,21 @@ | ||
import { createAction, on, props } from '@ngrx/store'; | ||
import { produce } from 'immer'; | ||
|
||
import { initialActionState } from '../../action-state'; | ||
import { Reducers } from '../../utils'; | ||
import { EVENTS_ACTION_SCOPE } from '../consts'; | ||
import { EventsFeatureState } from '../events.state'; | ||
|
||
export const resetEventsActionStateAction = createAction( | ||
`[${EVENTS_ACTION_SCOPE}] Reset Action State`, | ||
props<{ scope: keyof EventsFeatureState['actionStates'] }>() | ||
); | ||
|
||
export const resetEventsActionStateReducers: Reducers<EventsFeatureState> = [ | ||
on( | ||
resetEventsActionStateAction, | ||
produce((state, { scope }) => { | ||
state.actionStates[scope] = initialActionState; | ||
}) | ||
), | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DestroyRef, effect, Signal } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { Store } from '@ngrx/store'; | ||
import { filter } from 'rxjs'; | ||
|
||
import { loadEventsAction, loadEventAction } from './events.actions'; | ||
import { selectEventsActionState } from './events.selectors'; | ||
import { injectEx, OptionalInjector } from '../../utils/angular.utils'; | ||
|
||
export function keepEventsLoaded(options?: OptionalInjector) { | ||
const store = injectEx(Store, options); | ||
store.dispatch(loadEventsAction({ reload: false })); | ||
store | ||
.select(selectEventsActionState('load')) | ||
.pipe( | ||
filter(x => x.state === 'none'), | ||
takeUntilDestroyed(injectEx(DestroyRef, options)) | ||
) | ||
.subscribe(() => store.dispatch(loadEventsAction({ reload: true, silent: true }))); | ||
} | ||
|
||
export function keepEventLoaded(eventId: Signal<string>, options?: OptionalInjector) { | ||
const store = injectEx(Store, options); | ||
|
||
effect(() => store.dispatch(loadEventAction({ eventId: eventId(), reload: false })), { | ||
...options, | ||
allowSignalWrites: true, | ||
}); | ||
|
||
store | ||
.select(selectEventsActionState('loadOne')) | ||
.pipe( | ||
filter(x => x.state === 'none'), | ||
takeUntilDestroyed(injectEx(DestroyRef, options)) | ||
) | ||
.subscribe(() => | ||
store.dispatch(loadEventAction({ eventId: eventId(), reload: true, silent: true })) | ||
); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/client/src/app/+state/maps/actions/reset-maps-action-state.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,21 @@ | ||
import { createAction, on, props } from '@ngrx/store'; | ||
import { produce } from 'immer'; | ||
|
||
import { initialActionState } from '../../action-state'; | ||
import { Reducers } from '../../utils'; | ||
import { MAPS_ACTION_SCOPE } from '../consts'; | ||
import { MapsFeatureState } from '../maps.state'; | ||
|
||
export const resetMapsActionStateAction = createAction( | ||
`[${MAPS_ACTION_SCOPE}] Reset Action State`, | ||
props<{ scope: keyof MapsFeatureState['actionStates'] }>() | ||
); | ||
|
||
export const resetMapsActionStateReducers: Reducers<MapsFeatureState> = [ | ||
on( | ||
resetMapsActionStateAction, | ||
produce((state, { scope }) => { | ||
state.actionStates[scope] = initialActionState; | ||
}) | ||
), | ||
]; |
19 changes: 0 additions & 19 deletions
19
src/client/src/app/+state/maps/actions/reset-maps.action.ts
This file was deleted.
Oops, something went wrong.
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.