Skip to content

Commit f4e1b0b

Browse files
authored
Fix reuse (#125)
* chore: wip * chore: fix reuse * chore: update dependencies * chore: update dependencies
1 parent 4e2875e commit f4e1b0b

32 files changed

+946
-531
lines changed

code/api/get-thread.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const getThread = async ({
1313
userId: string;
1414
clientId: string;
1515
}) => {
16-
let endpoint = `${process.env.NEXT_PUBLIC_API_ENDPOINT}/${process.env.NEXT_PUBLIC_API_ENDPOINT_HUB_NAME}/rooms/${roomId}/threads/${threadId}`;
16+
const endpoint = `${process.env.NEXT_PUBLIC_API_ENDPOINT}/${process.env.NEXT_PUBLIC_API_ENDPOINT_HUB_NAME}/rooms/${roomId}/threads/${threadId}`;
1717

1818
const response = await fetch(endpoint, {
1919
headers: {
@@ -23,9 +23,12 @@ export const getThread = async ({
2323
},
2424
});
2525

26-
if (!response.ok) {
26+
if (!response.ok && response.status !== 404) {
2727
throw new Error(`Error getting the thread: ${response.statusText}`);
2828
}
29+
if (!response.ok && response.status === 404) {
30+
return null;
31+
}
2932

3033
const data = await response.json();
3134

code/app/globals.css

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,169 @@
216216
opacity: 1;
217217
}
218218
}
219+
220+
.checkered {
221+
height: 100%;
222+
background:
223+
-webkit-linear-gradient(
224+
45deg,
225+
rgba(0, 0, 0, 0.0980392) 25%,
226+
transparent 25%,
227+
transparent 75%,
228+
rgba(0, 0, 0, 0.0980392) 75%,
229+
rgba(0, 0, 0, 0.0980392) 0
230+
),
231+
-webkit-linear-gradient(
232+
45deg,
233+
rgba(0, 0, 0, 0.0980392) 25%,
234+
transparent 25%,
235+
transparent 75%,
236+
rgba(0, 0, 0, 0.0980392) 75%,
237+
rgba(0, 0, 0, 0.0980392) 0
238+
),
239+
white;
240+
background:
241+
-moz-linear-gradient(
242+
45deg,
243+
rgba(0, 0, 0, 0.0980392) 25%,
244+
transparent 25%,
245+
transparent 75%,
246+
rgba(0, 0, 0, 0.0980392) 75%,
247+
rgba(0, 0, 0, 0.0980392) 0
248+
),
249+
-moz-linear-gradient(
250+
45deg,
251+
rgba(0, 0, 0, 0.0980392) 25%,
252+
transparent 25%,
253+
transparent 75%,
254+
rgba(0, 0, 0, 0.0980392) 75%,
255+
rgba(0, 0, 0, 0.0980392) 0
256+
),
257+
white;
258+
background:
259+
linear-gradient(
260+
45deg,
261+
rgba(0, 0, 0, 0.0980392) 25%,
262+
transparent 25%,
263+
transparent 75%,
264+
rgba(0, 0, 0, 0.0980392) 75%,
265+
rgba(0, 0, 0, 0.0980392) 0
266+
),
267+
linear-gradient(
268+
45deg,
269+
rgba(0, 0, 0, 0.0980392) 25%,
270+
transparent 25%,
271+
transparent 75%,
272+
rgba(0, 0, 0, 0.0980392) 75%,
273+
rgba(0, 0, 0, 0.0980392) 0
274+
),
275+
white;
276+
background-repeat: repeat, repeat;
277+
background-position:
278+
0px 0,
279+
10px 10px;
280+
-webkit-transform-origin: 0 0 0;
281+
transform-origin: 0 0 0;
282+
-webkit-background-origin: padding-box, padding-box;
283+
background-origin: padding-box, padding-box;
284+
-webkit-background-clip: border-box, border-box;
285+
background-clip: border-box, border-box;
286+
-webkit-background-size:
287+
20px 20px,
288+
20px 20px;
289+
background-size:
290+
20px 20px,
291+
20px 20px;
292+
-webkit-box-shadow: none;
293+
box-shadow: none;
294+
text-shadow: none;
295+
-webkit-transition: none;
296+
-moz-transition: none;
297+
-o-transition: none;
298+
transition: none;
299+
-webkit-transform: scaleX(1) scaleY(1) scaleZ(1);
300+
transform: scaleX(1) scaleY(1) scaleZ(1);
301+
}
302+
303+
.checkered-alt {
304+
height: 100%;
305+
background:
306+
-webkit-linear-gradient(
307+
45deg,
308+
rgba(0, 0, 0, 0.0980392) 25%,
309+
transparent 25%,
310+
transparent 75%,
311+
rgba(0, 0, 0, 0.0980392) 75%,
312+
rgba(0, 0, 0, 0.0980392) 0
313+
),
314+
-webkit-linear-gradient(
315+
45deg,
316+
rgba(0, 0, 0, 0.0980392) 25%,
317+
transparent 25%,
318+
transparent 75%,
319+
rgba(0, 0, 0, 0.0980392) 75%,
320+
rgba(0, 0, 0, 0.0980392) 0
321+
),
322+
black;
323+
background:
324+
-moz-linear-gradient(
325+
45deg,
326+
rgba(0, 0, 0, 0.0980392) 25%,
327+
transparent 25%,
328+
transparent 75%,
329+
rgba(0, 0, 0, 0.0980392) 75%,
330+
rgba(0, 0, 0, 0.0980392) 0
331+
),
332+
-moz-linear-gradient(
333+
45deg,
334+
rgba(0, 0, 0, 0.0980392) 25%,
335+
transparent 25%,
336+
transparent 75%,
337+
rgba(0, 0, 0, 0.0980392) 75%,
338+
rgba(0, 0, 0, 0.0980392) 0
339+
),
340+
black;
341+
background:
342+
linear-gradient(
343+
45deg,
344+
rgba(0, 0, 0, 0.0980392) 25%,
345+
transparent 25%,
346+
transparent 75%,
347+
rgba(0, 0, 0, 0.0980392) 75%,
348+
rgba(0, 0, 0, 0.0980392) 0
349+
),
350+
linear-gradient(
351+
45deg,
352+
rgba(0, 0, 0, 0.0980392) 25%,
353+
transparent 25%,
354+
transparent 75%,
355+
rgba(0, 0, 0, 0.0980392) 75%,
356+
rgba(0, 0, 0, 0.0980392) 0
357+
),
358+
black;
359+
background-repeat: repeat, repeat;
360+
background-position:
361+
0px 0,
362+
10px 10px;
363+
-webkit-transform-origin: 0 0 0;
364+
transform-origin: 0 0 0;
365+
-webkit-background-origin: padding-box, padding-box;
366+
background-origin: padding-box, padding-box;
367+
-webkit-background-clip: border-box, border-box;
368+
background-clip: border-box, border-box;
369+
-webkit-background-size:
370+
20px 20px,
371+
20px 20px;
372+
background-size:
373+
20px 20px,
374+
20px 20px;
375+
-webkit-box-shadow: none;
376+
box-shadow: none;
377+
text-shadow: none;
378+
-webkit-transition: none;
379+
-moz-transition: none;
380+
-o-transition: none;
381+
transition: none;
382+
-webkit-transform: scaleX(1) scaleY(1) scaleZ(1);
383+
transform: scaleX(1) scaleY(1) scaleZ(1);
384+
}

code/components/room-components/comment/comment.viewing.answer.tsx

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ export const CommentAnswer = ({
5656
const clientId = useCollaborationRoom((state) => state.clientId);
5757
const room = useCollaborationRoom((state) => state.room);
5858

59-
const { commentId, handleRefreshComment, handleRefreshCommentAnswers } =
60-
useComment({ node });
59+
const {
60+
commentId,
61+
comment: { data: commentData },
62+
handleRefreshComment,
63+
handleRefreshCommentAnswers,
64+
} = useComment({ node });
6165

6266
const mutateEditThread = useMutation({
6367
mutationFn: async ({
@@ -319,70 +323,71 @@ export const CommentAnswer = ({
319323
})}
320324
</div>
321325
</div>
322-
{answer.userMetadata.name === user?.name && (
323-
<DropdownMenu modal={false} open={menuOpen}>
324-
<DropdownMenuTrigger
325-
className={cn(
326-
"rounded-none cursor-pointer h-[40px] hover:text-[#666666] focus:outline-none",
327-
{
328-
["font-normal"]: menuOpen,
329-
["font-extralight"]: !menuOpen,
330-
}
331-
)}
332-
asChild
333-
>
334-
<Button
335-
className="rounded-none w-[20px] h-[20px] cursor-pointer"
336-
variant="link"
337-
onClick={() => setMenuOpen((prev) => !prev)}
326+
{answer.userMetadata.name === user?.name &&
327+
commentData?.thread?.status !== "resolved" && (
328+
<DropdownMenu modal={false} open={menuOpen}>
329+
<DropdownMenuTrigger
330+
className={cn(
331+
"rounded-none cursor-pointer h-[40px] hover:text-[#666666] focus:outline-none",
332+
{
333+
["font-normal"]: menuOpen,
334+
["font-extralight"]: !menuOpen,
335+
}
336+
)}
337+
asChild
338338
>
339-
<Ellipsis strokeWidth={1} size={16} />
340-
</Button>
341-
</DropdownMenuTrigger>
342-
<DropdownMenuContent
343-
onCloseAutoFocus={(e) => {
344-
e.preventDefault();
345-
}}
346-
onFocusOutside={() => {
347-
setMenuOpen(false);
348-
}}
349-
align="end"
350-
side="bottom"
351-
alignOffset={0}
352-
sideOffset={8}
353-
className="font-inter rounded-none shadow-none"
354-
>
355-
<DropdownMenuItem
356-
className="text-foreground cursor-pointer font-inter text-xs hover:rounded-none"
357-
onPointerDown={(e) => {
339+
<Button
340+
className="rounded-none w-[20px] h-[20px] cursor-pointer"
341+
variant="link"
342+
onClick={() => setMenuOpen((prev) => !prev)}
343+
>
344+
<Ellipsis strokeWidth={1} size={16} />
345+
</Button>
346+
</DropdownMenuTrigger>
347+
<DropdownMenuContent
348+
onCloseAutoFocus={(e) => {
358349
e.preventDefault();
350+
}}
351+
onFocusOutside={() => {
359352
setMenuOpen(false);
360-
setContent(answer.content);
361-
setEditing(true);
362353
}}
354+
align="end"
355+
side="bottom"
356+
alignOffset={0}
357+
sideOffset={8}
358+
className="font-inter rounded-none shadow-none"
363359
>
364-
Edit
365-
</DropdownMenuItem>
366-
{!isMain && (
367360
<DropdownMenuItem
368361
className="text-foreground cursor-pointer font-inter text-xs hover:rounded-none"
369362
onPointerDown={(e) => {
370363
e.preventDefault();
371-
372364
setMenuOpen(false);
373-
mutateDeleteThreadAnswer.mutate({
374-
node,
375-
threadId: node.getAttrs().threadId,
376-
answerId: answer.answerId,
377-
});
365+
setContent(answer.content);
366+
setEditing(true);
378367
}}
379368
>
380-
Delete
369+
Edit
381370
</DropdownMenuItem>
382-
)}
383-
</DropdownMenuContent>
384-
</DropdownMenu>
385-
)}
371+
{!isMain && (
372+
<DropdownMenuItem
373+
className="text-foreground cursor-pointer font-inter text-xs hover:rounded-none"
374+
onPointerDown={(e) => {
375+
e.preventDefault();
376+
377+
setMenuOpen(false);
378+
mutateDeleteThreadAnswer.mutate({
379+
node,
380+
threadId: node.getAttrs().threadId,
381+
answerId: answer.answerId,
382+
});
383+
}}
384+
>
385+
Delete
386+
</DropdownMenuItem>
387+
)}
388+
</DropdownMenuContent>
389+
</DropdownMenu>
390+
)}
386391
</div>
387392
<div className="font-inter text-xs text-left whitespace-pre-line">
388393
{answer.content}

code/components/room-components/comment/comment.viewing.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ export const CommentViewing = ({
212212
};
213213
}, [instance, node, commentId, handleCloseComment]);
214214

215+
if (!commentData) {
216+
return null;
217+
}
218+
215219
return (
216220
<motion.div
217221
id={commentId ?? ""}
@@ -226,16 +230,17 @@ export const CommentViewing = ({
226230
Comment
227231
</div>
228232
<div className="flex justify-end items-center gap-1">
229-
{commentData?.thread?.userMetadata.name === user?.name && (
230-
<Button
231-
className="rounded-none cursor-pointer w-[24px] h-[24px] color-red"
232-
variant="link"
233-
disabled={isLoadingComment}
234-
onClick={handleDeleteComment}
235-
>
236-
<Trash strokeWidth={1} size={16} />
237-
</Button>
238-
)}
233+
{commentData?.thread?.userMetadata.name === user?.name &&
234+
commentData?.thread?.status !== "resolved" && (
235+
<Button
236+
className="rounded-none cursor-pointer w-[24px] h-[24px] color-red"
237+
variant="link"
238+
disabled={isLoadingComment}
239+
onClick={handleDeleteComment}
240+
>
241+
<Trash strokeWidth={1} size={16} />
242+
</Button>
243+
)}
239244
{!isLoadingComment && (
240245
<Button
241246
className="rounded-none cursor-pointer w-[24px] h-[24px]"

0 commit comments

Comments
 (0)