From 162961b5602fd67fec2c82ea199ff0c7a82b76cc Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sat, 20 Feb 2021 02:28:55 +0330 Subject: [PATCH] fix tabs --- webUI/react/src/screens/Library.tsx | 48 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/webUI/react/src/screens/Library.tsx b/webUI/react/src/screens/Library.tsx index 4ca3180..30e24fe 100644 --- a/webUI/react/src/screens/Library.tsx +++ b/webUI/react/src/screens/Library.tsx @@ -46,37 +46,38 @@ export default function Library() { useEffect(() => { setTitle('Library'); }, []); - useEffect(() => { + // eslint-disable-next-line no-var + var newTabs: IMangaCategory[] = []; fetch('http://127.0.0.1:4567/api/v1/library') .then((response) => response.json()) .then((data: IManga[]) => { + // if some manga with no category exist, they will be added under a virtual category if (data.length > 0) { - setTabs([ - ...tabs, + newTabs = [ { category: { name: 'Default', isLanding: true, order: 0, id: 0, }, mangas: data, }, - ]); + ]; // will set state on the next fetch } - }); + }) + .then( + () => { + fetch('http://127.0.0.1:4567/api/v1/category') + .then((response) => response.json()) + .then((data: ICategory[]) => { + const mangaCategories = data.map((category) => ({ + category, + mangas: [] as IManga[], + })); + setTabs([...newTabs, ...mangaCategories]); + }); + }, + ); }, []); - - useEffect(() => { - fetch('http://127.0.0.1:4567/api/v1/category') - .then((response) => response.json()) - .then((data: ICategory[]) => { - const mangaCategories = data.map((category) => ({ - category, - mangas: [] as IManga[], - })); - setTabs([...tabs, ...mangaCategories]); - }); - }, []); - // eslint-disable-next-line max-len const handleTabChange = (event: React.ChangeEvent<{}>, newValue: number) => setTabNum(newValue); @@ -84,8 +85,8 @@ export default function Library() { if (tabs.length > 1) { const tabDefines = tabs.map((tab) => ()); - const tabBodies = tabs.map((tab) => ( - + const tabBodies = tabs.map((tab, index) => ( + )); + + // 160px is min-width for viewport width of >600 + const scrollableTabs = window.innerWidth < tabs.length * 160; toRender = ( <> {tabDefines}