Skip to content

Commit

Permalink
handle create list button
Browse files Browse the repository at this point in the history
  • Loading branch information
didemydn committed Aug 21, 2024
1 parent c765bd4 commit a1e9d93
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/views/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
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 navigate = useNavigate(); //to call redirected to the List view

const handleCreateListButton = async (e) => {
e.preventDefault();

try {
await createList(userId, userEmail, listName);

const createListPath = `${userId}/${listName}}`;
setListPath(createListPath);
navigate('/list'); //redirect to the list view
} catch (error) {
console.error('error creating a list', error);
}
};

export function Home({ data, setListPath }) {
return (
<div className="Home">
<p>
Expand All @@ -17,6 +37,7 @@ export function Home({ data, setListPath }) {
/>
))}
</ul>
<form onSubmit={handleCreateListButton}></form>
</div>
);
}

0 comments on commit a1e9d93

Please sign in to comment.