1
1
import "./List.scss" ;
2
2
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" ;
5
4
import { ListItemCheckBox } from "../../components/ListItem" ;
6
5
import { FilterListInput } from "../../components/FilterListInput" ;
7
6
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" ;
10
8
import Button from "react-bootstrap/Button" ;
11
9
import ShareListForm from "../../components/forms/ShareListForm" ;
10
+ import { FaRegShareSquare } from "react-icons/fa" ;
12
11
13
12
interface Props {
14
13
data : ListItem [ ] ;
@@ -19,6 +18,7 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
19
18
const navigate = useNavigate ( ) ;
20
19
const [ searchTerm , setSearchTerm ] = useState < string > ( "" ) ;
21
20
const { listName } = useParams < { listName : string } > ( ) ;
21
+ const [ showShareModal , setShowShareModal ] = useState ( false ) ;
22
22
23
23
const filteredListItems = useMemo ( ( ) => {
24
24
return unfilteredListItems
@@ -64,15 +64,6 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
64
64
) ;
65
65
}
66
66
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
-
76
67
const viewListRef = useRef < HTMLElement | null > ( null ) ;
77
68
78
69
// Function to handle scrolling to the Add-ShareList section
@@ -84,27 +75,36 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
84
75
85
76
// Main content when list is not empty
86
77
return (
87
- < Container className = "ListPageContainer" >
78
+ < Container className = "ListPageContainer " >
88
79
< div className = "ListItemSection" >
89
80
< header >
90
81
< h2 className = "ListName p-1 m-2 mt-2" > { listName } </ h2 >
91
82
</ header >
92
83
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 >
94
102
{ unfilteredListItems . length > 0 && (
95
103
< FilterListInput
96
104
searchTerm = { searchTerm }
97
105
setSearchTerm = { setSearchTerm }
98
106
/>
99
107
) }
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 >
108
108
</ section >
109
109
110
110
< section ref = { viewListRef } >
@@ -114,20 +114,23 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
114
114
</ section >
115
115
</ div >
116
116
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 >
125
122
< 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 >
131
134
</ Container >
132
135
) ;
133
136
}
0 commit comments