File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ export class ArticlesService {
17
17
return this . _http . get < Article > ( `${ this . _apiBaseUrl } /articles/${ slug } ` ) ;
18
18
}
19
19
20
+ getArticlePreviewBySlug ( slug : string ) : Observable < Article > {
21
+ return this . _http . get < Article > ( `${ this . _apiBaseUrl } /articles/${ slug } ` , {
22
+ headers : {
23
+ 'Cache-Control' : 'no-cache' ,
24
+ } ,
25
+ } ) ;
26
+ }
27
+
20
28
getArticleList (
21
29
query : ArticlesQuery ,
22
30
) : Observable < ArrayResponse < ArticlePreview > > {
Original file line number Diff line number Diff line change 1
- import { computed , inject } from '@angular/core' ;
1
+ import { computed , inject , InjectionToken } from '@angular/core' ;
2
2
import { tapResponse } from '@ngrx/operators' ;
3
3
import {
4
4
patchState ,
@@ -30,6 +30,13 @@ const initialState: ArticleDetailsState = {
30
30
slug : null ,
31
31
} ;
32
32
33
+ export const IsArticlePreview = new InjectionToken < boolean > (
34
+ 'Article Details Store Is Article Preview' ,
35
+ {
36
+ factory : ( ) => false ,
37
+ } ,
38
+ ) ;
39
+
33
40
export const ArticleDetailsStore = signalStore (
34
41
{ providedIn : 'root' } ,
35
42
withSeo ( ) ,
@@ -38,6 +45,7 @@ export const ArticleDetailsStore = signalStore(
38
45
withLangState ( ) ,
39
46
withMethods ( ( { ...store } ) => {
40
47
const articlesService = inject ( ArticlesService ) ;
48
+ const isPreview = inject ( IsArticlePreview ) ;
41
49
42
50
return {
43
51
fetchArticleDetails : rxMethod < string | undefined > (
@@ -51,7 +59,10 @@ export const ArticleDetailsStore = signalStore(
51
59
} ) ,
52
60
) ,
53
61
switchMap ( ( slug ) =>
54
- articlesService . getArticleBySlug ( slug ) . pipe (
62
+ ( isPreview
63
+ ? articlesService . getArticlePreviewBySlug ( slug )
64
+ : articlesService . getArticleBySlug ( slug )
65
+ ) . pipe (
55
66
tapResponse ( {
56
67
error : ( error ) =>
57
68
patchState ( store , {
Original file line number Diff line number Diff line change 1
1
import { Routes } from '@angular/router' ;
2
2
3
- import { articleExistsGuard } from '@angular-love/blog/articles/data-access' ;
3
+ import {
4
+ ArticleDetailsStore ,
5
+ articleExistsGuard ,
6
+ IsArticlePreview ,
7
+ } from '@angular-love/blog/articles/data-access' ;
4
8
5
9
export const articleRoutes : Routes = [
6
10
{
@@ -39,6 +43,16 @@ export const articleRoutes: Routes = [
39
43
seo : { title : 'Angular In Depth' } ,
40
44
} ,
41
45
} ,
46
+ {
47
+ path : 'preview/:articleSlug' ,
48
+ providers : [
49
+ { provide : IsArticlePreview , useValue : true } ,
50
+ ArticleDetailsStore ,
51
+ ] ,
52
+ loadComponent : async ( ) =>
53
+ ( await import ( '@angular-love/blog/articles/feature-article' ) )
54
+ . ArticleDetailsContainerComponent ,
55
+ } ,
42
56
{
43
57
path : ':articleSlug' ,
44
58
pathMatch : 'full' ,
You can’t perform that action at this time.
0 commit comments