Fetch latest track data from tracker only once
Everytime the data was updated, the array changed and triggered the useEffect again, resulting in another request to get the latest data from the tracker
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import Box from '@mui/material/Box';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import DialogContent from '@mui/material/DialogContent';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
@@ -68,7 +68,13 @@ export const TrackManga = ({ manga }: { manga: MangaIdInfo & Pick<MangaType, 'ti
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
const fetchedLatestTrackDataRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!mangaTrackRecords.length || fetchedLatestTrackDataRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetchedLatestTrackDataRef.current = true;
|
||||
Promise.all(
|
||||
mangaTrackRecords.map((trackRecord) => requestManager.fetchTrackBind(trackRecord.id).response),
|
||||
).catch(() => makeToast(t('tracking.error.label.could_not_fetch_track_info'), 'error'));
|
||||
|
||||
Reference in New Issue
Block a user