|
1 |
| -import { Component, inject } from '@angular/core'; |
| 1 | +import { Component, computed, inject } from '@angular/core'; |
2 | 2 | import { toSignal } from '@angular/core/rxjs-interop';
|
3 | 3 | import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
|
4 |
| -import { filter, map } from 'rxjs'; |
| 4 | +import { filter } from 'rxjs'; |
5 | 5 |
|
6 | 6 | @Component({
|
7 | 7 | selector: 'app-root',
|
8 | 8 | standalone: true,
|
9 | 9 | template: `
|
10 | 10 | <router-outlet />
|
11 |
| - <select class="absolute bottom-4 right-4 font-mono" [value]="currentRoute()" (change)="onChange($event)"> |
12 |
| - <option value="soba">/soba</option> |
13 |
| - <option value="cannon">/cannon</option> |
14 |
| - <option value="postprocessing">/postprocessing</option> |
15 |
| - <option value="rapier">/rapier</option> |
16 |
| - <option value="misc">/misc</option> |
17 |
| - </select> |
| 11 | +
|
| 12 | + <div class="absolute bottom-4 right-4 flex gap-4 items-center"> |
| 13 | + <select [value]="currentRoute()" (change)="onChange($event)"> |
| 14 | + <option value="soba">/soba</option> |
| 15 | + <option value="cannon">/cannon</option> |
| 16 | + <option value="postprocessing">/postprocessing</option> |
| 17 | + <option value="rapier">/rapier</option> |
| 18 | + <option value="misc">/misc</option> |
| 19 | + </select> |
| 20 | +
|
| 21 | + <div class="bg-white rounded-full p-2 text-black border border-white border-dashed"> |
| 22 | + <a class="cursor-pointer" [href]="currentSourcePath()" target="_blank" title="View source"> |
| 23 | + <svg |
| 24 | + xmlns="http://www.w3.org/2000/svg" |
| 25 | + fill="none" |
| 26 | + viewBox="0 0 24 24" |
| 27 | + stroke-width="1.5" |
| 28 | + stroke="currentColor" |
| 29 | + class="h-6 w-6" |
| 30 | + > |
| 31 | + <path |
| 32 | + stroke-linecap="round" |
| 33 | + stroke-linejoin="round" |
| 34 | + d="M17.25 6.75 22.5 12l-5.25 5.25m-10.5 0L1.5 12l5.25-5.25m7.5-3-4.5 16.5" |
| 35 | + /> |
| 36 | + </svg> |
| 37 | + </a> |
| 38 | + </div> |
| 39 | + </div> |
18 | 40 | `,
|
19 | 41 | imports: [RouterOutlet],
|
20 | 42 | })
|
21 | 43 | export class AppComponent {
|
22 | 44 | private router = inject(Router);
|
23 | 45 |
|
24 |
| - currentRoute = toSignal( |
25 |
| - this.router.events.pipe( |
26 |
| - filter((event) => event instanceof NavigationEnd), |
27 |
| - map(() => { |
28 |
| - const [segment] = this.router.url.split('/').filter(Boolean); |
29 |
| - return segment; |
30 |
| - }), |
31 |
| - ), |
32 |
| - { initialValue: 'soba' }, |
33 |
| - ); |
| 46 | + private navigationEnd = toSignal(this.router.events.pipe(filter((event) => event instanceof NavigationEnd))); |
| 47 | + |
| 48 | + currentRoute = computed(() => { |
| 49 | + const navigationEnd = this.navigationEnd(); |
| 50 | + if (!navigationEnd) return 'soba'; |
| 51 | + const [segment] = navigationEnd.urlAfterRedirects.split('/').filter(Boolean); |
| 52 | + return segment; |
| 53 | + }); |
| 54 | + |
| 55 | + currentSourcePath = computed(() => { |
| 56 | + const navigationEnd = this.navigationEnd(); |
| 57 | + if (!navigationEnd) return ''; |
| 58 | + const paths = navigationEnd.urlAfterRedirects.split('/').filter(Boolean); |
| 59 | + return `https://github.com/angular-threejs/angular-three/tree/main/apps/kitchen-sink/src/app/${paths.join('/')}`; |
| 60 | + }); |
34 | 61 |
|
35 | 62 | onChange(event: Event) {
|
36 | 63 | const target = event.target as HTMLSelectElement;
|
|
0 commit comments