(props)
| 80 | }; |
| 81 | |
| 82 | const FavoriteAnimals = (props) => { |
| 83 | const firestore = useFirestore(); |
| 84 | const animalsCollection = collection(firestore, 'animals'); |
| 85 | const [isAscending, setIsAscending] = useState(true); |
| 86 | const animalsQuery = query(animalsCollection, orderBy('commonName', isAscending ? 'asc' : 'desc')); |
| 87 | const [isPending, startTransition] = useTransition(); |
| 88 | |
| 89 | const toggleSort = () => { |
| 90 | startTransition(() => { |
| 91 | setIsAscending(!isAscending); |
| 92 | }); |
| 93 | }; |
| 94 | |
| 95 | const addAnimal = () => { |
| 96 | const possibleAnimals = ['Dog', 'Cat', 'Iguana', 'Zebra']; |
| 97 | const selectedAnimal = possibleAnimals[Math.floor(Math.random() * possibleAnimals.length)]; |
| 98 | addDoc(animalsCollection, { commonName: selectedAnimal }); |
| 99 | }; |
| 100 | |
| 101 | const removeAnimal = (id) => deleteDoc(doc(animalsCollection, id)); |
| 102 | |
| 103 | return ( |
| 104 | <> |
| 105 | <WideButton label="Sort" onClick={toggleSort} /> |
| 106 | <React.Suspense fallback="loading..."> |
| 107 | <List query={animalsQuery} removeAnimal={removeAnimal} /> |
| 108 | </React.Suspense> |
| 109 | <WideButton |
| 110 | label="Add Animal" |
| 111 | onClick={() => { |
| 112 | addAnimal(); |
| 113 | }} |
| 114 | /> |
| 115 | </> |
| 116 | ); |
| 117 | }; |
| 118 | |
| 119 | function FirestoreWrapper({ children }) { |
| 120 | const { data: firestoreInstance } = useInitFirestore(async (firebaseApp) => { |
nothing calls this directly
no test coverage detected