diff --git a/src/App.jsx b/src/App.jsx index bc52f1a..e4dd64d 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -46,7 +46,14 @@ export function App() { }> } + element={ + + } /> } /> } /> diff --git a/src/views/Home.css b/src/views/Home.css index e69de29..b97c8d4 100644 --- a/src/views/Home.css +++ b/src/views/Home.css @@ -0,0 +1,10 @@ +form { + display: flex; + flex-direction: column; + width: 50%; +} +#listName, +.button { + padding: 4% 4%; + margin: 2% 2%; +} diff --git a/src/views/Home.jsx b/src/views/Home.jsx index d62a0c7..b7cf66f 100644 --- a/src/views/Home.jsx +++ b/src/views/Home.jsx @@ -1,7 +1,35 @@ import './Home.css'; import { SingleList } from '../components'; +import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { createList } from '../api/firebase'; + +export function Home({ data, setListPath, userId, userEmail }) { + const [listName, setListName] = useState(''); + const [message, setMessage] = useState(''); + const navigate = useNavigate(); //to call redirected to the List view + + const handleCreateListButton = async (e) => { + e.preventDefault(); + if (!listName) { + setMessage('Enter a list name'); + return; + } + + try { + await createList(userId, userEmail, listName); + setMessage('New list successfully created'); + + const createListPath = `${userId}/${listName}}`; + setListPath(createListPath); + navigate('/list'); //redirect to the list view + } catch (error) { + //Logging and error messages if list is not created + console.error('error creating a list', error); + setMessage('Failed to create list. Please try again!'); + } + }; -export function Home({ data, setListPath }) { return (

@@ -17,6 +45,21 @@ export function Home({ data, setListPath }) { /> ))} + +

+ + setListName(e.target.value)} + placeholder="Enter the name of your new list" + /> + + {message} +
); }