Skip to content

Commit

Permalink
handle parent trek press
Browse files Browse the repository at this point in the history
  • Loading branch information
bastyen committed Oct 6, 2023
1 parent f93d160 commit 7e1107a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ declare namespace LocalJSX {
"isLargeView"?: boolean;
"onDescriptionReferenceIsInViewport"?: (event: GrwTrekDetailCustomEvent<boolean>) => void;
"onInformationDeskIsInViewport"?: (event: GrwTrekDetailCustomEvent<boolean>) => void;
"onParentTrekPress"?: (event: GrwTrekDetailCustomEvent<number>) => void;
"onParkingIsInViewport"?: (event: GrwTrekDetailCustomEvent<boolean>) => void;
"onPoiIsInViewport"?: (event: GrwTrekDetailCustomEvent<boolean>) => void;
"onSensitiveAreaIsInViewport"?: (event: GrwTrekDetailCustomEvent<boolean>) => void;
Expand Down
12 changes: 12 additions & 0 deletions src/components/grw-app/grw-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export class GrwApp {
window.history.pushState({}, '', url);
}

@Listen('parentTrekPress', { target: 'window' })
onParentTrekPress(event: CustomEvent<number>) {
state.currentTrek = null;
this.currentTrekId = event.detail;
this.showTrek = true;
this.showTrekMap = false;
const url = new URL(window.location.toString());
url.searchParams.set('trek', this.currentTrekId.toString());
url.searchParams.delete('parentTrek');
window.history.pushState({}, '', url);
}

@Listen('resize', { target: 'window' })
onWindowResize() {
this.handleView();
Expand Down
5 changes: 3 additions & 2 deletions src/components/grw-trek-detail/grw-trek-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class GrwTrekDetail {
@Event() sensitiveAreaIsInViewport: EventEmitter<boolean>;
@Event() informationDeskIsInViewport: EventEmitter<boolean>;
@Event() poiIsInViewport: EventEmitter<boolean>;
@Event() parentTrekPress: EventEmitter<number>;
@State() currentTrek: Trek;
@State() difficulty: Difficulty;
@State() route: Route;
Expand Down Expand Up @@ -457,9 +458,9 @@ export class GrwTrekDetail {
{this.currentTrek.description_teaser && <div class="description-teaser" innerHTML={this.currentTrek.description_teaser}></div>}
{this.currentTrek.ambiance && <div class="ambiance" innerHTML={this.currentTrek.ambiance}></div>}
<div class="divider"></div>
{state.parentTrek && (
{state.parentTrekId && state.parentTrek && this.currentTrek.id !== state.parentTrekId && (
<div class="parent-trek-container">
<button class="parent-trek-title">
<button class="parent-trek-title" onClick={() => this.parentTrekPress.emit(state.parentTrekId)}>
<div>&lt;</div>
{state.parentTrek.name}
</button>
Expand Down
1 change: 1 addition & 0 deletions src/components/grw-trek-detail/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| ---------------------------------- | ----------- | ---------------------- |
| `descriptionReferenceIsInViewport` | | `CustomEvent<boolean>` |
| `informationDeskIsInViewport` | | `CustomEvent<boolean>` |
| `parentTrekPress` | | `CustomEvent<number>` |
| `parkingIsInViewport` | | `CustomEvent<boolean>` |
| `poiIsInViewport` | | `CustomEvent<boolean>` |
| `sensitiveAreaIsInViewport` | | `CustomEvent<boolean>` |
Expand Down

0 comments on commit 7e1107a

Please sign in to comment.