Skip to content

Commit 94780e3

Browse files
committed
docs: use router to drive routed rock
1 parent 0ec724a commit 94780e3

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

apps/kitchen-sink/src/app/routed-rocks/colored-rock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { RockStore } from './store';
1212
[castShadow]="true"
1313
[receiveShadow]="true"
1414
[rotation]="[0, Math.PI / 4, 0]"
15-
[position]="[0, 2, 0]"
15+
[position]="[0, 7, 0]"
1616
[scale]="0.5"
1717
>
1818
<ngt-box-geometry *args="[0.7, 0.7, 0.7]" />
1919
<ngt-mesh-phong-material [color]="rock.color" [side]="FrontSide" />
2020
</ngt-mesh>
2121
22-
<ngt-group>
22+
<ngt-group [position]="[0, 5, 0]">
2323
@for (text of texts; track $index) {
2424
<ngts-text
2525
font="https://fonts.gstatic.com/s/raleway/v14/1Ptrg8zYS_SKggPNwK4vaqI.woff"
@@ -30,6 +30,7 @@ import { RockStore } from './store';
3030
fontSize: 0.5,
3131
position: text.position,
3232
rotation: text.rotation,
33+
castShadow: true,
3334
}"
3435
/>
3536
}

apps/kitchen-sink/src/app/routed-rocks/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const menus = colors.map((color, index) => ({
3131
label: color.label,
3232
name: `rock-${color.slug}`,
3333
path: `/routed-rocks/rocks/${color.slug}`,
34-
contentId: index + 1,
3534
color: color.color,
3635
angle: ((360 / colors.length) * index * Math.PI) / 180,
3736
}));

apps/kitchen-sink/src/app/routed-rocks/rocks.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ interface RockGLTF extends GLTF {
4040
<ngt-group [rotation]="[Math.PI / 2, 0, 0]">
4141
<ngt-mesh
4242
cursor
43-
name="theRock"
4443
[castShadow]="true"
4544
[receiveShadow]="true"
4645
[geometry]="gltf.nodes.defaultMaterial.geometry"
4746
[material]="gltf.materials['08___Default']"
48-
(click)="onRockClicked()"
47+
(click)="router.navigate(['/routed-rocks/rocks'])"
4948
/>
5049
</ngt-group>
5150
</ngt-group>
@@ -58,15 +57,14 @@ interface RockGLTF extends GLTF {
5857
5958
<ngt-icosahedron-geometry #geometry attach="none" />
6059
@for (menu of menus; track menu.id) {
61-
<ngt-group [position]="[15 * Math.cos(menu.angle), 0, 15 * Math.sin(menu.angle)]" [name]="'group-' + menu.id">
60+
<ngt-group [name]="menu.name" [position]="[15 * Math.cos(menu.angle), 0, 15 * Math.sin(menu.angle)]">
6261
<ngt-mesh
6362
cursor
64-
[name]="menu.name"
6563
[position]="[0, 5, 0]"
6664
[castShadow]="true"
6765
[receiveShadow]="true"
6866
[geometry]="geometry"
69-
(click)="onColoredRockClicked(menu)"
67+
(click)="router.navigate([menu.path])"
7068
>
7169
<ngt-mesh-phong-material [color]="menu.color" [side]="FrontSide" />
7270
</ngt-mesh>
@@ -87,7 +85,7 @@ export default class Rocks {
8785

8886
protected readonly menus = menus;
8987

90-
private router = inject(Router);
88+
protected router = inject(Router);
9189
private rockStore = inject(RockStore);
9290
private store = injectStore();
9391

@@ -109,20 +107,8 @@ export default class Rocks {
109107

110108
const obj = rock ? scene.getObjectByName(rock.name) : gltf.scene;
111109
if (obj) {
112-
void controls.fitToBox(obj, true, {
113-
paddingTop: 5,
114-
});
110+
void controls.fitToBox(obj, true, { paddingTop: 5 });
115111
}
116112
});
117113
}
118-
119-
onColoredRockClicked(menu: (typeof menus)[number]) {
120-
this.rockStore.selectedRock.set(menu);
121-
this.router.navigate([menu.path]);
122-
}
123-
124-
onRockClicked() {
125-
this.rockStore.selectedRock.set(null);
126-
this.router.navigate(['/routed-rocks/rocks']);
127-
}
128114
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, Injectable, linkedSignal } from '@angular/core';
1+
import { inject, Injectable } from '@angular/core';
22
import { toSignal } from '@angular/core/rxjs-interop';
33
import { NavigationEnd, Router } from '@angular/router';
44
import { filter, map, startWith } from 'rxjs';
@@ -8,7 +8,7 @@ import { menus } from './constants';
88
export class RockStore {
99
private router = inject(Router);
1010

11-
private initialRock = toSignal(
11+
selectedRock = toSignal(
1212
this.router.events.pipe(
1313
filter((ev): ev is NavigationEnd => ev instanceof NavigationEnd),
1414
map((ev) => ev.urlAfterRedirects),
@@ -17,6 +17,4 @@ export class RockStore {
1717
),
1818
{ initialValue: null },
1919
);
20-
21-
selectedRock = linkedSignal(this.initialRock);
2220
}

0 commit comments

Comments
 (0)