mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Remove fetchPaginated and migrate viewer.js to viewer-index.js in webpack
This commit is contained in:
@ -123,37 +123,3 @@ function updateQueryString(key, value, action = History.REPLACE, url = null) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO : If one day a test workflow is made for JS in this project
|
||||
// please test this function. A all cost.
|
||||
/**
|
||||
* Given a paginated endpoint, fetch all the items of this endpoint,
|
||||
* performing multiple API calls if necessary.
|
||||
* @param {string} url The paginated endpoint to fetch
|
||||
* @return {Promise<Object[]>}
|
||||
*/
|
||||
// biome-ignore lint/correctness/noUnusedVariables: used in other scripts
|
||||
async function fetchPaginated(url) {
|
||||
const maxPerPage = 199;
|
||||
const paginatedUrl = new URL(url, document.location.origin);
|
||||
paginatedUrl.searchParams.set("page_size", maxPerPage.toString());
|
||||
paginatedUrl.searchParams.set("page", "1");
|
||||
|
||||
const firstPage = await (await fetch(paginatedUrl)).json();
|
||||
const results = firstPage.results;
|
||||
|
||||
const nbPictures = firstPage.count;
|
||||
const nbPages = Math.ceil(nbPictures / maxPerPage);
|
||||
|
||||
if (nbPages > 1) {
|
||||
const promises = [];
|
||||
for (let i = 2; i <= nbPages; i++) {
|
||||
paginatedUrl.searchParams.set("page", i.toString());
|
||||
promises.push(
|
||||
fetch(paginatedUrl).then((res) => res.json().then((json) => json.results)),
|
||||
);
|
||||
}
|
||||
results.push(...(await Promise.all(promises)).flat());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import { picturesFetchPictures } from "#openapi";
|
||||
* Load user picture page with a nice download bar
|
||||
* @param {PicturePageConfig} Configuration
|
||||
**/
|
||||
window.window.loadPicturePage = (config) => {
|
||||
window.loadPicturePage = (config) => {
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("user_pictures", () => ({
|
||||
isDownloading: false,
|
||||
|
@ -19,6 +19,8 @@ type PaginatedEndpoint<T> = <ThrowOnError extends boolean = false>(
|
||||
options?: Options<PaginatedRequest, ThrowOnError>,
|
||||
) => RequestResult<PaginatedResponse<T>, unknown, ThrowOnError>;
|
||||
|
||||
// TODO : If one day a test workflow is made for JS in this project
|
||||
// please test this function. A all cost.
|
||||
export const paginated = async <T>(
|
||||
endpoint: PaginatedEndpoint<T>,
|
||||
options?: PaginatedRequest,
|
||||
|
Reference in New Issue
Block a user