Skip to content

Commit

Permalink
remove load more mechanism in meso view
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Dec 22, 2023
1 parent c5b94d2 commit a8b1412
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/routes/mesocycles/view/[mesocycleId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ export const load = async ({ locals, params, fetch }) => {
let workouts: WithSerializedId<Workout>[] = [];
let workoutsCount = 0;
const getAllWorkoutsResponse = await fetch(
"/api/workouts/getAllWorkouts?page=0&mesocycleId=" + mesocycle._id
"/api/workouts/getAllWorkouts?mesocycleId=" + mesocycle._id
);
if (getAllWorkoutsResponse.ok) {
({ workouts, workoutsCount } = await getAllWorkoutsResponse.json());
}
workouts.reverse();

return { mesocycle, mesocycleTemplate, workouts, workoutsCount };
};
23 changes: 0 additions & 23 deletions src/routes/mesocycles/view/[mesocycleId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@
await goto("/mesocycles");
redirecting = false;
}
let loadingMore = false;
async function loadMore() {
const pageToLoad = Math.floor(workouts.length / 10);
let params = "?page=" + pageToLoad + "&mesocycleId=" + data.mesocycle._id;
loadingMore = true;
const response = await fetch("/api/workouts/getAllWorkouts" + params);
const { workouts: newWorkouts, workoutsCount: newCount } = await response.json();
loadingMore = false;
workoutsCount = newCount;
workouts = [...workouts, ...newWorkouts];
}
</script>

<MyModal onClose={closeMesocycleStoppedModal} bind:dialogElement={modal} bind:title={modalTitle}>
Expand Down Expand Up @@ -122,15 +108,6 @@
</div>
</a>
{/each}
{#if data.workouts.length < data.workoutsCount}
<button class="btn bg-base-200/50 btn-sm" on:click={loadMore}>
{#if loadingMore}
<span class="loading loading-bars"></span>
{:else}
Load more
{/if}
</button>
{/if}
{:else}
<div class="btn btn-sm btn-block text-error">No workouts found</div>
{/if}
Expand Down

0 comments on commit a8b1412

Please sign in to comment.