Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(articles): prevent flickering (#2910)
- Loading branch information
Showing
8 changed files
with
69 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { map, shareReplay } from 'rxjs/operators'; | ||
import { NgdMdSection, NgdTextService } from './text.service'; | ||
|
||
@Injectable() | ||
export class NgdArticleService { | ||
constructor(private http: HttpClient, private textService: NgdTextService) {} | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
getArticle(source: string): Observable<string> { | ||
return this.http.get(`articles/${source}`, { responseType: 'text' }); | ||
getArticle(source: string): Observable<NgdMdSection[]> { | ||
return this.http.get(`articles/${source}`, { responseType: 'text' }).pipe( | ||
map((article) => this.textService.mdToSectionsHTML(article)), | ||
shareReplay(1), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, ReplaySubject } from 'rxjs'; | ||
import { NgdMdSection } from './text.service'; | ||
|
||
/** | ||
* We store the last viewed section here to prevent flickering when switching between articles. | ||
* When a user clicks on an article link, `ngd-md-block` is destroyed and a new one is created. | ||
* This service replays the last viewed article to the newly created `ngd-md-block` to show it | ||
* while a requested article is loading. | ||
* */ | ||
@Injectable() | ||
export class NgdLastViewedSectionService { | ||
private _sections = new ReplaySubject<NgdMdSection[]>(1); | ||
|
||
setSection(section: NgdMdSection[]): void { | ||
this._sections.next(section); | ||
} | ||
|
||
getSections(): Observable<NgdMdSection[]> { | ||
return this._sections.asObservable(); | ||
} | ||
} |
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
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
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