Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: Commenting one after another

Richie McIlroyb00cdfab9dd7
diff --git a/apps/web/app/api/video/comment/route.ts b/apps/web/app/api/video/comment/route.ts
index 5af0b5127..f0c3016cc 100644
--- a/apps/web/app/api/video/comment/route.ts
+++ b/apps/web/app/api/video/comment/route.ts
@@ -14,12 +14,6 @@ async function handlePost(request: NextRequest) {
const userId = user?.id || "anonymous";
const parentCommentIdSanitized = parentCommentId ? parentCommentId.replace("temp-", "") : null;
- console.log("type", type);
- console.log("content", content);
- console.log("videoId", videoId);
- console.log("timestamp", timestamp);
- console.log("parentCommentIdSanitized", parentCommentIdSanitized);
-
if (!type || !content || !videoId) {
console.error("Missing required data in /api/video/comment/route.ts");
@@ -37,7 +31,7 @@ async function handlePost(request: NextRequest) {
const id = nanoId();
try {
- await db.insert(comments).values({
+ const newComment = {
id: id,
authorId: userId,
type: type,
@@ -45,12 +39,16 @@ async function handlePost(request: NextRequest) {
videoId: videoId,
timestamp: timestamp || null,
parentCommentId: parentCommentIdSanitized || null,
- });
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ };
+
+ await db.insert(comments).values(newComment);
return new Response(
JSON.stringify({
- success: true,
- commentId: id
+ ...newComment,
+ authorName: user?.name || "Anonymous",
}), {
status: 200,
headers: {
diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
index 9ba6a8a4a..e02d02baa 100644
--- a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
@@ -297,10 +297,10 @@ const EmptyState = () => (
animate={{ opacity: 1 }}
className="flex flex-col items-center justify-center h-full p-8 text-center"
>
- <div className="text-gray-300 mb-2">
+ <div className="text-gray-300 space-y-2">
<svg
xmlns="http://www.w3.org/2000/svg"
- className="h-12 w-12 mx-auto mb-4"
+ className="h-8 w-8 mx-auto"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
@@ -312,10 +312,10 @@ const EmptyState = () => (
d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"
/>
</svg>
- <h3 className="text-lg font-medium text-gray-500 mb-1">
- No comments yet
- </h3>
- <p className="text-gray-400">Be the first to share your thoughts!</p>
+ <h3 className="text-sm font-medium text-gray-500">No comments yet</h3>
+ <p className="text-gray-400 text-sm">
+ Be the first to share your thoughts!
+ </p>
</div>
</motion.div>
);
@@ -416,18 +416,13 @@ export const Activity: React.FC<ActivityProps> = ({
throw new Error("Failed to post comment");
}
- const newComment = await response.json();
+ const data = await response.json();
setOptimisticComments((prev) =>
prev.filter((c) => c.id !== optimisticComment.id)
);
- setTimeout(() => {
- setComments((prev) => [
- ...prev,
- { ...optimisticComment, ...newComment },
- ]);
- }, 100);
+ setComments((prev) => [...prev, data]);
} catch (error) {
console.error("Error posting comment:", error);
setOptimisticComments((prev) =>
@@ -477,31 +472,21 @@ export const Activity: React.FC<ActivityProps> = ({
throw new Error("Failed to post reply");
}
- const newReply = await response.json();
+ const data = await response.json();
- // Remove optimistic reply first
setOptimisticComments((prev) =>
prev.filter((c) => c.id !== optimisticReply.id)
);
- // Add the real reply with a delay and scroll to it
- setTimeout(() => {
- const newReplyWithId = { ...optimisticReply, ...newReply };
- setComments((prev) => [...prev, newReplyWithId]);
+ setComments((prev) => [...prev, data]);
- // Wait a bit for the DOM to update, then scroll to the new reply
- setTimeout(() => {
- const newReplyElement = document.getElementById(
- `comment-${newReplyWithId.id}`
- );
- if (newReplyElement) {
- newReplyElement.scrollIntoView({
- behavior: "smooth",
- block: "center",
- });
- }
- }, 100);
- }, 100);
+ const newReplyElement = document.getElementById(`comment-${data.id}`);
+ if (newReplyElement) {
+ newReplyElement.scrollIntoView({
+ behavior: "smooth",
+ block: "center",
+ });
+ }
setReplyingTo(null);
} catch (error) {