forked from btholt/citr-v8-project
-
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.
uncontrolled forms, added context css to every style.css, and rebased…
… the later steps on uncontrolled forms
- Loading branch information
Showing
113 changed files
with
7,515 additions
and
343 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
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
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
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,17 @@ | ||
async function fetchBreedList({ queryKey }) { | ||
const animal = queryKey[1]; | ||
|
||
if (!animal) return []; | ||
|
||
const res = await fetch( | ||
`http://pets-v2.dev-apis.com/breeds?animal=${animal}` | ||
); | ||
|
||
if (!res.ok) { | ||
throw new Error(`breeds ${animal} fetch not ok`); | ||
} | ||
|
||
return res.json(); | ||
} | ||
|
||
export default fetchBreedList; |
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 |
---|---|---|
|
@@ -340,3 +340,9 @@ header { | |
display: flex; | ||
padding: 15px; | ||
} | ||
|
||
form .pet { | ||
float: unset; | ||
margin: 0 auto; | ||
} | ||
|
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,32 +1,8 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
const localCache = {}; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import fetchBreedList from "./fetchBreedList"; | ||
|
||
export default function useBreedList(animal) { | ||
const [breedList, setBreedList] = useState([]); | ||
const [status, setStatus] = useState("unloaded"); | ||
|
||
useEffect(() => { | ||
if (!animal) { | ||
setBreedList([]); | ||
} else if (localCache[animal]) { | ||
setBreedList(localCache[animal]); | ||
} else { | ||
requestBreedList(); | ||
} | ||
|
||
async function requestBreedList() { | ||
setBreedList([]); | ||
setStatus("loading"); | ||
const res = await fetch( | ||
`http://pets-v2.dev-apis.com/breeds?animal=${animal}` | ||
); | ||
const json = await res.json(); | ||
localCache[animal] = json.breeds || []; | ||
setBreedList(localCache[animal]); | ||
setStatus("loaded"); | ||
} | ||
}, [animal]); | ||
const results = useQuery(["breeds", animal], fetchBreedList); | ||
|
||
return [breedList, status]; | ||
return [results?.data?.breeds ?? [], results.status]; | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useParams } from "react-router-dom"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { RingLoader } from "react-spinners"; | ||
import fetchPet from "./fetchPet"; | ||
|
||
const Details = () => { | ||
const { id } = useParams(); | ||
const results = useQuery(["details", id], fetchPet); | ||
|
||
if (results.isLoading) { | ||
return ( | ||
<div className="loading-pane"> | ||
<RingLoader size={250} /> | ||
</div> | ||
); | ||
} | ||
|
||
const pet = results.data.pets[0]; | ||
|
||
return ( | ||
<div className="details"> | ||
<div> | ||
<h1>{pet.name}</h1> | ||
<h2>{`${pet.animal} — ${pet.breed} — ${pet.city}, ${pet.state}`}</h2> | ||
<button>Adopt {pet.name}</button> | ||
<p>{pet.description}</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Details; |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
async function fetchBreedList({ queryKey }) { | ||
const animal = queryKey[1]; | ||
|
||
if (!animal) return []; | ||
|
||
const res = await fetch( | ||
`http://pets-v2.dev-apis.com/breeds?animal=${animal}` | ||
); | ||
|
||
if (!res.ok) { | ||
throw new Error(`breeds ${animal} fetch not ok`); | ||
} | ||
|
||
return res.json(); | ||
} | ||
|
||
export default fetchBreedList; |
File renamed without changes.
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,13 @@ | ||
async function fetchSearch({ queryKey }) { | ||
const { animal, location, breed } = queryKey[1]; | ||
const res = await fetch( | ||
`http://pets-v2.dev-apis.com/pets?animal=${animal}&location=${location}&breed=${breed}` | ||
); | ||
|
||
if (!res.ok) | ||
throw new Error(`pet search not okay: ${animal}, ${location}, ${breed}`); | ||
|
||
return res.json(); | ||
} | ||
|
||
export default fetchSearch; |
File renamed without changes.
Oops, something went wrong.