fix chapter list not calling onlineFetch=true

This commit is contained in:
Aria Moradi
2021-09-27 18:29:05 +03:30
parent 9a89346c01
commit cd86e160ca
2 changed files with 8 additions and 5 deletions

View File

@@ -107,6 +107,7 @@ export default function CategorySelect(props: IProps) {
/> />
)} )}
label={categoryInfo.category.name} label={categoryInfo.category.name}
key={categoryInfo.category.id}
/> />
))} ))}
</FormGroup> </FormGroup>

View File

@@ -58,9 +58,10 @@ export default function Manga() {
const [manga, setManga] = useState<IManga>(); const [manga, setManga] = useState<IManga>();
const [chapters, setChapters] = useState<IChapter[]>([]); const [chapters, setChapters] = useState<IChapter[]>([]);
const [fetchedChapters, setFetchedChapters] = useState(false);
const [noChaptersFound, setNoChaptersFound] = useState(false); const [noChaptersFound, setNoChaptersFound] = useState(false);
const [chapterUpdateTriggerer, setChapterUpdateTriggerer] = useState(0); const [chapterUpdateTriggerer, setChapterUpdateTriggerer] = useState(0);
const [fetchedOnline, setFetchedOnline] = useState(false);
const [fetchedOffline, setFetchedOffline] = useState(false);
const [, setWsClient] = useState<WebSocket>(); const [, setWsClient] = useState<WebSocket>();
const [{ queue }, setQueueState] = useState<IQueue>(initialQueue); const [{ queue }, setQueueState] = useState<IQueue>(initialQueue);
@@ -110,18 +111,19 @@ export default function Manga() {
}, [manga]); }, [manga]);
useEffect(() => { useEffect(() => {
const shouldFetchOnline = fetchedChapters && chapterUpdateTriggerer === 0; const shouldFetchOnline = fetchedOffline && !fetchedOnline;
client.get(`/api/v1/manga/${id}/chapters?onlineFetch=${shouldFetchOnline}`) client.get(`/api/v1/manga/${id}/chapters?onlineFetch=${shouldFetchOnline}`)
.then((response) => response.data) .then((response) => response.data)
.then((data) => { .then((data) => {
if (data.length === 0 && fetchedChapters) { if (data.length === 0 && fetchedOffline) {
makeToast('No chapters found', 'warning'); makeToast('No chapters found', 'warning');
setNoChaptersFound(true); setNoChaptersFound(true);
} }
setChapters(data); setChapters(data);
}) })
.then(() => setFetchedChapters(true)); .then(() => { setFetchedOffline(true); setFetchedOnline(shouldFetchOnline); });
}, [chapters.length, fetchedChapters, chapterUpdateTriggerer]); }, [chapters.length, fetchedOffline, chapterUpdateTriggerer]);
return ( return (
<div className={classes.root}> <div className={classes.root}>