feat(platform): checkpoint current implementation state
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { CommentEntityType } from "@capakraken/shared";
|
||||
import { useState } from "react";
|
||||
import { clsx } from "clsx";
|
||||
import { trpc } from "~/lib/trpc/client.js";
|
||||
@@ -7,6 +8,11 @@ import { ConfirmDialog } from "~/components/ui/ConfirmDialog.js";
|
||||
import { CommentInput } from "./CommentInput.js";
|
||||
import { sanitizeHtml } from "~/lib/sanitize.js";
|
||||
|
||||
interface CommentTarget {
|
||||
entityType: CommentEntityType;
|
||||
entityId: string;
|
||||
}
|
||||
|
||||
interface CommentAuthor {
|
||||
id: string;
|
||||
name: string | null;
|
||||
@@ -32,7 +38,7 @@ interface CommentItem {
|
||||
}
|
||||
|
||||
interface CommentThreadProps {
|
||||
entityId: string;
|
||||
commentTarget: CommentTarget;
|
||||
}
|
||||
|
||||
function formatRelativeTime(date: Date | string): string {
|
||||
@@ -110,18 +116,16 @@ function CommentBody({ body }: { body: string }) {
|
||||
|
||||
function SingleComment({
|
||||
comment,
|
||||
entityId,
|
||||
commentTarget,
|
||||
isReply = false,
|
||||
}: {
|
||||
comment: CommentItem | CommentReply;
|
||||
entityId: string;
|
||||
commentTarget: CommentTarget;
|
||||
isReply?: boolean;
|
||||
}) {
|
||||
const [showReplyInput, setShowReplyInput] = useState(false);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const utils = trpc.useUtils();
|
||||
const commentTarget = { entityType: "estimate" as const, entityId };
|
||||
|
||||
const createMutation = trpc.comment.create.useMutation({
|
||||
onSuccess: () => {
|
||||
setShowReplyInput(false);
|
||||
@@ -212,17 +216,17 @@ function SingleComment({
|
||||
{/* Inline reply input */}
|
||||
{showReplyInput && (
|
||||
<div className="mt-3">
|
||||
<CommentInput
|
||||
entityType={commentTarget.entityType}
|
||||
entityId={entityId}
|
||||
parentId={comment.id}
|
||||
onSubmit={(replyBody) => {
|
||||
createMutation.mutate({
|
||||
entityType: commentTarget.entityType,
|
||||
entityId,
|
||||
parentId: comment.id,
|
||||
body: replyBody,
|
||||
});
|
||||
<CommentInput
|
||||
entityType={commentTarget.entityType}
|
||||
entityId={commentTarget.entityId}
|
||||
parentId={comment.id}
|
||||
onSubmit={(replyBody) => {
|
||||
createMutation.mutate({
|
||||
entityType: commentTarget.entityType,
|
||||
entityId: commentTarget.entityId,
|
||||
parentId: comment.id,
|
||||
body: replyBody,
|
||||
});
|
||||
}}
|
||||
onCancel={() => setShowReplyInput(false)}
|
||||
isSubmitting={createMutation.isPending}
|
||||
@@ -255,7 +259,7 @@ function SingleComment({
|
||||
<SingleComment
|
||||
key={reply.id}
|
||||
comment={reply}
|
||||
entityId={entityId}
|
||||
commentTarget={commentTarget}
|
||||
isReply
|
||||
/>
|
||||
))}
|
||||
@@ -265,9 +269,8 @@ function SingleComment({
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentThread({ entityId }: CommentThreadProps) {
|
||||
export function CommentThread({ commentTarget }: CommentThreadProps) {
|
||||
const utils = trpc.useUtils();
|
||||
const commentTarget = { entityType: "estimate" as const, entityId };
|
||||
|
||||
const commentsQuery = trpc.comment.list.useQuery(
|
||||
commentTarget,
|
||||
@@ -308,7 +311,7 @@ export function CommentThread({ entityId }: CommentThreadProps) {
|
||||
<SingleComment
|
||||
key={comment.id}
|
||||
comment={comment}
|
||||
entityId={entityId}
|
||||
commentTarget={commentTarget}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -318,11 +321,11 @@ export function CommentThread({ entityId }: CommentThreadProps) {
|
||||
<div className="border-t border-gray-200 dark:border-gray-700 pt-4">
|
||||
<CommentInput
|
||||
entityType={commentTarget.entityType}
|
||||
entityId={entityId}
|
||||
entityId={commentTarget.entityId}
|
||||
onSubmit={(body) => {
|
||||
createMutation.mutate({
|
||||
entityType: commentTarget.entityType,
|
||||
entityId,
|
||||
entityId: commentTarget.entityId,
|
||||
body,
|
||||
});
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user