|
1 | 1 | import './Home.css'; |
2 | 2 | import { SingleList, ShareListComponent } from '../components'; |
3 | | -import { createList, useAuth, deleteList, unfollowList } from '../api'; |
| 3 | +import { |
| 4 | + createList, |
| 5 | + useAuth, |
| 6 | + deleteList, |
| 7 | + unfollowList, |
| 8 | + SignInButton, |
| 9 | +} from '../api'; |
4 | 10 | import { Fragment, useState, useEffect } from 'react'; |
5 | 11 | import { useNavigate } from 'react-router-dom'; |
6 | 12 | import { useVoiceToText } from '../utils'; |
@@ -76,69 +82,94 @@ export function Home({ data, setListPath, setAllLists }) { |
76 | 82 | console.log(error); |
77 | 83 | } |
78 | 84 | }; |
79 | | - |
80 | 85 | return ( |
81 | | - <div className="flex flex-col h-[70vh] my-8 p-8 bg-white rounded-3xl shadow-xl overflow-hidden mx-auto"> |
82 | | - <ul className="font-archivo flex-grow overflow-y-auto space-y-4"> |
83 | | - {data && |
84 | | - data.map((list) => { |
85 | | - const uniqueId = crypto.randomUUID(); |
86 | | - return ( |
87 | | - <Fragment key={uniqueId}> |
88 | | - <div className="flex items-center justify-between p-4 rounded-3xl shadow-md border"> |
89 | | - <SingleList |
90 | | - name={list.name} |
91 | | - setListPath={setListPath} |
92 | | - path={list.path} |
93 | | - /> |
94 | | - <div className="flex items-center space-x-4"> |
95 | | - {!list.isShared && ( |
96 | | - <button |
97 | | - onClick={() => handleDelete(list)} |
98 | | - className="p-2" |
99 | | - > |
100 | | - <DeleteIcon /> |
101 | | - </button> |
102 | | - )} |
| 86 | + <> |
| 87 | + {data.length ? ( |
| 88 | + <div className="flex flex-col h-[70vh] my-8 p-8 rounded-3xl shadow-xl overflow-hidden mx-auto bg-neutral"> |
| 89 | + <ul className="font-archivo flex-grow overflow-y-auto space-y-4 "> |
| 90 | + {data && |
| 91 | + data.map((list) => { |
| 92 | + const uniqueId = crypto.randomUUID(); |
| 93 | + return ( |
| 94 | + <Fragment key={uniqueId}> |
| 95 | + <div |
| 96 | + className="flex items-center justify-between p-4 rounded-3xl shadow-md border border-primary" |
| 97 | + style={{ background: '#f8fdef' }} |
| 98 | + > |
| 99 | + <SingleList |
| 100 | + name={list.name} |
| 101 | + setListPath={setListPath} |
| 102 | + path={list.path} |
| 103 | + /> |
| 104 | + <div className="flex items-center space-x-4"> |
| 105 | + {!list.isShared && ( |
| 106 | + <button |
| 107 | + onClick={() => handleDelete(list)} |
| 108 | + aria-label="Delete this shopping list" |
| 109 | + > |
| 110 | + <DeleteIcon /> |
| 111 | + </button> |
| 112 | + )} |
| 113 | + |
| 114 | + {/* Remove button for shared lists */} |
| 115 | + {list.isShared && ( |
| 116 | + <button |
| 117 | + onClick={() => handleUnfollowSharedList(list)} |
| 118 | + aria-label="Remove this shared list" |
| 119 | + > |
| 120 | + <RemoveCircleIcon /> |
| 121 | + </button> |
| 122 | + )} |
| 123 | + <ShareListComponent |
| 124 | + name={list.name} |
| 125 | + setListPath={setListPath} |
| 126 | + path={list.path} |
| 127 | + /> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + </Fragment> |
| 131 | + ); |
| 132 | + })} |
| 133 | + </ul> |
| 134 | + <form |
| 135 | + onSubmit={handleSubmit} |
| 136 | + className="flex flex-col sm:flex-row items-center space-y-2 sm:space-y-0 sm:space-x-4 mt-4 justify-center" |
| 137 | + > |
| 138 | + <label htmlFor="listName" className="text-white font-medium"> |
| 139 | + Create a new list: |
| 140 | + </label> |
| 141 | + <div className="flex flex-col"> |
| 142 | + <input |
| 143 | + type="text" |
| 144 | + id="listName" |
| 145 | + value={listName} |
| 146 | + onChange={(e) => setListName(e.target.value)} |
| 147 | + /> |
| 148 | + <span className="text-error">{error}</span> |
| 149 | + </div> |
103 | 150 |
|
104 | | - {/* Remove button for shared lists */} |
105 | | - {list.isShared && ( |
106 | | - <button |
107 | | - onClick={() => handleUnfollowSharedList(list)} |
108 | | - className="p-2" |
109 | | - > |
110 | | - <RemoveCircleIcon /> |
111 | | - </button> |
112 | | - )} |
113 | | - <ShareListComponent |
114 | | - name={list.name} |
115 | | - setListPath={setListPath} |
116 | | - path={list.path} |
117 | | - /> |
118 | | - </div> |
119 | | - </div> |
120 | | - </Fragment> |
121 | | - ); |
122 | | - })} |
123 | | - </ul> |
124 | | - <form |
125 | | - action="" |
126 | | - onSubmit={handleSubmit} |
127 | | - className="flex flex-col sm:flex-row items-center space-y-2 sm:space-y-0 sm:space-x-4 mt-4" |
128 | | - > |
129 | | - <label htmlFor="listName">Create a new list:</label> |
130 | | - <input |
131 | | - type="text" |
132 | | - id="listName" |
133 | | - value={listName} |
134 | | - onChange={(e) => setListName(e.target.value)} |
135 | | - /> |
136 | | - <button type="button" onClick={startListening}> |
137 | | - {isListening ? 'Listening...' : <KeyboardVoiceIcon />} |
138 | | - </button> |
139 | | - <button>Submit</button> |
140 | | - <p>{error}</p> |
141 | | - </form> |
142 | | - </div> |
| 151 | + <button |
| 152 | + type="button" |
| 153 | + onClick={startListening} |
| 154 | + aria-label="Use microphone to add a new list" |
| 155 | + className="bg-accent text-black hover:bg-third" |
| 156 | + > |
| 157 | + {isListening ? 'Listening...' : <KeyboardVoiceIcon />} |
| 158 | + </button> |
| 159 | + <button className="bg-accent text-black hover:bg-third"> |
| 160 | + Submit |
| 161 | + </button> |
| 162 | + </form> |
| 163 | + </div> |
| 164 | + ) : ( |
| 165 | + <div className="flex flex-col h-[80vh] my-8 p-8 rounded-3xl overflow-hidden mx-auto place-content-center items-center "> |
| 166 | + <h1 className="text-center my-8 text-neutral text-6xl"> |
| 167 | + {' '} |
| 168 | + Welcome to SnapShop! |
| 169 | + </h1> |
| 170 | + <SignInButton styles={'bg-neutral text-white btn-lg text-2xl'} /> |
| 171 | + </div> |
| 172 | + )} |
| 173 | + </> |
143 | 174 | ); |
144 | 175 | } |
0 commit comments