Skip to content

Commit a3789b6

Browse files
authored
feat(client): add & use banner slider loaded from the backend (#323)
1 parent e1dd760 commit a3789b6

File tree

19 files changed

+129
-177
lines changed

19 files changed

+129
-177
lines changed
-331 KB
Binary file not shown.
-331 KB
Binary file not shown.
-324 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/state/ad-banner.store';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { inject, Injectable } from '@angular/core';
3+
4+
import { Slider } from '@angular-love/blog/contracts/banners';
5+
import { ConfigService } from '@angular-love/shared/config';
6+
7+
@Injectable({ providedIn: 'root' })
8+
export class AdBannerService {
9+
private readonly _apiBaseUrl = inject(ConfigService).get('apiBaseUrl');
10+
private readonly _http = inject(HttpClient);
11+
12+
getBannerSlider() {
13+
return this._http.get<Slider>(`${this._apiBaseUrl}/banners`);
14+
}
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { inject } from '@angular/core';
2+
import { tapResponse } from '@ngrx/operators';
3+
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
4+
import { rxMethod } from '@ngrx/signals/rxjs-interop';
5+
import { pipe, switchMap } from 'rxjs';
6+
7+
import { Slider } from '@angular-love/blog/contracts/banners';
8+
9+
import { AdBannerService } from '../infrastructure/ad-banner.service';
10+
11+
type AdBannerState = {
12+
slider: Slider | null;
13+
};
14+
15+
const initialState: AdBannerState = {
16+
slider: null,
17+
};
18+
19+
export const AdBannerStore = signalStore(
20+
{ providedIn: 'root' },
21+
withState(initialState),
22+
withMethods((store, adBannerService = inject(AdBannerService)) => ({
23+
getData: rxMethod<void>(
24+
pipe(
25+
switchMap(() =>
26+
adBannerService.getBannerSlider().pipe(
27+
tapResponse({
28+
next: (slider) => {
29+
patchState(store, { slider });
30+
},
31+
error: () => {
32+
patchState(store);
33+
},
34+
}),
35+
),
36+
),
37+
),
38+
),
39+
})),
40+
);

libs/blog/ad-banner/ui/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export * from './lib/ad-banner/ad-banner.component';
21
export * from './lib/ad-image-banner/ad-image-banner.component';
32
export * from './lib/ad-image-banner/ad-image-banner-data.interface';
43
export * from './lib/instances/al-indepth-banner.component';
5-
export * from './lib/instances/autumn-camp/al-autumn-camp-banner.component';
4+
export * from './lib/banner-carousel/al-banner-carousel.component';

libs/blog/ad-banner/ui/src/lib/ad-banner/ad-banner.component.html

Lines changed: 0 additions & 50 deletions
This file was deleted.

libs/blog/ad-banner/ui/src/lib/ad-banner/ad-banner.component.spec.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

libs/blog/ad-banner/ui/src/lib/ad-banner/ad-banner.component.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)