generated from 202306-NEA-DZ-FEW/capstone-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from 202306-NEA-DZ-FEW/develop
v1.0.1
- Loading branch information
Showing
19 changed files
with
374 additions
and
153 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,51 @@ | ||
import { arrayRemove, arrayUnion } from "firebase/firestore"; | ||
import React, { useEffect, useState } from "react"; | ||
import { FaBookmark, FaRegBookmark } from "react-icons/fa"; | ||
|
||
import { updateUserDocument } from "@/lib/firebase/controller"; | ||
|
||
const EventsSave = ({ userDoc, eventId }) => { | ||
// State to manage eventsSave array | ||
const [eventsSave, setEventsSave] = useState([]); | ||
|
||
// Update state when userDoc changes | ||
useEffect(() => { | ||
if (userDoc && userDoc.eventsSave) { | ||
setEventsSave(userDoc.eventsSave); | ||
} else { | ||
setEventsSave([]); | ||
} | ||
}, [userDoc]); | ||
|
||
const handleSave = async () => { | ||
if (eventsSave.includes(eventId)) { | ||
await updateUserDocument(userDoc.id, { | ||
eventsSave: arrayRemove(eventId), | ||
}); | ||
setEventsSave((prevEventsSave) => | ||
prevEventsSave.filter((id) => id !== eventId) | ||
); | ||
} else { | ||
await updateUserDocument(userDoc.id, { | ||
eventsSave: arrayUnion(eventId), | ||
}); | ||
setEventsSave((prevEventsSave) => [...prevEventsSave, eventId]); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='cursor-pointer' onClick={handleSave}> | ||
{eventsSave.includes(eventId) ? ( | ||
<div className='text-amber-400'> | ||
<FaBookmark /> | ||
</div> | ||
) : ( | ||
<div className='text-gray-950'> | ||
<FaRegBookmark /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default EventsSave; |
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
Oops, something went wrong.