From f383ab75afe3e0be976c13fb83ca5e7acdd04cac Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Wed, 8 May 2024 17:42:53 +1000 Subject: [PATCH] added loading spinners to the store --- src/interface/pages/Store.tsx | 39 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/interface/pages/Store.tsx b/src/interface/pages/Store.tsx index 951c5e74..e54466a1 100644 --- a/src/interface/pages/Store.tsx +++ b/src/interface/pages/Store.tsx @@ -42,19 +42,27 @@ const Store = () => { const [coverThemes, setCoverThemes] = useState([]); const [installingThemes, setInstallingThemes] = useState([]); const [currentThemes, setCurrentThemes] = useState([]); + const [loading, setLoading] = useState(true); + + const fetchThemes = async () => { + try { + const response = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes.json?nocache=${(new Date()).getTime()}`, { cache: 'no-store' }); + const data: ThemesResponse = await response.json(); + setGridThemes(data.themes); + // Select up to 3 random themes to display in coverThemes + const shuffled = [...data.themes].sort(() => 0.5 - Math.random()); + setCoverThemes(shuffled.slice(0, 3)); + setLoading(false); + } catch (error) { + console.error('Failed to fetch themes', error); + // Retry after 5 seconds + setTimeout(fetchThemes, 5000); + } + }; useEffect(() => { - fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes.json?nocache=${(new Date()).getTime()}`, { cache: 'no-store' }) - .then(response => response.json()) - .then((data: ThemesResponse) => { - setGridThemes(data.themes); - // Select up to 3 random themes to display in coverThemes - const shuffled = [...data.themes].sort(() => 0.5 - Math.random()); - setCoverThemes(shuffled.slice(0, 3)); - }) - .catch(error => console.error('Failed to fetch themes', error)); - (async () => { + fetchThemes(); const availableThemes = await localforage.getItem('availableThemes') as string[]; setCurrentThemes(availableThemes) })(); @@ -97,11 +105,16 @@ const Store = () => { } return ( -
+
-
+ {/* loader */} +
+ +
+ +
{ ))}
- {filteredThemes.length == 0 && ( + {filteredThemes.length == 0 && !loading && (

That doesnt exist! 😭😭😭

Sorry, we couldn’t find the theme you’re looking for. Maybe... you could create it?