Skip to content

Commit 52db7a1

Browse files
committed
refactor: listpage to excluse additem form and refactor sharelist form to appear in form of modal to reduce extra space
1 parent 6844c90 commit 52db7a1

File tree

6 files changed

+55
-44
lines changed

6 files changed

+55
-44
lines changed

src/components/ListItem.scss

-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
max-width: 50%;
2020
width: 80%;
2121
border-radius: 4px;
22-
}
2322

24-
.UrgencyStatus {
2523
// Default styles for urgency status
2624
font-weight: bold;
2725

src/components/forms/AddItemForm.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChangeEvent, FormEvent, useState } from "react";
2+
import { useNavigate, useParams } from "react-router-dom";
23
import { addItem, ListItem } from "../../api";
34
import { validateItemName } from "../../utils";
45
import toast from "react-hot-toast";
@@ -31,6 +32,9 @@ export function AddItemForm({ listPath, data: unfilteredListItems }: Props) {
3132

3233
const [addedQuantity, setAddedQuantity] = useState(1);
3334

35+
const navigate = useNavigate();
36+
const listName = listPath.split("/").pop();
37+
3438
const handleItemNameTextChange = (e: ChangeEvent<HTMLInputElement>) => {
3539
setItemName(e.target.value);
3640
};
@@ -87,18 +91,20 @@ export function AddItemForm({ listPath, data: unfilteredListItems }: Props) {
8791
},
8892
},
8993
);
94+
navigate(`/list/${listName}`);
9095
console.log("Quantity added from Add Item form:", addedQuantity);
9196
} catch (error) {
9297
console.error("Failed to add item:", error);
9398
}
9499
};
95100

96101
return (
97-
<section className="custom-borders d-flex flex-column align-items-center ">
102+
<section className="d-flex flex-column align-items-center ">
98103
<Form onSubmit={(e) => handleSubmit(e, listPath)}>
99-
<h3 className="text-center">Add Item</h3>
104+
<h1 className="text-center mt-5">New Item</h1>
100105

101106
<Form.Label htmlFor="item-name">
107+
<h4>Item Name:</h4>
102108
<Form.Control
103109
id="item-name"
104110
type="text"
@@ -111,6 +117,7 @@ export function AddItemForm({ listPath, data: unfilteredListItems }: Props) {
111117
/>
112118
</Form.Label>
113119
<label htmlFor="item-quantity">
120+
<h4>Item Quantity</h4>
114121
<Form.Control
115122
id="item-quantity"
116123
type="number"

src/components/forms/ShareListForm.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getUser } from "../ProtectedRoute";
55
import Button from "react-bootstrap/Button";
66
import Form from "react-bootstrap/Form";
77
import { InputGroup } from "react-bootstrap";
8+
import { FaRegShareSquare } from "react-icons/fa";
89
import toast from "react-hot-toast";
910

1011
interface Props {
@@ -44,7 +45,7 @@ const ShareListForm = ({ listPath }: Props) => {
4445

4546
return (
4647
<Form
47-
className="custom-borders d-flex flex-column align-items-center mt-3"
48+
className="d-flex flex-column align-items-center mt-3"
4849
onSubmit={(e) => handleInvite(e, listPath)}
4950
>
5051
<Form.Label className="h3 text-center " htmlFor="recipient-email">
@@ -63,7 +64,8 @@ const ShareListForm = ({ listPath }: Props) => {
6364
aria-required
6465
/>
6566
<Button type="submit" aria-label="submits form to share shopping list">
66-
Share List
67+
<FaRegShareSquare />
68+
<span>Share</span>
6769
</Button>
6870
</InputGroup>
6971
</Form>

src/views/authenticated/List.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
display: flex;
1515
flex-wrap: wrap;
1616
box-sizing: border-box;
17+
flex-direction: column;
1718
}
1819

19-
.filter-list {
20+
.list-functions {
2021
background-color: rgb(241, 230, 204);
22+
z-index: 1020;
2123
}
2224

2325
.Add-ShareList {

src/views/authenticated/List.tsx

+39-36
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import "./List.scss";
22
import { useParams, useNavigate } from "react-router-dom";
3-
import { useRef } from "react";
4-
import { useState, useMemo } from "react";
3+
import { useState, useMemo, useRef } from "react";
54
import { ListItemCheckBox } from "../../components/ListItem";
65
import { FilterListInput } from "../../components/FilterListInput";
76
import { ListItem, comparePurchaseUrgency } from "../../api";
8-
import { Container } from "react-bootstrap";
9-
import { AddItemForm } from "../../components/forms/AddItemForm";
7+
import { Container, Modal } from "react-bootstrap";
108
import Button from "react-bootstrap/Button";
119
import ShareListForm from "../../components/forms/ShareListForm";
10+
import { FaRegShareSquare } from "react-icons/fa";
1211

1312
interface Props {
1413
data: ListItem[];
@@ -19,6 +18,7 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
1918
const navigate = useNavigate();
2019
const [searchTerm, setSearchTerm] = useState<string>("");
2120
const { listName } = useParams<{ listName: string }>();
21+
const [showShareModal, setShowShareModal] = useState(false);
2222

2323
const filteredListItems = useMemo(() => {
2424
return unfilteredListItems
@@ -64,15 +64,6 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
6464
);
6565
}
6666

67-
const addShareListRef = useRef<HTMLElement | null>(null);
68-
69-
// Function to handle scrolling to the Add-ShareList section
70-
const scrollToAddShareItem = () => {
71-
if (addShareListRef.current) {
72-
addShareListRef.current.scrollIntoView({ behavior: "smooth" });
73-
}
74-
};
75-
7667
const viewListRef = useRef<HTMLElement | null>(null);
7768

7869
// Function to handle scrolling to the Add-ShareList section
@@ -84,27 +75,36 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
8475

8576
// Main content when list is not empty
8677
return (
87-
<Container className="ListPageContainer">
78+
<Container className="ListPageContainer ">
8879
<div className="ListItemSection">
8980
<header>
9081
<h2 className="ListName p-1 m-2 mt-2">{listName}</h2>
9182
</header>
9283

93-
<section className="filter-list d-flex sticky-top flex-nowrap align-items-center justify-content-center">
84+
<section className="list-functions mt-3 d-flex flex-column sticky-top align-items-center justify-content-center">
85+
<div>
86+
<Button
87+
className="ms-2"
88+
onClick={() => navigate("/manage-list")}
89+
aria-label="Navigate to add more items to your list"
90+
>
91+
<span className="text-nowrap">Add items</span>
92+
</Button>
93+
<Button
94+
className="ms-2"
95+
onClick={() => setShowShareModal(true)}
96+
aria-label="Share your list"
97+
>
98+
<FaRegShareSquare />
99+
<span className="text-nowrap ms-1">Share</span>
100+
</Button>
101+
</div>
94102
{unfilteredListItems.length > 0 && (
95103
<FilterListInput
96104
searchTerm={searchTerm}
97105
setSearchTerm={setSearchTerm}
98106
/>
99107
)}
100-
101-
<Button
102-
className="ms-2 d-md-none"
103-
onClick={scrollToAddShareItem}
104-
aria-label="Navigate to add more items to your list"
105-
>
106-
<span className="text-nowrap">Add items</span>
107-
</Button>
108108
</section>
109109

110110
<section ref={viewListRef}>
@@ -114,20 +114,23 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
114114
</section>
115115
</div>
116116

117-
<section
118-
ref={addShareListRef}
119-
className="Add-ShareList d-flex flex-column justify-content-start align-items-center "
120-
>
121-
<div className="Add-ItemForm ">
122-
<AddItemForm listPath={listPath} data={unfilteredListItems || []} />
123-
</div>
124-
<div className="Share-ListForm ">
117+
<Modal show={showShareModal} onHide={() => setShowShareModal(false)}>
118+
<Modal.Header closeButton>
119+
<Modal.Title>Share Your List</Modal.Title>
120+
</Modal.Header>
121+
<Modal.Body>
125122
<ShareListForm listPath={listPath} />
126-
</div>
127-
<Button className="d-md-none mt-3" onClick={scrollToViewList}>
128-
{"View List"}
129-
</Button>
130-
</section>
123+
</Modal.Body>
124+
<Modal.Footer>
125+
<Button variant="secondary" onClick={() => setShowShareModal(false)}>
126+
Close
127+
</Button>
128+
</Modal.Footer>
129+
</Modal>
130+
131+
<Button className="d-md-none mt-3" onClick={scrollToViewList}>
132+
{"View List"}
133+
</Button>
131134
</Container>
132135
);
133136
}

src/views/authenticated/ManageList.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export function ManageList({ listPath, data }: Props) {
2929
return (
3030
<div>
3131
<AddItemForm listPath={listPath} data={data || []} />
32-
<ShareListForm listPath={listPath} />
3332
</div>
3433
);
3534
}

0 commit comments

Comments
 (0)