Skip to content

Commit

Permalink
feat: handle pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
bastyen committed Jan 22, 2025
1 parent 631dd9f commit 6bd289e
Show file tree
Hide file tree
Showing 16 changed files with 849 additions and 2,377 deletions.
2,951 changes: 686 additions & 2,265 deletions hars/grw-app.har

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/grw-app/test/grw-app.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test.describe('grw-app', () => {

test('steps', async ({ page }) => {
await page.getByText('Boucle de Pouzol').click();
await page.getByText('Etape GR09').click();
await page.getByText('Etape GR09 Étang Rond-Refuge').click();
await expect(page.getByText('Etape GR09 Étang Rond-Refuge').first()).toBeVisible();
});

Expand Down
6 changes: 4 additions & 2 deletions src/services/outdoor-courses.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAllPaginatedResults } from '../utils/utils';

export function getOutdoorCourses(api, language, inBbox, cities, districts, structures, themes, portals, init) {
let outdoorCoursesRequest = `${api}outdoor_course/?language=${language}&published=true`;
inBbox && (outdoorCoursesRequest += `&in_bbox=${inBbox}`);
Expand All @@ -8,7 +10,7 @@ export function getOutdoorCourses(api, language, inBbox, cities, districts, stru
portals && (outdoorCoursesRequest += `&portals=${portals}`);

outdoorCoursesRequest += `&fields=id,name,geometry,accessibility,advice,attachments,children,cities,description,districts,duration,equipment,gear,height,length,max_elevation,min_elevation,parents,pdf,points_reference,provider,ratings,ratings_description,sites,structure,type&page_size=999`;
return fetch(outdoorCoursesRequest, init);
return getAllPaginatedResults(outdoorCoursesRequest, init);
}

export function getOutdoorCourse(api, language, outdoorCourseId, init) {
Expand All @@ -23,5 +25,5 @@ export function getOutdoorCourseTypes(api, language, init) {
}

export function getPoisNearCourse(api, language, courseId, init) {
return fetch(`${api}poi/?language=${language}&courses=${courseId}&published=true&fields=id,name,description,attachments,type,geometry&page_size=999`, init);
return getAllPaginatedResults(`${api}poi/?language=${language}&courses=${courseId}&published=true&fields=id,name,description,attachments,type,geometry&page_size=999`, init);
}
7 changes: 4 additions & 3 deletions src/services/outdoor-sites.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDataInStore } from './grw-db.service';
import { getAllPaginatedResults } from '../utils/utils';

export function getOutdoorSites(api, language, inBbox, cities, districts, structures, themes, portals, init) {
let outdoorSitesRequest = `${api}outdoor_site/?language=${language}&root_sites_only=true&published=true`;
Expand All @@ -9,8 +10,8 @@ export function getOutdoorSites(api, language, inBbox, cities, districts, struct
themes && (outdoorSitesRequest += `&themes=${themes}`);
portals && (outdoorSitesRequest += `&portals=${portals}`);

outdoorSitesRequest += `&fields=id,name,geometry,accessibility,advice,ambiance,attachments,cities,children,description,description_teaser,districts,information_desks,labels,managers,orientation,pdf,period,parent,portal,practice,provider,ratings,sector,source,structure,themes,view_points,type,courses,web_links,wind&page_size=999`;
return fetch(outdoorSitesRequest, init);
outdoorSitesRequest += `&fields=id,name,geometry,accessibility,advice,ambiance,attachments,cities,children,description,description_teaser,districts,information_desks,labels,managers,orientation,pdf,period,parent,portal,practice,provider,ratings,sector,source,structure,themes,view_points,type,courses,web_links,wind`;
return getAllPaginatedResults(outdoorSitesRequest, init);
}

export function getOutdoorSite(api, language, outdoorSiteId, init) {
Expand All @@ -30,7 +31,7 @@ export function getOutdoorPractices(api, language, init) {
}

export function getPoisNearSite(api, language, siteId, init) {
return fetch(`${api}poi/?language=${language}&sites=${siteId}&published=true&fields=id,name,description,attachments,type,geometry&page_size=999`, init);
return getAllPaginatedResults(`${api}poi/?language=${language}&sites=${siteId}&published=true&fields=id,name,description,attachments,type,geometry`, init);
}

export async function outdoorSiteIsAvailableOffline(outdoorSiteId) {
Expand Down
43 changes: 37 additions & 6 deletions src/services/touristic-contents.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { getAllPaginatedResults } from '../utils/utils';

export function getTouristicContents(api, language, init) {
return fetch(
`${api}touristiccontent/?language=${language}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts`,
init,
);
}

export function getTouristicContent(api, language, touristicContentId, init) {
return fetch(
`${api}touristiccontent/${touristicContentId}/?language=${language}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts`,
Expand All @@ -6,22 +15,44 @@ export function getTouristicContent(api, language, touristicContentId, init) {
}

export function getTouristicContentsNearTrek(api, language, trekId, init) {
return fetch(
`${api}touristiccontent/?language=${language}&near_trek=${trekId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts&page_size=999`,
return getAllPaginatedResults(
`${api}touristiccontent/?language=${language}&near_trek=${trekId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts`,
init,
);
}

export function getTouristicContentsNearOutdoorSite(api, language, outdoorSiteId, init) {
return fetch(
`${api}touristiccontent/?language=${language}&near_outdoorsite=${outdoorSiteId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts&page_size=999`,
return getAllPaginatedResults(
`${api}touristiccontent/?language=${language}&near_outdoorsite=${outdoorSiteId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts`,
init,
);
}

export function getTouristicContentsNearOutdoorCourse(api, language, outdoorCourseId, init) {
return fetch(
`${api}touristiccontent/?language=${language}&near_outdoorcourse=${outdoorCourseId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts&page_size=999`,
return getAllPaginatedResults(
`${api}touristiccontent/?language=${language}&near_outdoorcourse=${outdoorCourseId}&published=true&fields=id,name,attachments,description,description_teaser,category,geometry,cities,pdf,practical_info,contact,email,website,districts`,
init,
);
}

export function getTouristicContentCategory(api, language, portals, init) {
return getAllPaginatedResults(
`${api}touristiccontent_category/?language=${language}${portals ? '&portals='.concat(portals) : ''}&published=true&fields=id,label,pictogram`,
init,
);
}

export function getTouristicContentsList(api, language, inBbox, cities, districts, structures, themes, portals, init) {
let touristicContentsRequest = `${api}touristiccontent/?language=${language}&published=true`;

this.inBbox && (touristicContentsRequest += `&in_bbox=${inBbox}`);
this.cities && (touristicContentsRequest += `&cities=${cities}`);
this.districts && (touristicContentsRequest += `&districts=${districts}`);
this.structures && (touristicContentsRequest += `&structures=${structures}`);
this.themes && (touristicContentsRequest += `&themes=${themes}`);
this.portals && (touristicContentsRequest += `&portals=${portals}`);

touristicContentsRequest += `&fields=id,name,attachments,category,geometry,cities,districts`;

return getAllPaginatedResults(touristicContentsRequest, init);
}
27 changes: 24 additions & 3 deletions src/services/touristic-events.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAllPaginatedResults } from '../utils/utils';

export function getTouristicEvent(api, language, touristicEventId, init) {
return fetch(
`${api}touristicevent/${touristicEventId}/?language=${language}&fields=id,name,attachments,description,description_teaser,type,geometry,cities,pdf,practical_info,contact,email,website,begin_date,end_date&published=true`,
Expand All @@ -6,13 +8,32 @@ export function getTouristicEvent(api, language, touristicEventId, init) {
}

export function getTouristicEventsNearTrek(api, language, trekId, init) {
return fetch(`${api}touristicevent/?language=${language}&near_trek=${trekId}&published=true&fields=id,name,attachments,type,geometry&page_size=999`, init);
return getAllPaginatedResults(`${api}touristicevent/?language=${language}&near_trek=${trekId}&published=true&fields=id,name,attachments,type,geometry`, init);
}

export function getTouristicEventsNearOutdoorSite(api, language, outdoorSiteId, init) {
return fetch(`${api}touristicevent/?language=${language}&near_outdoorsite=${outdoorSiteId}&published=true&fields=id,name,attachments,type,geometry&page_size=999`, init);
return getAllPaginatedResults(`${api}touristicevent/?language=${language}&near_outdoorsite=${outdoorSiteId}&published=true&fields=id,name,attachments,type,geometry`, init);
}

export function getTouristicEventsNearOutdoorCourse(api, language, outdoorCourseId, init) {
return fetch(`${api}touristicevent/?language=${language}&near_outdoorcourse=${outdoorCourseId}&published=true&fields=id,name,attachments,type,geometry&page_size=999`, init);
return getAllPaginatedResults(`${api}touristicevent/?language=${language}&near_outdoorcourse=${outdoorCourseId}&published=true&fields=id,name,attachments,type,geometry`, init);
}

export function getTouristicEventType(api, language, portals, init) {
return getAllPaginatedResults(`${api}touristicevent_type/?language=${language}${portals ? '&portals='.concat(portals) : ''}&published=true&fields=id,type,pictogram`, init);
}

export function getTouristicEventsList(api, language, inBbox, cities, districts, structures, themes, portals, init) {
let touristicEventsRequest = `${api}touristicevent/?language=${language}&published=true`;

this.inBbox && (touristicEventsRequest += `&in_bbox=${inBbox}`);
this.cities && (touristicEventsRequest += `&cities=${cities}`);
this.districts && (touristicEventsRequest += `&districts=${districts}`);
this.structures && (touristicEventsRequest += `&structures=${structures}`);
this.themes && (touristicEventsRequest += `&themes=${themes}`);
this.portals && (touristicEventsRequest += `&portals=${portals}`);

touristicEventsRequest += `&fields=id,name,attachments,category,geometry,cities,districts,type,begin_date,end_date`;

return getAllPaginatedResults(touristicEventsRequest, init);
}
21 changes: 17 additions & 4 deletions src/services/treks.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Build } from '@stencil/core';
import state from 'store/store';
import { getDataInStore } from './grw-db.service';
import { getAllPaginatedResults } from '../utils/utils';

export function getTrekGeometry(id: number) {
return fetch(`${state.api}trek/${id}/?language=${state.language}&published=true&fields=geometry`, { cache: Build.isDev ? 'force-cache' : 'default' }).then(response =>
Expand All @@ -21,9 +22,9 @@ export function getTreksList(api, language, inBbox, cities, districts, structure
practices && (treksRequest += `&practices=${practices}`);
labels && (treksRequest += `&labels=${labels}`);

treksRequest += `&fields=id,name,attachments,description_teaser,difficulty,duration,ascent,length_2d,practice,themes,route,departure,departure_city,departure_geom,cities,accessibilities,labels,districts&page_size=999`;
treksRequest += `&fields=id,name,attachments,description_teaser,difficulty,duration,ascent,length_2d,practice,themes,route,departure,departure_city,departure_geom,cities,accessibilities,labels,districts`;

return fetch(treksRequest, init);
return getAllPaginatedResults(treksRequest, init);
}

export function getTrek(api, language, trekId, init) {
Expand All @@ -34,7 +35,7 @@ export function getTrek(api, language, trekId, init) {
}

export function getDistricts(api, language, init) {
return fetch(`${api}district/?language=${language}&fields=id,name&published=true&page_size=999`, init);
return getAllPaginatedResults(`${api}district/?language=${language}&fields=id,name&published=true`, init);
}

export async function trekIsAvailableOffline(trekId) {
Expand All @@ -51,7 +52,7 @@ export function getSensitiveAreasNearTrek(api, language, trekId, init) {
}

export function getCities(api, language, init) {
return fetch(`${api}city/?language=${language}&fields=id,name&published=true&page_size=999`, init);
return getAllPaginatedResults(`${api}city/?language=${language}&fields=id,name&published=true`, init);
}

export function getThemes(api, language, portals, init) {
Expand All @@ -72,3 +73,15 @@ export function getSources(api, language, init) {
export function getSignages(api, language, trekId, init) {
return fetch(`${api}signage/?language=${language}&near_trek=${trekId}&fields=id,geometry,name&published=true&page_size=999`, init);
}

export function getTrekNetwork(api, language, init) {
return fetch(`${api}trek_network/?language=${language}&published=true&fields=id,label,pictogram&page_size=999`, init);
}

export function getTrekAccessibility(api: string, language: string, portals: string, init: RequestInit): any {
return fetch(`${api}trek_accessibility/?language=${language}${portals ? '&portals='.concat(portals) : ''}&fields=id,name,pictogram&published=true&page_size=999`, init);
}

export function getLabel(api: string, language: string, portals: string, init: RequestInit) {
return fetch(`${api}label/?language=${language}${portals ? '&portals='.concat(portals) : ''}&fields=id,name,advice,pictogram,filter&published=true&page_size=999`, init);
}
8 changes: 4 additions & 4 deletions src/store/grw-outdoor-course-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Build, Component, h, Host, Prop } from '@stencil/core';
import { getDataInStore, handleOfflineProperty } from 'services/grw-db.service';
import { getOutdoorCourse, getOutdoorCourseTypes, getPoisNearCourse } from 'services/outdoor-courses.service';
import { getTouristicContentsNearOutdoorCourse } from 'services/touristic-contents.service';
import { getTouristicEventsNearOutdoorCourse } from 'services/touristic-events.service';
import { getTouristicContentCategory, getTouristicContentsNearOutdoorCourse } from 'services/touristic-contents.service';
import { getTouristicEventsNearOutdoorCourse, getTouristicEventType } from 'services/touristic-events.service';
import { getCities, getDistricts, getThemes } from 'services/treks.service';
import state from 'store/store';
import { OutdoorCourse } from 'types/types';
Expand Down Expand Up @@ -76,9 +76,9 @@ export class GrwOutdoorCourseProvider {
requests.push(!state.themes ? getThemes(state.api, state.language, this.portals, this.init) : new Response('null'));
requests.push(!state.outdoorCourseTypes ? getOutdoorCourseTypes(state.api, state.language, this.init) : new Response('null'));
requests.push(getTouristicContentsNearOutdoorCourse(state.api, state.language, this.outdoorCourseId, this.init));
requests.push(fetch(`${state.api}touristiccontent_category/?language=${state.language}&published=true&fields=id,label,pictogram&page_size=999`, this.init));
requests.push(getTouristicContentCategory(state.api, state.language, null, this.init));
requests.push(getTouristicEventsNearOutdoorCourse(state.api, state.language, this.outdoorCourseId, this.init));
requests.push(fetch(`${state.api}touristicevent_type/?language=${state.language}&published=true&fields=id,type,pictogram&page_size=999`, this.init));
requests.push(getTouristicEventType(state.api, state.language, null, this.init));
requests.push(getPoisNearCourse(state.api, state.language, this.outdoorCourseId, this.init));
requests.push(fetch(`${state.api}poi_type/?language=${state.language}&fields=id,pictogram`, this.init));
requests.push(getOutdoorCourse(state.api, state.language, this.outdoorCourseId, this.init));
Expand Down
8 changes: 4 additions & 4 deletions src/store/grw-outdoor-site-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { OutdoorSite } from 'components';
import { getDataInStore, handleOfflineProperty } from 'services/grw-db.service';
import { getOutdoorCourse, getOutdoorCourseTypes } from 'services/outdoor-courses.service';
import { getOutdoorPractices, getOutdoorSite, getOutdoorSiteTypes, getPoisNearSite } from 'services/outdoor-sites.service';
import { getTouristicContentsNearOutdoorSite } from 'services/touristic-contents.service';
import { getTouristicEventsNearOutdoorSite } from 'services/touristic-events.service';
import { getTouristicContentCategory, getTouristicContentsNearOutdoorSite } from 'services/touristic-contents.service';
import { getTouristicEventsNearOutdoorSite, getTouristicEventType } from 'services/touristic-events.service';
import { getCities, getDistricts, getInformationsDesks, getSources, getThemes } from 'services/treks.service';
import state from 'store/store';
import { imagesRegExp, setFilesFromStore } from 'utils/utils';
Expand Down Expand Up @@ -112,9 +112,9 @@ export class GrwOutdoorSiteProvider {
requests.push(!state.outdoorRatingsScale ? fetch(`${state.api}outdoor_ratingscale/?language=${state.language}&fields=id,name`, this.init) : new Response('null'));
requests.push(getInformationsDesks(state.api, state.language, this.init));
requests.push(getTouristicContentsNearOutdoorSite(state.api, state.language, this.outdoorSiteId, this.init));
requests.push(fetch(`${state.api}touristiccontent_category/?language=${state.language}&published=true&fields=id,label,pictogram&page_size=999`, this.init));
requests.push(getTouristicContentCategory(state.api, state.language, null, this.init));
requests.push(getTouristicEventsNearOutdoorSite(state.api, state.language, this.outdoorSiteId, this.init));
requests.push(fetch(`${state.api}touristicevent_type/?language=${state.language}&published=true&fields=id,type,pictogram&page_size=999`, this.init));
requests.push(getTouristicEventType(state.api, state.language, null, this.init));
requests.push(getPoisNearSite(state.api, state.language, this.outdoorSiteId, this.init));
requests.push(fetch(`${state.api}poi_type/?language=${state.language}&fields=id,pictogram`, this.init));
requests.push(!state.outdoorCourseTypes ? getOutdoorCourseTypes(state.api, state.language, this.init) : new Response('null'));
Expand Down
16 changes: 4 additions & 12 deletions src/store/grw-touristic-content-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Build, Component, h, Host, Prop } from '@stencil/core';
import { getAllDataInStore, getDataInStore } from 'services/grw-db.service';
import { getTouristicContent } from 'services/touristic-contents.service';
import { getTouristicContent, getTouristicContentCategory } from 'services/touristic-contents.service';
import { getCities } from 'services/treks.service';
import state from 'store/store';
import { TouristicContent } from 'types/types';

Expand Down Expand Up @@ -48,17 +49,8 @@ export class GrwTouristicContentProvider {

handleOnlineTouristicContent() {
const requests = [];
requests.push(!state.cities ? fetch(`${state.api}city/?language=${state.language}&fields=id,name&published=true&page_size=999`, this.init) : new Response('null'));
requests.push(
!state.touristicContentCategories
? fetch(
`${state.api}touristiccontent_category/?language=${state.language}${
this.portals ? '&portals='.concat(this.portals) : ''
}&published=true&fields=id,label,pictogram&page_size=999`,
this.init,
)
: new Response('null'),
);
requests.push(!state.cities ? getCities(state.api, state.language, this.init) : new Response('null'));
requests.push(!state.touristicContentCategories ? getTouristicContentCategory(state.api, state.language, this.portals, this.init) : new Response('null'));
try {
Promise.all([...requests, getTouristicContent(state.api, state.language, this.touristicContentId, this.init)])
.then(responses => Promise.all(responses.map(response => response.json())))
Expand Down
Loading

0 comments on commit 6bd289e

Please sign in to comment.