-
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.
# Conflicts: # src/client/src/app/+state/player-events/actions/register-for-event.action.ts # src/client/src/app/+state/player-events/player-events.reducer.ts # src/client/src/app/components/player-events/player-event-details/player-event-details.component.html # src/client/src/app/components/player-events/player-event-details/player-event-details.component.ts
- Loading branch information
Showing
13 changed files
with
251 additions
and
111 deletions.
There are no files selected for viewing
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
60 changes: 0 additions & 60 deletions
60
src/client/src/app/+state/player-events/actions/register-for-event.action.ts
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
src/client/src/app/+state/player-events/actions/update-event-registration.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,100 @@ | ||
import { inject } from '@angular/core'; | ||
import { concatLatestFrom } from '@ngrx/effects'; | ||
import { on, Store } from '@ngrx/store'; | ||
import { produce } from 'immer'; | ||
import { switchMap } from 'rxjs'; | ||
|
||
import { ApiEventTimeslotRegistration } from '../../../api/models'; | ||
import { EventsService } from '../../../api/services'; | ||
import { PlayerEvent } from '../../../models/parsed-models'; | ||
import { createHttpAction, handleHttpAction, onHttpAction, toHttpAction } from '../../action-state'; | ||
import { createFunctionalEffect } from '../../functional-effect'; | ||
import { Effects, Reducers } from '../../utils'; | ||
import { PLAYER_EVENTS_ACTION_SCOPE } from '../consts'; | ||
import { selectPlayerEvent, selectPlayerEventsActionState } from '../player-events.selectors'; | ||
import { PlayerEventsFeatureState, playerEventEntityAdapter } from '../player-events.state'; | ||
|
||
export const updateEventRegistrationAction = createHttpAction<{ | ||
eventId: string; | ||
timeslotId: string; | ||
isRegistered?: boolean; | ||
fallbackTimeslotId?: string | null; | ||
}>()(PLAYER_EVENTS_ACTION_SCOPE, 'Update Event Registration'); | ||
|
||
export const updateEventRegistrationReducers: Reducers<PlayerEventsFeatureState> = [ | ||
on(updateEventRegistrationAction.success, (state, { props }) => | ||
playerEventEntityAdapter.mapOne( | ||
{ | ||
id: props.eventId, | ||
map: produce(draft => { | ||
const timeslot = draft.timeslots.find(t => t.id === props.timeslotId); | ||
if (timeslot) { | ||
if (props.isRegistered !== undefined) { | ||
timeslot.isRegistered = props.isRegistered; | ||
} | ||
if (props.fallbackTimeslotId !== undefined) { | ||
timeslot.chosenFallbackTimeslotId = props.fallbackTimeslotId; | ||
} | ||
} | ||
}), | ||
}, | ||
state | ||
) | ||
), | ||
handleHttpAction('register', updateEventRegistrationAction), | ||
]; | ||
|
||
export const updateEventRegistrationEffects: Effects = { | ||
updateEventRegistration$: createFunctionalEffect.dispatching( | ||
(store = inject(Store), api = inject(EventsService)) => | ||
onHttpAction(updateEventRegistrationAction, selectPlayerEventsActionState('register')).pipe( | ||
concatLatestFrom(({ props }) => store.select(selectPlayerEvent(props.eventId))), | ||
switchMap(([{ props }, currentEvent]) => | ||
toHttpAction( | ||
updatePlayerEventRegistrations(api, props, currentEvent), | ||
updateEventRegistrationAction, | ||
props | ||
) | ||
) | ||
) | ||
), | ||
}; | ||
|
||
async function updatePlayerEventRegistrations( | ||
api: EventsService, | ||
props: ReturnType<typeof updateEventRegistrationAction>['props'], | ||
currentTimeslot: PlayerEvent | undefined | ||
) { | ||
if (!currentTimeslot) return updateEventRegistrationAction.error(props, 'Event not found'); | ||
|
||
let registrations: ApiEventTimeslotRegistration[] = currentTimeslot.timeslots | ||
.filter(t => t.isRegistered) | ||
.map(t => ({ | ||
timeslotId: t.id, | ||
fallbackTimeslotId: t.chosenFallbackTimeslotId, | ||
})); | ||
|
||
let timeslotRegistration = registrations.find(r => r.timeslotId === props.timeslotId); | ||
if (props.isRegistered === true && !timeslotRegistration) { | ||
timeslotRegistration = { | ||
timeslotId: props.timeslotId, | ||
fallbackTimeslotId: props.fallbackTimeslotId, | ||
}; | ||
registrations.push(timeslotRegistration); | ||
} else if (props.isRegistered === false && timeslotRegistration) { | ||
registrations = registrations.filter(r => r.timeslotId !== props.timeslotId); | ||
timeslotRegistration = undefined; | ||
} | ||
|
||
if (timeslotRegistration && props.fallbackTimeslotId !== undefined) { | ||
timeslotRegistration.fallbackTimeslotId = props.fallbackTimeslotId; | ||
} | ||
|
||
const response = await api.updatePlayerEventRegistrations({ | ||
eventId: props.eventId, | ||
body: { timeslotRegistrations: registrations }, | ||
}); | ||
return response.ok | ||
? updateEventRegistrationAction.success(props, undefined) | ||
: updateEventRegistrationAction.error(props, response); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/client/src/app/+state/player-events/player-events.actions.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { loadPlayerEventAction } from './actions/load-player-event.action'; | ||
export { loadPlayerEventsAction } from './actions/load-player-events.action'; | ||
export { registerForEventAction } from './actions/register-for-event.action'; | ||
export { updateEventRegistrationAction } from './actions/update-event-registration.action'; |
4 changes: 2 additions & 2 deletions
4
src/client/src/app/+state/player-events/player-events.effects.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { loadPlayerEventEffects } from './actions/load-player-event.action'; | ||
import { loadPlayerEventsEffects } from './actions/load-player-events.action'; | ||
import { registerForEventEffects } from './actions/register-for-event.action'; | ||
import { updateEventRegistrationEffects } from './actions/update-event-registration.action'; | ||
import { Effects } from '../utils'; | ||
|
||
export const PlayerEventsFeatureEffects: Effects[] = [ | ||
loadPlayerEventsEffects, | ||
loadPlayerEventEffects, | ||
registerForEventEffects, | ||
updateEventRegistrationEffects, | ||
]; |
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
76 changes: 76 additions & 0 deletions
76
src/client/src/app/components/+common/fading-message.component.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,76 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
effect, | ||
HostBinding, | ||
input, | ||
OnDestroy, | ||
signal, | ||
untracked, | ||
} from '@angular/core'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'app-fading-message', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: `<ng-content></ng-content>`, | ||
styles: ` | ||
:host { | ||
display: block; | ||
opacity: 0; | ||
transition-property: opacity; | ||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
transition-duration: var(--fm-fade-out-duration); | ||
&.show { | ||
opacity: 1; | ||
transition-duration: var(--fm-fade-in-duration); | ||
} | ||
} | ||
`, | ||
}) | ||
export class FadingMessageComponent implements OnDestroy { | ||
private _lastTimeout?: ReturnType<typeof setTimeout>; | ||
private readonly _isShowing = signal(false); | ||
|
||
public readonly fadeInDuration = input<number>(150); | ||
public readonly fadeOutDuration = input<number>(3000); | ||
public readonly showTrigger = input<boolean | null | undefined>(); | ||
|
||
@HostBinding('style.--fm-fade-in-duration') | ||
protected get fadeInDurationValue() { | ||
return `${this.fadeInDuration()}ms`; | ||
} | ||
|
||
@HostBinding('style.--fm-fade-out-duration') | ||
protected get fadeOutDurationValue() { | ||
return `${this.fadeOutDuration()}ms`; | ||
} | ||
|
||
@HostBinding('class.show') | ||
protected get hasShowClass() { | ||
return this._isShowing(); | ||
} | ||
|
||
constructor() { | ||
effect( | ||
() => { | ||
if (this.showTrigger()) { | ||
untracked(() => this.show()); | ||
} | ||
}, | ||
{ allowSignalWrites: true } | ||
); | ||
} | ||
|
||
public show() { | ||
if (this._isShowing()) return; | ||
this._isShowing.set(true); | ||
|
||
this._lastTimeout = setTimeout(() => this._isShowing.set(false), this.fadeInDuration()); | ||
} | ||
|
||
public ngOnDestroy(): void { | ||
clearTimeout(this._lastTimeout); | ||
} | ||
} |
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.