added loading states to category and language filters

This commit is contained in:
namushka 2023-11-09 11:17:11 +03:00
parent 8fb2b07323
commit 9ea88ac524
3 changed files with 13 additions and 7 deletions

View File

@ -40,9 +40,11 @@ const CategoryFilter = ({
fetchCategoriesOfCategoryType,
}) => {
const [menuItems, setMenuItems] = useState([]);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
(async () => {
setIsLoading(true);
let newMenuItems = await fetchCategoryTypes();
const categoryPromises = newMenuItems.map(
@ -68,11 +70,14 @@ const CategoryFilter = ({
categories: [],
}));
})
.finally(() => setMenuItems(newMenuItems));
.finally(() => {
setMenuItems(newMenuItems);
setIsLoading(false);
});
})();
}, []);
if (menuItems.length === 0) return null;
if (!isLoading && menuItems.length === 0) return null;
return (
<StyledCategoryFilterWrapper
@ -85,7 +90,8 @@ const CategoryFilter = ({
);
};
export default inject(({ oformsStore }) => ({
noLocales: oformsStore.oformLocales.length === 0,
noLocales:
oformsStore.oformLocales !== null && oformsStore.oformLocales?.length === 0,
fetchCategoryTypes: oformsStore.fetchCategoryTypes,
fetchCategoriesOfCategoryType: oformsStore.fetchCategoriesOfCategoryType,
}))(observer(CategoryFilter));

View File

@ -29,7 +29,7 @@ const LanguageFilter = ({
sectionScroll.scrollTop = 0;
};
if (oformLocales.length === 0) return null;
if (oformLocales !== null && oformLocales?.length === 0) return null;
return (
<Styled.LanguageFilter>
@ -63,7 +63,7 @@ const LanguageFilter = ({
selectedOption={{}}
advancedOptions={
<>
{oformLocales.map((locale) => (
{oformLocales?.map((locale) => (
<Styled.LanguageFilterItem
className={"language-item"}
key={locale}

View File

@ -32,7 +32,7 @@ class OformsStore {
currentCategory = null;
categoryTitles = [];
oformLocales = [];
oformLocales = null;
submitToGalleryTileIsVisible = !localStorage.getItem(
"submitToGalleryTileIsHidden"
@ -45,7 +45,7 @@ class OformsStore {
get defaultOformLocale() {
const userLocale = convertToLanguage(getCookie(LANGUAGE)) || "en";
return this.oformLocales.includes(userLocale) ? userLocale : "en";
return this.oformLocales?.includes(userLocale) ? userLocale : "en";
}
setOformFiles = (oformFiles) => (this.oformFiles = oformFiles);