|
1 |
| -import { Avatar } from '@/ui' |
| 1 | +import { Avatar, Menu } from '@/ui' |
2 | 2 | import {
|
3 | 3 | ChatCenteredDots,
|
| 4 | + DotsThreeOutlineVertical, |
4 | 5 | Gear,
|
| 6 | + Pencil, |
5 | 7 | RocketLaunch,
|
6 | 8 | ThumbsUp,
|
| 9 | + Trash, |
7 | 10 | UserCircle,
|
8 | 11 | Users,
|
9 | 12 | } from 'phosphor-react'
|
@@ -34,7 +37,8 @@ import {
|
34 | 37 | import { Goal } from './goals'
|
35 | 38 | import type { GoalResponse } from 'src/pages/[username]'
|
36 | 39 | import { scrollToContentWithId } from 'src/utils'
|
37 |
| -import { IconBrandDiscord } from 'tabler-icons' |
| 40 | +import { IconBrandDiscord, IconMenu } from 'tabler-icons' |
| 41 | +import EditUpdate from './goals/EditUpdate' |
38 | 42 |
|
39 | 43 | type LikeData = {
|
40 | 44 | count: number
|
@@ -65,6 +69,7 @@ export function HomePageFeedUpdate({
|
65 | 69 | update: HomePageFeedUpdateType
|
66 | 70 | setGoalId: () => void
|
67 | 71 | }) {
|
| 72 | + const [isInEditMode, setIsInEditMode] = useState(false) |
68 | 73 | const [isLikeModalOpen, setIsLikeModalOpen] = useState(false)
|
69 | 74 | const [session] = useSession()
|
70 | 75 | const [showComments, setShowComments] = useState(false)
|
@@ -120,114 +125,154 @@ export function HomePageFeedUpdate({
|
120 | 125 | className="bg-white px-4 py-6 shadow sm:p-6 sm:rounded-lg"
|
121 | 126 | id={`homepage-update-${update.id}`}
|
122 | 127 | >
|
123 |
| - <article> |
124 |
| - <div> |
125 |
| - <div className="flex space-x-3"> |
126 |
| - <div className="flex-shrink-0"> |
127 |
| - <A href={`/${postedBy.username}`}> |
128 |
| - <Avatar src={postedBy.image} /> |
129 |
| - </A> |
130 |
| - </div> |
131 |
| - <div className="min-w-0 flex-1"> |
132 |
| - <p className="text-sm font-medium text-gray-900"> |
133 |
| - <A href={`/${postedBy.username}`} className="hover:underline"> |
134 |
| - {postedBy.name} |
| 128 | + {isInEditMode ? ( |
| 129 | + <EditUpdate |
| 130 | + update={update} |
| 131 | + goalId={goal.id} |
| 132 | + cancelEditMode={() => setIsInEditMode(false)} |
| 133 | + updateFromHomePage={true} |
| 134 | + /> |
| 135 | + ) : ( |
| 136 | + <> |
| 137 | + <article> |
| 138 | + <div> |
| 139 | + <div className="flex space-x-3"> |
| 140 | + <div className="flex-shrink-0"> |
| 141 | + <A href={`/${postedBy.username}`}> |
| 142 | + <Avatar src={postedBy.image} /> |
| 143 | + </A> |
| 144 | + </div> |
| 145 | + <div className="min-w-0 flex-1"> |
| 146 | + <p className="text-sm font-medium text-gray-900"> |
| 147 | + <A |
| 148 | + href={`/${postedBy.username}`} |
| 149 | + className="hover:underline" |
| 150 | + > |
| 151 | + {postedBy.name} |
| 152 | + </A> |
| 153 | + </p> |
| 154 | + <p className="text-sm text-gray-500"> |
| 155 | + <time dateTime={createdAt.toISO()}> |
| 156 | + {createdAt.toLocaleString(DateTime.DATETIME_MED)} |
| 157 | + </time> |
| 158 | + </p> |
| 159 | + </div> |
| 160 | + |
| 161 | + <div className="flex-shrink-0 self-center flex"> |
| 162 | + <div className="relative inline-block text-left"> |
| 163 | + <Menu |
| 164 | + trigger={ |
| 165 | + <button className="-m-2 p-2 rounded-full flex items-center text-gray-400 hover:text-gray-600"> |
| 166 | + <span className="sr-only">Open quick actions</span> |
| 167 | + <DotsThreeOutlineVertical |
| 168 | + className="h-5 w-5" |
| 169 | + aria-hidden={true} |
| 170 | + /> |
| 171 | + </button> |
| 172 | + } |
| 173 | + > |
| 174 | + <Menu.Item |
| 175 | + icon={Pencil} |
| 176 | + onClick={() => setIsInEditMode(true)} |
| 177 | + > |
| 178 | + Edit |
| 179 | + </Menu.Item> |
| 180 | + <Menu.Item icon={Trash}>Delete</Menu.Item> |
| 181 | + </Menu> |
| 182 | + </div> |
| 183 | + </div> |
| 184 | + </div> |
| 185 | + <div className="mt-4 flex"> |
| 186 | + <button |
| 187 | + onClick={() => { |
| 188 | + setGoalId() |
| 189 | + scrollToContentWithId(`homepage-update-${update.id}`) |
| 190 | + }} |
| 191 | + className="hidden lg:block" |
| 192 | + > |
| 193 | + <span className="inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-brand-100 text-brand-800 hover:text-brand-600"> |
| 194 | + 🚀 Goal: {goal.title} |
| 195 | + </span> |
| 196 | + </button> |
| 197 | + <A href={`/${postedBy.username}`} className="lg:hidden"> |
| 198 | + <span className="inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-brand-100 text-brand-800 hover:text-brand-600"> |
| 199 | + 🚀 Goal: {goal.title} |
| 200 | + </span> |
135 | 201 | </A>
|
136 |
| - </p> |
137 |
| - <p className="text-sm text-gray-500"> |
138 |
| - <time dateTime={createdAt.toISO()}> |
139 |
| - {createdAt.toLocaleString(DateTime.DATETIME_MED)} |
140 |
| - </time> |
141 |
| - </p> |
| 202 | + </div> |
142 | 203 | </div>
|
143 |
| - </div> |
144 |
| - <div className="mt-4 flex"> |
145 |
| - <button |
146 |
| - onClick={() => { |
147 |
| - setGoalId() |
148 |
| - scrollToContentWithId(`homepage-update-${update.id}`) |
149 |
| - }} |
150 |
| - className="hidden lg:block" |
151 |
| - > |
152 |
| - <span className="inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-brand-100 text-brand-800 hover:text-brand-600"> |
153 |
| - 🚀 Goal: {goal.title} |
154 |
| - </span> |
155 |
| - </button> |
156 |
| - <A href={`/${postedBy.username}`} className="lg:hidden"> |
157 |
| - <span className="inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-brand-100 text-brand-800 hover:text-brand-600"> |
158 |
| - 🚀 Goal: {goal.title} |
159 |
| - </span> |
160 |
| - </A> |
161 |
| - </div> |
162 |
| - </div> |
163 |
| - <div className="mt-2 text-sm text-gray-700 space-y-4"> |
164 |
| - <div className="prose max-w-none"> |
165 |
| - <Markdown>{description}</Markdown> |
166 |
| - </div> |
167 |
| - </div> |
168 |
| - <div className="mt-6 flex justify-between space-x-8"> |
169 |
| - <div className="flex space-x-6"> |
170 |
| - <span className="inline-flex items-center text-sm"> |
171 |
| - <button |
172 |
| - className="inline-flex space-x-2 text-gray-400 hover:text-gray-500" |
173 |
| - onClick={() => { |
174 |
| - if (!session) { |
175 |
| - setIsLikeModalOpen(true) |
176 |
| - return |
177 |
| - } |
178 |
| - dispatch({ type: 'toggle' }) |
179 |
| - mutate() |
180 |
| - }} |
181 |
| - > |
182 |
| - <ThumbsUp |
183 |
| - className={classNames( |
184 |
| - 'h-5 w-5', |
185 |
| - hasLiked && 'text-brand-600' |
186 |
| - )} |
187 |
| - weight={hasLiked ? 'bold' : 'regular'} |
188 |
| - /> |
189 |
| - <span className="font-medium text-gray-900">{likesCount}</span> |
190 |
| - <span className="sr-only">likes</span> |
191 |
| - </button> |
192 |
| - <LikeModal |
193 |
| - user={postedBy} |
194 |
| - isOpen={isLikeModalOpen} |
195 |
| - setIsOpen={setIsLikeModalOpen} |
196 |
| - /> |
197 |
| - </span> |
198 |
| - <span className="inline-flex items-center text-sm"> |
199 |
| - <button |
200 |
| - className="inline-flex space-x-2 text-gray-400 hover:text-gray-500" |
201 |
| - onClick={() => setShowComments(!showComments)} |
202 |
| - > |
203 |
| - <ChatCenteredDots className="h-5 w-5" /> |
204 |
| - <span className="font-medium text-gray-900"> |
205 |
| - {update.comments.data.length} |
| 204 | + <div className="mt-2 text-sm text-gray-700 space-y-4"> |
| 205 | + <div className="prose max-w-none"> |
| 206 | + <Markdown>{description}</Markdown> |
| 207 | + </div> |
| 208 | + </div> |
| 209 | + <div className="mt-6 flex justify-between space-x-8"> |
| 210 | + <div className="flex space-x-6"> |
| 211 | + <span className="inline-flex items-center text-sm"> |
| 212 | + <button |
| 213 | + className="inline-flex space-x-2 text-gray-400 hover:text-gray-500" |
| 214 | + onClick={() => { |
| 215 | + if (!session) { |
| 216 | + setIsLikeModalOpen(true) |
| 217 | + return |
| 218 | + } |
| 219 | + dispatch({ type: 'toggle' }) |
| 220 | + mutate() |
| 221 | + }} |
| 222 | + > |
| 223 | + <ThumbsUp |
| 224 | + className={classNames( |
| 225 | + 'h-5 w-5', |
| 226 | + hasLiked && 'text-brand-600' |
| 227 | + )} |
| 228 | + weight={hasLiked ? 'bold' : 'regular'} |
| 229 | + /> |
| 230 | + <span className="font-medium text-gray-900"> |
| 231 | + {likesCount} |
| 232 | + </span> |
| 233 | + <span className="sr-only">likes</span> |
| 234 | + </button> |
| 235 | + <LikeModal |
| 236 | + user={postedBy} |
| 237 | + isOpen={isLikeModalOpen} |
| 238 | + setIsOpen={setIsLikeModalOpen} |
| 239 | + /> |
206 | 240 | </span>
|
207 |
| - <span className="sr-only">replies</span> |
208 |
| - </button> |
209 |
| - </span> |
210 |
| - </div> |
211 |
| - </div> |
212 |
| - </article> |
| 241 | + <span className="inline-flex items-center text-sm"> |
| 242 | + <button |
| 243 | + className="inline-flex space-x-2 text-gray-400 hover:text-gray-500" |
| 244 | + onClick={() => setShowComments(!showComments)} |
| 245 | + > |
| 246 | + <ChatCenteredDots className="h-5 w-5" /> |
| 247 | + <span className="font-medium text-gray-900"> |
| 248 | + {update.comments.data.length} |
| 249 | + </span> |
| 250 | + <span className="sr-only">replies</span> |
| 251 | + </button> |
| 252 | + </span> |
| 253 | + </div> |
| 254 | + </div> |
| 255 | + </article> |
213 | 256 |
|
214 |
| - {showComments && ( |
215 |
| - <> |
216 |
| - <UpdateComments> |
217 |
| - <UpdateCommentsList> |
218 |
| - {update.comments.data.map((comment, index) => ( |
219 |
| - <UpdateComment |
220 |
| - key={comment.id} |
221 |
| - postedBy={comment.postedBy} |
222 |
| - postedOn={DateTime.fromMillis(comment.createdAt)} |
223 |
| - isLastComment={index === update.comments.data.length - 1} |
224 |
| - > |
225 |
| - {comment.description} |
226 |
| - </UpdateComment> |
227 |
| - ))} |
228 |
| - </UpdateCommentsList> |
229 |
| - {session && <NewComment updateId={update.id} />} |
230 |
| - </UpdateComments> |
| 257 | + {showComments && ( |
| 258 | + <> |
| 259 | + <UpdateComments> |
| 260 | + <UpdateCommentsList> |
| 261 | + {update.comments.data.map((comment, index) => ( |
| 262 | + <UpdateComment |
| 263 | + key={comment.id} |
| 264 | + postedBy={comment.postedBy} |
| 265 | + postedOn={DateTime.fromMillis(comment.createdAt)} |
| 266 | + isLastComment={index === update.comments.data.length - 1} |
| 267 | + > |
| 268 | + {comment.description} |
| 269 | + </UpdateComment> |
| 270 | + ))} |
| 271 | + </UpdateCommentsList> |
| 272 | + {session && <NewComment updateId={update.id} />} |
| 273 | + </UpdateComments> |
| 274 | + </> |
| 275 | + )} |
231 | 276 | </>
|
232 | 277 | )}
|
233 | 278 | </li>
|
|
0 commit comments