fetches other data when cat is set.

This commit is contained in:
moist-webDev 2023-06-08 21:09:32 -04:00
parent c8fba938d5
commit 48fc498a5e
1 changed files with 16 additions and 6 deletions

22
App.tsx
View File

@ -50,9 +50,9 @@ export default function App() {
let [showBack, setShowBack] = useState(''); let [showBack, setShowBack] = useState('');
const [movies, setMovies] = useState([]); const [movies, setMovies] = useState([]);
const [shows, setShows] = useState([]); const [shows, setShows] = useState([]);
const [selCat, setSelCat] = useState({}); const [selCat, setSelCat] = useState({id:0});
const [otherCategories, setOtherCategories] = useState([]); const [otherCategories, setOtherCategories] = useState([]);
const [other, setOther] = useState([]); const [others, setOthers] = useState([]);
@ -81,6 +81,16 @@ export default function App() {
} }
fetchData() fetchData()
}, []); }, []);
useEffect(() => {
const fetchData = async () => {
const other = await db.from('others').select().eq({category: selCat.id});
if (other.data) {
setOthers(other.data);
}
}
fetchData()
}, [selCat]);
const changeTheme = async (mode:string ) => { const changeTheme = async (mode:string ) => {
switch(mode) { switch(mode) {
@ -122,19 +132,19 @@ export default function App() {
setMovies([]); setMovies([]);
setShows([]); setShows([]);
setOtherCategories([]); setOtherCategories([]);
setOther([]); setOthers([]);
} }
return ( return (
<View style={{...styles.mainContainer, backgroundColor: theme.background}}> <View style={{...styles.mainContainer, backgroundColor: theme.background}}>
<NativeRouter> <NativeRouter>
<TitleBar title={title} theme={theme} showBack={showBack} setShowBack={setShowBack} setTitle={setTitle}/> <TitleBar title={title} theme={theme} showBack={showBack} setShowBack={setShowBack} setTitle={setTitle} setSelCat={setSelCat}/>
<Routes> <Routes>
<Route path="/" element={<Home theme={theme}/>}/> <Route path="/" element={<Home theme={theme}/>}/>
<Route path="/movies" element={<Movies theme={theme} movies={movies} setMovies={setMovies} />} /> <Route path="/movies" element={<Movies theme={theme} movies={movies} setMovies={setMovies} />} />
<Route path="/shows" element={<Shows theme={theme} shows={shows} setShows={setShows}/>}/> <Route path="/shows" element={<Shows theme={theme} shows={shows} setShows={setShows}/>}/>
<Route path="/categories" element={<OtherCat theme={theme} otherCategories={otherCategories} setOtherCategories={setOtherCategories} setSelCat={setSelCat} setShowBack={setShowBack} setTitle={setTitle}/>} /> <Route path="/categories" element={<OtherCat theme={theme} otherCategories={otherCategories} setOtherCategories={setOtherCategories} setSelCat={setSelCat} setShowBack={setShowBack} setTitle={setTitle} setOthers={setOthers}/>} />
<Route path="/other" element={<Other theme={theme} selCat={selCat} other={other} setOther={setOther}/>} /> <Route path="/other" element={<Other theme={theme} selCat={selCat} others={others} setOthers={setOthers} setSelCat={setSelCat}/>} />
<Route path="/settings" element={<Settings theme={theme} changeTheme={changeTheme} themeMode={themeMode} clearAll={clearAll}/>} /> <Route path="/settings" element={<Settings theme={theme} changeTheme={changeTheme} themeMode={themeMode} clearAll={clearAll}/>} />
</Routes> </Routes>
<Navbar theme={theme} setTitle={setTitle} setShowBack={setShowBack}/> <Navbar theme={theme} setTitle={setTitle} setShowBack={setShowBack}/>