Skip to content

Commit

Permalink
FullCourseList: fix take desync
Browse files Browse the repository at this point in the history
  • Loading branch information
makinbacon21 committed Nov 14, 2024
1 parent 1376615 commit 01c0612
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"use client";
import { Course, Prisma } from "@prisma/client";

import prisma from "../lib/prisma";
import { useEffect, useState } from "react";

import CourseCard from "./CourseCard";
import React from "react";
import { getCourses, getInitialCourses } from "../app/actions/getCourses";
import { getCourses } from "../app/actions/getCourses";
import { useInView } from "react-intersection-observer";
import { Skeleton } from "@nextui-org/react";

Expand All @@ -33,15 +32,18 @@ export function FullCourseList({
const { ref, inView } = useInView();

const loadMoreUsers = async () => {
if (inView) {
setCursor((cursor) => cursor + NUMBER_OF_USERS_TO_FETCH);
setTake((take) => take + NUMBER_OF_USERS_TO_FETCH);
}
// NOTE: if this isn't done every time we get a double take and a
// race condition desync, breaking isDone. Maybe we'll have better
// logic in the future.
setCursor((cursor) => cursor + NUMBER_OF_USERS_TO_FETCH);
setTake((take) => take + NUMBER_OF_USERS_TO_FETCH);

const apiCourses = await getCourses(take, cursor, query, term, dotw, stime);
console.log("apiCourses");
console.log(apiCourses);
if (apiCourses.length == 0 || apiCourses.length == courses.length) {
if (
inView &&
(apiCourses.length == 0 || apiCourses.length == courses.length)
) {
console.log("setting isDone true");
setIsDone(true);
} else {
setIsDone(false);
Expand Down

0 comments on commit 01c0612

Please sign in to comment.