Skip to content

Commit 34bcb03

Browse files
committed
social - change og:image, description and title dynamically for snippet details
1 parent f3d0003 commit 34bcb03

21 files changed

+115
-84
lines changed
Loading
Binary file not shown.
Loading
Binary file not shown.

frontend/src/app/core/user/user-info.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class UserInfoService {
2323
key: localStorageKeys.userInfoOidc,
2424
cacheHours: 24,
2525
isSensitive: true
26-
}; // cache it for a day
26+
}; // cache it for a day, it gets cleaned when user logs out
2727

2828
return this.httpClientLocalStorageService
2929
.get<UserInfoOidc>(options)

frontend/src/app/my-snippets/snippet-details-page/snippet-details-page.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<div *ngIf="(snippet$ | async) as snippet" class="mt-3">
2-
1+
<div class="mt-3">
32
<app-snippet-details
4-
[snippet$]="snippet$"
3+
[snippet]="snippet$ | async"
54
[queryText]="queryText">
65
</app-snippet-details>
76

frontend/src/app/my-snippets/snippet-details-page/snippet-details-page.component.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { Snippet } from '../../core/model/snippet';
44
import { ActivatedRoute } from '@angular/router';
55
import { PersonalSnippetsService } from '../../core/personal-snippets.service';
66
import { UserInfoStore } from '../../core/user/user-info.store';
7+
import { last, map, mergeMap, switchMap, take, withLatestFrom } from 'rxjs/operators';
8+
import { combineLatest } from 'rxjs';
9+
import { Meta, Title } from '@angular/platform-browser';
10+
import { environment } from '../../../environments/environment';
711

812
@Component({
913
selector: 'app-snippet-details-page',
@@ -13,8 +17,6 @@ import { UserInfoStore } from '../../core/user/user-info.store';
1317
export class SnippetDetailsPageComponent implements OnInit {
1418

1519
snippet$: Observable<Snippet>;
16-
snippetId: string;
17-
userId: string;
1820

1921
popup: string;
2022

@@ -24,22 +26,30 @@ export class SnippetDetailsPageComponent implements OnInit {
2426
@Input()
2527
showCloseWindowBtn: boolean;
2628

29+
environment = environment;
30+
31+
snippetTitle: string;
32+
2733
constructor(
2834
private personalSnippetsService: PersonalSnippetsService,
2935
private userInfoStore: UserInfoStore,
30-
private route: ActivatedRoute) {
36+
private route: ActivatedRoute,
37+
) {
3138

3239
}
3340

3441
ngOnInit(): void {
3542
this.popup = this.route.snapshot.queryParamMap.get('popup');
36-
this.snippet$ = of(window.history.state.snippet);
37-
if (!window.history.state.snippet) {
38-
this.userInfoStore.getUserInfoOidc$().subscribe(userInfo => {
39-
this.userId = userInfo.sub;
40-
this.snippetId = this.route.snapshot.paramMap.get('id');
41-
this.snippet$ = this.personalSnippetsService.getPersonalSnippetById(this.userId, this.snippetId);
42-
});
43+
if (window.history.state.snippet) {
44+
this.snippetTitle = window.history.state.snippet.title;
45+
this.snippet$ = of(window.history.state.snippet);
46+
} else {
47+
this.snippet$ = combineLatest([this.userInfoStore.getUserId$(), this.route.paramMap] ).pipe(
48+
take(1),
49+
switchMap(([userId, paramMap]) => {
50+
return this.personalSnippetsService.getPersonalSnippetById(userId, paramMap.get('id'));
51+
})
52+
);
4353
}
4454
}
4555

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<app-snippet-details [snippet$]="snippet$"></app-snippet-details>
1+
<app-snippet-details [snippet]="snippet$ | async"></app-snippet-details>

frontend/src/app/public/snippets/public-snippets.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class PublicSnippetsService {
4545
getPublicSnippetById(snippetId: string): Observable<Snippet> {
4646
return this.httpClient
4747
.get<Snippet>(`${this.publicSnippetsApiBaseUrl}/${snippetId}`).pipe(
48+
shareReplay(1),
4849
catchError(() => {
4950
this.router.navigate(['/404-snippet'],
5051
{

frontend/src/app/public/tag/bookmarks-tagged.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>Public bookmarks tagged [<em>{{tag}}</em>]</h2>
3333

3434
<div *ngIf="(bookmarksForTag$ | async)?.length - counter > 0">
3535
<button type="button" class="btn btn-primary btn-lg btn-block" (click)="showMoreResults()"
36-
[disabled]="counter>=(bookmarksForTag$ | async)?.length">Show more
36+
[disabled]="counter>=(bookmarksForTag$ | async)?.length" title="Show More">Show more
3737
</button>
3838
<hr/>
3939
</div>

0 commit comments

Comments
 (0)