diff --git a/src/App.jsx b/src/App.jsx index d59876f..b4a4507 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -8,7 +8,6 @@ import Login from './views/Login'; export function App() { const [isModalOpen, setIsModalOpen] = useState(false); - const [isLoading, setIsLoading] = useState(false); /** * This custom hook takes the path of a shopping list @@ -43,7 +42,7 @@ export function App() { * This custom hook takes our token and fetches the data for our list. * Check ./api/firestore.js for its implementation. */ - const data = useShoppingListData(listPath); + const { data, isLoading } = useShoppingListData(listPath); const handleShareModalClick = () => { console.log('isModalOpen', isModalOpen); @@ -65,7 +64,6 @@ export function App() { setListPath={setListPath} isModalOpen={isModalOpen} handleShareModalClick={handleShareModalClick} - setIsLoading={setIsLoading} /> } /> @@ -77,7 +75,6 @@ export function App() { listPath={listPath} listName={listName} isLoading={isLoading} - setIsLoading={setIsLoading} /> } /> diff --git a/src/api/firebase.js b/src/api/firebase.js index e26b506..d176e74 100644 --- a/src/api/firebase.js +++ b/src/api/firebase.js @@ -62,10 +62,15 @@ export function useShoppingListData(listPath) { /** @type {import('firebase/firestore').DocumentData[]} */ const initialState = []; const [data, setData] = useState(initialState); + const [isLoading, setIsLoading] = useState(true); useEffect(() => { - if (!listPath) return; + if (!listPath) { + setIsLoading(false); + return; + } + setIsLoading(true); // When we get a listPath, we use it to subscribe to real-time updates // from Firestore. return onSnapshot(collection(db, listPath, 'items'), (snapshot) => { @@ -84,11 +89,12 @@ export function useShoppingListData(listPath) { // Update our React state with the new data. setData(nextData); + setIsLoading(false); }); }, [listPath]); // Return the data so it can be used by our React components. - return data; + return { data, isLoading }; } /** diff --git a/src/components/CreateShoppingList.jsx b/src/components/CreateShoppingList.jsx index b9bbb44..cac3b6c 100644 --- a/src/components/CreateShoppingList.jsx +++ b/src/components/CreateShoppingList.jsx @@ -3,6 +3,7 @@ import { createList } from '../api/firebase'; import { useNavigate } from 'react-router-dom'; import toast from 'react-hot-toast'; import { Input } from './ui/input'; +import { ListPlus } from 'lucide-react'; export default function CreateShoppingList({ user, setListPath }) { const [listName, setListName] = useState(''); @@ -28,8 +29,8 @@ export default function CreateShoppingList({ user, setListPath }) { onSubmit={handleSubmit} className="relative w-full flex items-center justify-center gap-4 max-w-lg mx-auto " > -