Open History to see the last commit
1import {
2 ChangeDetectionStrategy,
3 Component,
4 computed,
5 inject,
6} from '@angular/core'
7import { injectInfiniteQuery } from '@tanstack/angular-query-experimental'
8import { ProjectStyleDirective } from '../directives/project-style.directive'
9import { ProjectsQueries } from '../services/projects/queries'
10β
11@Component({
12 changeDetection: ChangeDetectionStrategy.OnPush,
13 selector: 'example',
14 templateUrl: './example.component.html',
15 imports: [ProjectStyleDirective],
16})
17export class ExampleComponent {
18 readonly #projectsQueries = inject(ProjectsQueries)
19β
20 readonly query = injectInfiniteQuery(() => ({
21 ...this.#projectsQueries.list(),
22 maxPages: 3,
23 }))
24β
25 readonly nextButtonDisabled = computed(
26 () => !this.#hasNextPage() || this.#isFetchingNextPage(),
27 )
28β
29 readonly nextButtonText = computed(() =>
30 this.#isFetchingNextPage()
31 ? 'Loading more...'
32 : this.#hasNextPage()
33 ? 'Load newer'
34 : 'Nothing more to load',
35 )
36β
37 readonly previousButtonDisabled = computed(
38 () => !this.#hasPreviousPage() || this.#isFetchingPreviousPage(),
39 )
40 readonly previousButtonText = computed(() =>
41 this.#isFetchingPreviousPage()
42 ? 'Loading more...'
43 : this.#hasPreviousPage()
44 ? 'Load Older'
45 : 'Nothing more to load',
46 )
47β
48 readonly #hasPreviousPage = this.query.hasPreviousPage
49 readonly #hasNextPage = this.query.hasNextPage
50 readonly #isFetchingPreviousPage = this.query.isFetchingPreviousPage
51 readonly #isFetchingNextPage = this.query.isFetchingNextPage
52}