Skip to content

Commit

Permalink
Fix restoring non-public saved view state
Browse files Browse the repository at this point in the history
  • Loading branch information
slak44 committed Jun 22, 2024
1 parent 37ae898 commit e705bc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h3 *ngIf="(data.recentPublicLinks?.length ?? 0) > 0">
class="viewstate-item"
mat-ripple
role="button"
(click)="restoreState(viewState.id!)">
(click)="restorePublicState(viewState.id!)">
<span>{{ (i + 1) + '. ' + viewState.name }}</span>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MatButtonModule } from '@angular/material/button';
import { environment } from '../../../../environments/environment';
import { BROADCAST_ROUTE, PUBLIC_SHARE_ROUTE } from '@cki-utils/routes';
import { Router } from '@angular/router';
import { SnackbarService } from '../../../material-utils/services/snackbar.service';

@Component({
selector: 'cki-viewstate-list',
Expand Down Expand Up @@ -58,6 +59,7 @@ export class ViewstateListComponent extends SubscriptionDestroy implements OnIni
private readonly broadcastViewStateService: BroadcastViewStateService,
private readonly broadcastService: BroadcastService,
private readonly router: Router,
private readonly snackbarService: SnackbarService,
) {
super();
}
Expand All @@ -79,6 +81,18 @@ export class ViewstateListComponent extends SubscriptionDestroy implements OnIni
}

public restoreState(stateId: string): void {
this.viewStateService.fetchAndRestoreState(stateId).pipe(takeUntil(this.destroy$)).subscribe({
next: (viewState) => {
this.router.navigate([viewState.activeRoute]).catch(console.error);
},
error: error => {
console.error(error);
this.snackbarService.showLongSnackWithDismiss('Failed to load view state.');
}
});
}

public restorePublicState(stateId: string): void {
this.router.navigate([PUBLIC_SHARE_ROUTE, stateId]).catch(console.error);
}

Expand Down

0 comments on commit e705bc1

Please sign in to comment.