Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/features/project/project.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const projectRoutes: Routes = [
),
providers: [provideStates([DuplicatesState])],
},
{
path: 'wiki/:wikiName',
loadComponent: () =>
import('../project/wiki/legacy-wiki-redirect.component').then((m) => m.LegacyWikiRedirectComponent),
},
{
path: 'wiki',
loadComponent: () => import('../project/wiki/wiki.component').then((mod) => mod.WikiComponent),
Expand Down
53 changes: 53 additions & 0 deletions src/app/features/project/wiki/legacy-wiki-redirect.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { createDispatchMap, select } from '@ngxs/store';

import { map, of, tap } from 'rxjs';

import { Component, DestroyRef, inject } from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, Router } from '@angular/router';

import { ResourceType } from '@osf/shared/enums';
import { LoaderService } from '@osf/shared/services';
import { GetWikiList, WikiSelectors } from '@osf/shared/stores';

@Component({
template: '',
})
export class LegacyWikiRedirectComponent {
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly destroyRef = inject(DestroyRef);
private readonly loaderService = inject(LoaderService);

readonly projectId = toSignal(this.route.parent?.params.pipe(map((params) => params['id'])) ?? of(undefined));
wikiList = select(WikiSelectors.getWikiList);

actions = createDispatchMap({
getWikiList: GetWikiList,
});

constructor() {
this.loaderService.show();
this.redirectWiki();
}

redirectWiki() {
const params = this.route.snapshot.params;
const wikiName = params['wikiName'];

this.actions
.getWikiList(ResourceType.Project, this.projectId())
.pipe(
takeUntilDestroyed(this.destroyRef),
tap(() => {
const wikiGUID = this.wikiList().find((item) => item.name === wikiName)?.id ?? null;
this.router.navigate([`/${this.projectId()}/wiki`], {
queryParams: { wiki: wikiGUID },
replaceUrl: true,
});
this.loaderService.hide();
})
)
.subscribe();
}
}