Skip to content

Commit

Permalink
fixed when spinner stops just after first offline chapter fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMoradi committed May 15, 2021
1 parent bab25f9 commit 4bf3c12
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions webUI/react/src/screens/Manga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ const useStyles = makeStyles((theme: Theme) => ({
},
}));

// const InnerItem = React.memo(({ chapters, index }: any) => (
// <ChapterCard chapter={chapters[index]} />
// ));

export default function Manga() {
const classes = useStyles();
const theme = useTheme();
Expand All @@ -60,6 +56,7 @@ export default function Manga() {
const [manga, setManga] = useState<IManga>();
const [chapters, setChapters] = useState<IChapter[]>([]);
const [fetchedChapters, setFetchedChapters] = useState(false);
const [noChaptersFound, setNoChaptersFound] = useState(false);
const [chapterUpdateTriggerer, setChapterUpdateTriggerer] = useState(0);

function triggerChaptersUpdate() {
Expand All @@ -84,20 +81,13 @@ export default function Manga() {
.then((data) => {
if (data.length === 0 && fetchedChapters) {
makeToast('No chapters found', 'warning');
setNoChaptersFound(true);
}
setChapters(data);
})
.then(() => setFetchedChapters(true));
}, [chapters.length, fetchedChapters, chapterUpdateTriggerer]);

// const itemContent = (index:any) => <InnerItem chapters={chapters} index={index} />;
const itemContent = (index:any) => (
<ChapterCard
chapter={chapters[index]}
triggerChaptersUpdate={triggerChaptersUpdate}
/>
);

return (
<div className={classes.root}>
<LoadingPlaceholder
Expand All @@ -107,15 +97,20 @@ export default function Manga() {
/>

<LoadingPlaceholder
shouldRender={chapters.length > 0 || fetchedChapters}
shouldRender={chapters.length > 0 || noChaptersFound}
>
<Virtuoso
style={{ // override Virtuoso default values and set them with class
height: 'undefined',
}}
className={classes.chapters}
totalCount={chapters.length}
itemContent={itemContent}
itemContent={(index:number) => (
<ChapterCard
chapter={chapters[index]}
triggerChaptersUpdate={triggerChaptersUpdate}
/>
)}
useWindowScroll={window.innerWidth < 960}
overscan={window.innerHeight * 0.5}
/>
Expand Down

0 comments on commit 4bf3c12

Please sign in to comment.