This commit is contained in:
Bastian Meissner 2020-06-26 17:30:39 +02:00
parent b307a12382
commit b532a39be5

View file

@ -5,7 +5,7 @@ import {
handleResponse, handleResponse,
Headline, Headline,
ListContainer, ListContainer,
ErrorMessage, ErrorMessage
} from './elements'; } from './elements';
const useAppData = () => { const useAppData = () => {
@ -15,10 +15,10 @@ const useAppData = () => {
? fetch('/data/apps.json').then(handleResponse) ? fetch('/data/apps.json').then(handleResponse)
: import('./data/apps.json') : import('./data/apps.json')
) )
.then((jsonResponse) => { .then(jsonResponse => {
setAppData({ ...jsonResponse, error: false }); setAppData({ ...jsonResponse, error: false });
}) })
.catch((error) => { .catch(error => {
setAppData({ categories: [], apps: [], error: error.message }); setAppData({ categories: [], apps: [], error: error.message });
}); });
}, []); }, []);
@ -31,7 +31,7 @@ const useAppData = () => {
const AppList = () => { const AppList = () => {
const { const {
appData: { categories, apps, error }, appData: { categories, apps, error }
} = useAppData(); } = useAppData();
return ( return (
<ListContainer> <ListContainer>
@ -45,10 +45,12 @@ const AppList = () => {
items={items} items={items}
/> />
))} ))}
<AppCategory {apps && (
name={categories ? 'Uncategorized apps' : null} <AppCategory
items={apps} name={categories ? 'Uncategorized apps' : null}
/> items={apps}
/>
)}
</ListContainer> </ListContainer>
); );
}; };