Skip to content

Commit

Permalink
added delete item functionality. slight css tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesslane94 committed Jun 12, 2024
1 parent 2558d75 commit 4abb055
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions collections/src/hooks/useDeleteItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { deleteDoc, doc } from "firebase/firestore";
import { db } from "../config/firebase-config";
// import { storage } from "../config/firebase-config";

export const useDeleteItem = (docID) => {
export const useDeleteItem = (item) => {
const deleteItem = async() => {
await deleteDoc(doc(db, "items", docID));
await deleteDoc(doc(db, "items", item.id));
}

return { deleteItem };
Expand Down
30 changes: 16 additions & 14 deletions collections/src/pages/collections-manager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useDeleteItem } from '../../hooks/useDeleteItem';
export const Collections = () => {
const [file, setFile] = useState(null);
const [error, setError] = useState(null);
const [itemID, setDeleteItemID] = useState(null);
const [item, setDeleteItem] = useState(null);
const [itemName, setName] = useState("");
const [description, setDescription] = useState("");
const [type, setType] = useState("");
Expand All @@ -28,7 +28,7 @@ export const Collections = () => {
const { items, totalItems } = useGetItems();
const { name, profilePhoto, userID } = useGetUserID();
const navigate = useNavigate();
const { deleteItem } = useDeleteItem(itemID);
const { deleteItem } = useDeleteItem(item);

const types = ["image/png", "image/jpeg", "image/jpg"];

Expand Down Expand Up @@ -78,6 +78,14 @@ export const Collections = () => {
return (
<>
<div className="collections">
<br></br>
{profilePhoto && <div className="profile">
<img className="profile-photo" src={profilePhoto} alt="user's profile" />
<br></br>
<button className="sign-out-button" onClick={signUserOut}>
Sign Out
</button>
</div>}
<div className="container">
<h1>{name}'s Collection</h1>
<div className="item">
Expand Down Expand Up @@ -173,14 +181,6 @@ export const Collections = () => {
<button type="submit">Add Item</button>
</form>

<br></br>
{profilePhoto && <div className="profile">
<img className="profile-photo" src={profilePhoto} alt="user's profile" />
<br></br>
<button className="sign-out-button" onClick={signUserOut}>
Sign Out
</button>
</div>}
</div>

<div className="items">
Expand All @@ -189,8 +189,9 @@ export const Collections = () => {
{items.map((item) => {
const { itemName, description, type, brandOrCreator, price, series, character, dateAcquired, inCollection } = item;
return (
<li key={item.id}>
<h4> {itemName} </h4>
<div className="card" key={item.id}>
<div className="card-header"> {itemName} </div>
<div className="card-body">
<p> description: {description} </p>
<p> type: {type} </p>
<p> brand/creator: {brandOrCreator} </p>
Expand All @@ -200,10 +201,11 @@ export const Collections = () => {
<p> date acquired: {dateAcquired} </p>
<p> still in collection: {inCollection} </p>
<button className="delete-item" type="button" onClick={() => {
setDeleteItemID(item.id);
setDeleteItem(item);
deleteItem();
}}> Delete Item</button>
</li>
</div>
</div>
)
})}
</ul>
Expand Down
18 changes: 17 additions & 1 deletion collections/src/pages/collections-manager/styles.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
.items {
/* .items {
margin-left: 650px;
margin-top: 20px;
padding-left: 10px;
width: 600px;
height: 400px;
overflow: auto;
border: 3px solid #023047;
} */

.card {
margin-bottom: 10px;
display: inline-block;
padding: 20px;
}

.card-header {
color: rgb(48, 39, 56);
background-color: rgb(227, 230, 230);
font-weight: bold;
}

.profile {
display: block;
}

0 comments on commit 4abb055

Please sign in to comment.