Skip to content

Commit

Permalink
fixed compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefeu committed Mar 1, 2024
1 parent 377cb5f commit e9baf58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion web/src/app/api/simulations/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function getStepsFromRedis(id: string, prevStartIndex: number, chunkSize:
return [totalSteps, []];
}

var startIndex = 0;
let startIndex = 0;
if (totalSteps - prevStartIndex <= chunkSize) {
startIndex = -1; // last chunk, we start at index 0
}
Expand Down
10 changes: 4 additions & 6 deletions web/src/components/RenderLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Level, { LevelState } from '@/classes/Level';
import styles from './RenderLevel.module.css';
import React from 'react';
import { useEffect, useRef, useState } from 'react';
import Sidebar from './Sidebar';
import AgentSprite from './AgentSprite';
Expand Down Expand Up @@ -32,7 +33,6 @@ const RenderLevel: React.FC<{ simId: string }> = ({ simId }) => {
const [followAgent, setFollowAgent] = useState<Agent | undefined>(undefined);
const [levelState, setLevelState] = useState<LevelState>({ stepId: 0, substepId: 0, agents: [] });
const [fetchIndex, setFetchIndex] = useState(0);
const [totalSteps, setTotalSteps] = useState(0);
const [initialFetchDone, setInitialFetchDone] = useState(false);
const chunkSize = 500; // Adjust chunk size as needed

Expand All @@ -42,12 +42,10 @@ const RenderLevel: React.FC<{ simId: string }> = ({ simId }) => {

const fetchData = async () => {
const [totalSteps, data] = await getData(simId, fetchIndex);
console.log(chunkSize);
setFetchIndex(fetchIndex + chunkSize);
console.log(totalSteps);

// Update totalSteps once
if (!initialFetchDone) {
setTotalSteps(totalSteps);
setInitialFetchDone(true);
}

Expand All @@ -59,14 +57,14 @@ const RenderLevel: React.FC<{ simId: string }> = ({ simId }) => {
};

useEffect(() => {
let isMounted = true;
// let isMounted = true;
if (!initialFetchDone) {
fetchData(); // Fetch immediately for the first time
} else {
const interval = setInterval(fetchData, 20000); // Subsequent fetches at 20-second intervals

return () => {
isMounted = false;
// isMounted = false;
clearInterval(interval);
};
}
Expand Down

0 comments on commit e9baf58

Please sign in to comment.