diff --git a/.env b/.env
new file mode 100644
index 0000000..6a20770
--- /dev/null
+++ b/.env
@@ -0,0 +1 @@
+VITE_CFP_BASE_URL=http://cfp.localhost/api/conferences/
diff --git a/src/App.jsx b/src/App.jsx
index 8c1cd86..90deecb 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,11 +1,8 @@
import './App.css';
+import ScheduleLoader from './ScheduleLoader.jsx';
function App() {
-
- return (
- <>
- >
- );
+ return (
Please wait...
} + {error &&Error: {error}
} + {conferences && <> + + + >} + >); +} diff --git a/src/hooks/useCfpRequest.js b/src/hooks/useCfpRequest.js new file mode 100644 index 0000000..a2945a8 --- /dev/null +++ b/src/hooks/useCfpRequest.js @@ -0,0 +1,7 @@ +import useSWR from 'swr'; + +const fetcher = (...args) => fetch(...args).then(res => res.json()); + +export default function useCfpRequest(path = '') { + return useSWR(import.meta.env.VITE_CFP_BASE_URL.concat(path), fetcher); +} diff --git a/src/hooks/useConferences.js b/src/hooks/useConferences.js new file mode 100644 index 0000000..676a099 --- /dev/null +++ b/src/hooks/useConferences.js @@ -0,0 +1,17 @@ +import useCfpRequest from './useCfpRequest.js'; +import { useMemo } from 'react'; +import { dateSorter } from '../utils.js'; + +export default function useConferences() { + const { + data, + ...rest + } = useCfpRequest(); + + const conferences = useMemo(() => Array.isArray(data) ? data.sort(dateSorter('start_date')) : data, [data]); + + return { + conferences, + ...rest, + }; +} diff --git a/src/main.jsx b/src/main.jsx index 833c97f..c40899d 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -4,7 +4,7 @@ import App from './App.jsx'; import './index.css'; createRoot(document.getElementById('root')).render( -