diff --git a/src/components/manga/CategorySelect.tsx b/src/components/manga/CategorySelect.tsx index 6265c3a5..22bcb1b4 100644 --- a/src/components/manga/CategorySelect.tsx +++ b/src/components/manga/CategorySelect.tsx @@ -48,6 +48,7 @@ export default function CategorySelect(props: IProps) { client.get('/api/v1/category/') .then((response) => response.data) .then((data: ICategory[]) => { + if (data.length > 0 && data[0].name === 'Default') { data.shift(); } tmpCategoryInfos = data.map((category) => ({ category, selected: false })); }) .then(() => { diff --git a/src/screens/manga/Library.tsx b/src/screens/manga/Library.tsx index 5c9983d8..330051a2 100644 --- a/src/screens/manga/Library.tsx +++ b/src/screens/manga/Library.tsx @@ -56,45 +56,23 @@ export default function Library() { }; useEffect(() => { - Promise.all([ - client.get('/api/v1/library').then((response) => response.data), - client.get('/api/v1/category').then((response) => response.data), - ]) - .then( - ([libraryMangas, categories]) => { - const categoryTabs = categories.map((category) => ({ - category, - mangas: [] as IManga[], - isFetched: false, - })); + client.get('/api/v1/category') + .then((response) => response.data) + .then((categories: ICategory[]) => { + const categoryTabs = categories.map((category) => ({ + category, + mangas: [] as IManga[], + isFetched: false, + })); - if (libraryMangas.length > 0 || categoryTabs.length === 0) { - const defaultCategoryTab = { - category: { - name: 'Default', - default: true, - order: 0, - id: -1, - }, - mangas: libraryMangas, - isFetched: true, - }; - setTabs( - [defaultCategoryTab, ...categoryTabs], - ); - } else { - setTabs(categoryTabs); - setTabNum(1); - } - }, - ); + setTabs(categoryTabs); + }); }, []); - // console.log(client.defaults.baseURL); // fetch the current tab useEffect(() => { tabs.forEach((tab, index) => { - if (tab.category.order === tabNum && !tab.isFetched) { + if (index === tabNum && !tab.isFetched) { // eslint-disable-next-line @typescript-eslint/no-shadow client.get(`/api/v1/category/${tab.category.id}`) .then((response) => response.data) @@ -107,7 +85,11 @@ export default function Library() { }); } }); - }, [tabNum]); + }, [tabs.length, tabNum]); + + if (tabs.length === 0) { + return

Library is empty

; + } let toRender; if (tabs.length > 1) {