mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
fix(challenge29): challenge 29
This commit is contained in:
@@ -6,19 +6,19 @@ export type User = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Ticket = {
|
export interface BaseTicket {
|
||||||
id: number;
|
id: number;
|
||||||
description: string;
|
description: string;
|
||||||
assigneeId: number | null;
|
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
};
|
}
|
||||||
|
|
||||||
export type TicketUser = {
|
export interface Ticket extends BaseTicket {
|
||||||
id: number;
|
assigneeId: number | null;
|
||||||
description: string;
|
}
|
||||||
|
|
||||||
|
export interface TicketUser extends BaseTicket {
|
||||||
assignee: string;
|
assignee: string;
|
||||||
completed: boolean;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function randomDelay() {
|
function randomDelay() {
|
||||||
return Math.random() * 1000;
|
return Math.random() * 1000;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable, inject } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ComponentStore,
|
ComponentStore,
|
||||||
OnStateInit,
|
OnStateInit,
|
||||||
|
OnStoreInit,
|
||||||
tapResponse,
|
tapResponse,
|
||||||
} from '@ngrx/component-store';
|
} from '@ngrx/component-store';
|
||||||
import { pipe } from 'rxjs';
|
import { pipe } from 'rxjs';
|
||||||
@@ -27,7 +28,7 @@ const initialState: TicketState = {
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class TicketStore
|
export class TicketStore
|
||||||
extends ComponentStore<TicketState>
|
extends ComponentStore<TicketState>
|
||||||
implements OnStateInit
|
implements OnStoreInit, OnStateInit
|
||||||
{
|
{
|
||||||
readonly users$ = this.select((state) => state.users);
|
readonly users$ = this.select((state) => state.users);
|
||||||
readonly error$ = this.select((state) => state.error);
|
readonly error$ = this.select((state) => state.error);
|
||||||
@@ -35,15 +36,11 @@ export class TicketStore
|
|||||||
private readonly ticketsInput$ = this.select((state) => state.tickets);
|
private readonly ticketsInput$ = this.select((state) => state.tickets);
|
||||||
private readonly search$ = this.select((state) => state.search);
|
private readonly search$ = this.select((state) => state.search);
|
||||||
|
|
||||||
constructor(private backend: BackendService) {
|
|
||||||
super(initialState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly ticketsUsers$ = this.select(
|
private readonly ticketsUsers$ = this.select(
|
||||||
this.users$,
|
this.users$,
|
||||||
this.ticketsInput$,
|
this.ticketsInput$,
|
||||||
(users, tickets) =>
|
(users, tickets) =>
|
||||||
users
|
users && users.length > 0
|
||||||
? tickets.map((ticket) => ({
|
? tickets.map((ticket) => ({
|
||||||
...ticket,
|
...ticket,
|
||||||
assignee:
|
assignee:
|
||||||
@@ -78,6 +75,17 @@ export class TicketStore
|
|||||||
search,
|
search,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
private backend = inject(BackendService);
|
||||||
|
|
||||||
|
ngrxOnStoreInit() {
|
||||||
|
this.setState(initialState);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngrxOnStateInit() {
|
||||||
|
this.loadTickets();
|
||||||
|
this.loadUsers();
|
||||||
|
}
|
||||||
|
|
||||||
readonly loadTickets = this.effect<void>(
|
readonly loadTickets = this.effect<void>(
|
||||||
pipe(
|
pipe(
|
||||||
tap(() => this.patchState({ loading: true, error: '' })),
|
tap(() => this.patchState({ loading: true, error: '' })),
|
||||||
@@ -159,9 +167,4 @@ export class TicketStore
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
ngrxOnStateInit() {
|
|
||||||
this.loadTickets();
|
|
||||||
this.loadUsers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user