Skip to content

Commit ac41aaf

Browse files
authored
Merge pull request #81 from React-ChatBotify/theme-fetch-fix
fix theme fetch logic
2 parents f34e073 + 3cdfc06 commit ac41aaf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/pages/Themes.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'react-loading-skeleton/dist/skeleton.css';
44

55
import ThemeCard from '../components/Themes/ThemeCard';
66
import SearchBar from '../components/SearchBar/SearchBar';
7-
import useFetchData from '../hooks/useFetchThemes';
7+
import useFetchData, { fetchThemesFromApi } from '../hooks/useFetchThemes';
88
import { Endpoints } from '../constants/Endpoints';
99
import { useSearchParams } from 'react-router-dom';
1010
import ThemePreview from '../components/Themes/ThemePreview';
@@ -54,9 +54,14 @@ const Themes: React.FC = () => {
5454
}
5555
const focusedThemeObject = themes.find(theme => theme.id === focusedThemeId);
5656
if (!focusedThemeObject) {
57-
return
57+
//check if it exists in the list we havent search for yet
58+
fetchThemesFromApi(undefined, 1, 1, focusedThemeId).then(
59+
themes => setFocusedTheme(themes[0])
60+
)
61+
}else {
62+
setFocusedTheme(focusedThemeObject)
5863
}
59-
setFocusedTheme(focusedThemeObject)
64+
6065

6166
}, [themes])
6267

0 commit comments

Comments
 (0)