Skip to content

Commit

Permalink
feat(kit): refactor generateDialogableRoute and RoutableDialogComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Puris committed Feb 20, 2023
1 parent 74c1382 commit 4afcac0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ import {TuiRoutableDialogComponent} from './routable-dialog.component';

export function tuiGenerateDialogableRoute<I>(
component: Type<any>,
{path, ...dialogOptions}: Partial<TuiDialogOptions<I>> & {path?: string} = {},
{path = ``, ...dialogOptions}: Partial<TuiDialogOptions<I>> & {path?: string} = {},
): Route {
const processedPath = path ?? ``;

return {
path: processedPath,
path,
component: TuiRoutableDialogComponent,
data: {
dialog: component,
backUrl: processedPath
backUrl: path
.split(`/`)
.map(() => `..`)
.join(`/`),
isLazy: processedPath === ``,
isLazy: path === ``,
dialogOptions,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ import {takeUntil} from 'rxjs/operators';
})
export class TuiRoutableDialogComponent {
constructor(
@Inject(TuiDialogService) private readonly dialogService: TuiDialogService,
@Inject(ActivatedRoute) private readonly route: ActivatedRoute,
@Inject(Router) private readonly router: Router,
@Inject(Injector) private readonly injector: Injector,
@Self() @Inject(TuiDestroyService) private readonly destroy$: TuiDestroyService,
@Inject(TuiDialogService) dialogService: TuiDialogService,
@Inject(Injector) injector: Injector,
@Self() @Inject(TuiDestroyService) destroy$: TuiDestroyService,
) {
this.dialogService
dialogService
.open(
new PolymorpheusComponent(
this.route.snapshot.data['dialog'],
this.injector,
),
new PolymorpheusComponent(this.route.snapshot.data['dialog'], injector),
this.route.snapshot.data['dialogOptions'],
)
.pipe(takeUntil(this.destroy$))
.pipe(takeUntil(destroy$))
.subscribe({
complete: () => this.navigateToParent(),
});
Expand Down

0 comments on commit 4afcac0

Please sign in to comment.