This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
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
1 parent
416c65c
commit 9b7dae0
Showing
4 changed files
with
160 additions
and
27 deletions.
There are no files selected for viewing
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
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,23 +1,85 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { QueryClient, QueryClientProvider, useQuery } from "react-query"; | ||
|
||
import "./App.css"; | ||
|
||
const fetchTestDatas = function () { | ||
fetch("/api/v1/tests") | ||
.then((res) => res.json()) | ||
.then((response) => { | ||
console.log("Test data response", response); | ||
}) | ||
.catch((error) => { | ||
console.log("Error while fetching test data", error); | ||
}); | ||
}; | ||
const queryClient = new QueryClient(); | ||
|
||
// function getTasks() { | ||
// return fetch("/api/tasks").then((response) => { | ||
// if (response.ok) { | ||
// return; | ||
// } | ||
// const result = response.json(); | ||
// if (result.response) { | ||
// return result.response; | ||
// } | ||
// }); | ||
// } | ||
|
||
// function useTasks() {} | ||
|
||
function App() { | ||
// const [tasks, setTasks] = useState([]); | ||
|
||
// useEffect(() => { | ||
// // let mounted = true; | ||
|
||
// getTasks().then((result) => { | ||
// setTasks(result); | ||
// }); | ||
|
||
// return () => (mounted = false); | ||
// }, []); | ||
// console.log(tasks); | ||
|
||
return ( | ||
<div className="App"> | ||
<button onClick={fetchTestDatas}>Fetch Test Data</button> | ||
<QueryClientProvider client={queryClient}> | ||
<MainPage /> | ||
</QueryClientProvider> | ||
); | ||
} | ||
|
||
function MainPage() { | ||
const { isLoading, error, data } = useQuery("tasks", () => | ||
fetch("/api/tasks").then((response) => response.json()) | ||
); | ||
const allTasks = data ? data.data : []; | ||
// XXX handle filtering | ||
const filters: null[] = []; | ||
const filteredTasks = allTasks; | ||
console.log("data [hvuqlfbu]:", data); // eslint-disable-line no-console | ||
console.log("error [lvzmsvfx]:", error); // eslint-disable-line no-console | ||
console.log("isLoading [rbxjtyqx]:", isLoading); // eslint-disable-line no-console | ||
|
||
return ( | ||
<div className="flex flex-wrap text-lg"> | ||
<div className="sticky top-0 bg-gray-300 card md:static"> | ||
<div className="py-2"> | ||
{allTasks.length} tasks ({filteredTasks.length} shown) | ||
</div> | ||
<div className="flex-grow py-2"> | ||
{filters && <Filters filters={filters} />} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function Filters({ filters }: { filters: null[] }) { | ||
// XXX add rest here | ||
return ( | ||
<> | ||
Filters: | ||
{filters.map((filter) => ( | ||
<FilterPill filter={filter} /> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
function FilterPill({ filter }: { filter: null }) { | ||
return filter; | ||
} | ||
|
||
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