Skip to content

Commit

Permalink
handle trek rating scale
Browse files Browse the repository at this point in the history
  • Loading branch information
bastyen committed Jan 9, 2024
1 parent c05be3a commit 3962c05
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/grw-trek-detail/grw-trek-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ export class GrwTrekDetail {
</div>
</div>
{this.currentTrek.ratings.map(trekRating => (
<div class="row">{state.ratings.find(rating => rating.id === trekRating).name}</div>
<div class="row">
{`${state.ratingsScale.find(ratingScale => ratingScale.id === state.ratings.find(rating => rating.id === trekRating).scale).name} : ${
state.ratings.find(rating => rating.id === trekRating).name
}`}
</div>
))}
{this.currentTrek.ratings_description && this.currentTrek.ratings_description !== '' && <div class="row">{this.currentTrek.ratings_description}</div>}
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/store/grw-trek-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export class GrwTrekProvider {
);
requests.push(
!state.ratings
? fetch(`${state.api}trek_rating/?language=${state.language}${this.portals ? '&portals='.concat(this.portals) : ''}&fields=id,name`, this.init)
? fetch(`${state.api}trek_rating/?language=${state.language}${this.portals ? '&portals='.concat(this.portals) : ''}&fields=id,name,scale`, this.init)
: new Response('null'),
);
requests.push(!state.ratings ? fetch(`${state.api}trek_ratingscale/?language=${state.language}&fields=id,name`, this.init) : new Response('null'));

Promise.all([
...requests,
fetch(
Expand Down Expand Up @@ -104,6 +106,7 @@ export class GrwTrekProvider {
cities,
accessibilities,
ratings,
ratingsScale,
sensitiveAreas,
labels,
sources,
Expand Down Expand Up @@ -167,6 +170,10 @@ export class GrwTrekProvider {
state.ratings = ratings.results;
}

if (ratingsScale) {
state.ratingsScale = ratingsScale.results;
}

if (sensitiveAreas) {
state.currentSensitiveAreas = sensitiveAreas.results;
}
Expand Down
3 changes: 3 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
TouristicEventTypes,
TouristicEvent,
Ratings,
RatingsScale,
} from 'types/types';

const { state, onChange, reset } = createStore<{
Expand All @@ -50,6 +51,7 @@ const { state, onChange, reset } = createStore<{
districts: Districts;
sources: Sources;
ratings: Ratings;
ratingsScale: RatingsScale;
accessibilities: Accessibilities;
accessibilitiesLevel: accessibilitiesLevel;
poiTypes: PoiTypes;
Expand Down Expand Up @@ -103,6 +105,7 @@ const { state, onChange, reset } = createStore<{
districts: null,
sources: null,
ratings: null,
ratingsScale: null,
accessibilities: null,
accessibilitiesLevel: null,
poiTypes: null,
Expand Down
8 changes: 8 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,12 @@ export type Ratings = Rating[];
export type Rating = {
id: number;
name: string;
scale: number;
};

export type RatingsScale = RatingScale[];

export type RatingScale = {
id: number;
name: string;
};

0 comments on commit 3962c05

Please sign in to comment.