-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,31 @@ | ||
// import { useState } from 'react'; | ||
// import logo from './logo.svg'; | ||
// import './App.css'; | ||
import Banner from './components/Banner'; | ||
import CourseList from './components/CourseList'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { useJsonQuery } from './utilities/fetch'; | ||
|
||
const Main = () => { | ||
const [data, isLoading, error] = useJsonQuery('https://courses.cs.northwestern.edu/394/guides/data/cs-courses.php'); | ||
|
||
if (error) {return <h1>Error loading courses data: {`${error}`}</h1>}; | ||
if (isLoading) {return <h1>Loading courses data...</h1>}; | ||
if (!data) {return <h1>No course data found</h1>}; | ||
|
||
const schedule = { | ||
"title": "CS Courses for 2018-2019", | ||
"courses": { | ||
"F101" : { | ||
"term": "Fall", | ||
"number": "101", | ||
"meets" : "MWF 11:00-11:50", | ||
"title" : "Computer Science: Concepts, Philosophy, and Connections" | ||
}, | ||
"F110" : { | ||
"term": "Fall", | ||
"number": "110", | ||
"meets" : "MWF 10:00-10:50", | ||
"title" : "Intro Programming for non-majors" | ||
}, | ||
"S313" : { | ||
"term": "Spring", | ||
"number": "313", | ||
"meets" : "TuTh 15:30-16:50", | ||
"title" : "Tangible Interaction Design and Learning" | ||
}, | ||
"S314" : { | ||
"term": "Spring", | ||
"number": "314", | ||
"meets" : "TuTh 9:30-10:50", | ||
"title" : "Tech & Human Interaction" | ||
} | ||
} | ||
}; | ||
const App = () => { | ||
return ( | ||
<div> | ||
<Banner title={schedule.title}></Banner> | ||
<CourseList courses={schedule.courses}></CourseList> | ||
<Banner title={data.title}></Banner> | ||
<CourseList courses={data.courses}></CourseList> | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const App = () => ( | ||
<QueryClientProvider client={queryClient}> | ||
<div className="container"> | ||
<Main /> | ||
</div> | ||
</QueryClientProvider> | ||
); | ||
|
||
export default App; | ||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const fetchJson = async (url) => { | ||
const response = await fetch(url); | ||
if (!response.ok) throw response; | ||
return response.json(); | ||
}; | ||
|
||
export const useJsonQuery = (url) => { | ||
const { data, isLoading, error } = useQuery({ | ||
queryKey: [url], | ||
queryFn: () => fetchJson(url) | ||
}); | ||
|
||
return [ data, isLoading, error ]; | ||
}; |