diff --git a/app/form/admin/result/[id]/client.tsx b/app/form/admin/result/[id]/client.tsx index c0039f6..d55b8ad 100644 --- a/app/form/admin/result/[id]/client.tsx +++ b/app/form/admin/result/[id]/client.tsx @@ -4,8 +4,17 @@ import React, { useState, useEffect, useRef } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; -import { toast } from "sonner"; -import { Copy, Check, Users, Calendar, Clock, History } from "lucide-react"; +import { + ContextMenu, + ContextMenuTrigger, + ContextMenuContent, + ContextMenuLabel, + ContextMenuSeparator, + ContextMenuItem, + ContextMenuGroup +} from "@/components/ui/context-menu"; +import { Copy, Check, Users, Calendar, Clock } from "lucide-react"; +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import Image from 'next/image'; interface Question { @@ -27,26 +36,12 @@ interface SubmissionDetailClientProps { answers: Record; } -interface ContextMenuState { - visible: boolean; - x: number; - y: number; - questionId: string | null; -} - export default function SubmissionDetailClient({ submission, questions, answers, }: SubmissionDetailClientProps) { const [copiedId, setCopiedId] = useState(null); - const [contextMenu, setContextMenu] = useState({ - visible: false, - x: 0, - y: 0, - questionId: null, - }); - const menuRef = useRef(null); const handleCopy = (text: string, id: string) => { if (!text) return; @@ -55,47 +50,13 @@ export default function SubmissionDetailClient({ setTimeout(() => setCopiedId(null), 2000); }; - const handleContextMenu = (e: React.MouseEvent, questionId: string) => { - e.preventDefault(); - setContextMenu({ visible: true, x: e.clientX, y: e.clientY, questionId }); - }; - - const closeMenu = () => { - setContextMenu((prev) => ({ ...prev, visible: false, questionId: null })); - }; - - // Close menu on click outside or scroll - useEffect(() => { - const handleClick = (e: MouseEvent) => { - if (menuRef.current && !menuRef.current.contains(e.target as Node)) { - closeMenu(); - } - }; - document.addEventListener("mousedown", handleClick); - document.addEventListener("scroll", closeMenu, true); - return () => { - document.removeEventListener("mousedown", handleClick); - document.removeEventListener("scroll", closeMenu, true); - }; - }, []); - const userLabel = submission.userName ? `${submission.userName} (${submission.userDiscordId || "N/A"})` : submission.userDiscordId || "Anonymous"; const editHistory = Array.isArray(submission.editHistory) ? submission.editHistory : []; - // Build context menu data for the right-clicked question - const ctxQuestion = questions.find((q) => q.id === contextMenu.questionId); - const ctxAnswerHistory: { editedAt: string; answer: string }[] = []; - if (contextMenu.questionId) { - for (const edit of editHistory) { - ctxAnswerHistory.push({ - editedAt: edit.editedAt, - answer: edit.oldAnswers[contextMenu.questionId] ?? "", - }); - } - } + return (
@@ -138,12 +99,17 @@ export default function SubmissionDetailClient({ (edit) => (edit.oldAnswers[q.id] ?? "") !== ansValue ); + const qAnswerHistory = editHistory.map((edit) => ({ + editedAt: edit.editedAt, + answer: edit.oldAnswers[q.id] ?? "", + })); + return ( - handleContextMenu(e, q.id)} - className={wasEdited ? "cursor-context-menu" : ""} - > + + +
- {/* Context Menu */} - {contextMenu.visible && ctxQuestion && ( -
- {/* Header */} -
-

- History -

-

- {ctxQuestion.label} -

-
- {/* Edit History timestamps */} - {editHistory.length > 0 && ( -
-

- Edit History: -

-
    - {editHistory.map((edit, idx) => ( -
  • - - {new Date(edit.editedAt).toLocaleString()} -
  • - ))} -
-
- )} - - {/* All Previous Answers */} -
-

- Previous Answers: -

- {ctxAnswerHistory.length === 0 ? ( -

No edit history for this question.

- ) : ( -
- {ctxAnswerHistory.map((entry, idx) => ( -
-
- - {new Date(entry.editedAt).toLocaleString()} -
- - {entry.answer || No response} - -
- ))} -
- )} -
- - {/* Footer */} -
- -
-
- )}
); } diff --git a/components/ui/scroll-area.tsx b/components/ui/scroll-area.tsx new file mode 100644 index 0000000..facbbe7 --- /dev/null +++ b/components/ui/scroll-area.tsx @@ -0,0 +1,55 @@ +"use client" + +import * as React from "react" +import { ScrollArea as ScrollAreaPrimitive } from "radix-ui" + +import { cn } from "@/lib/utils" + +function ScrollArea({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + + {children} + + + + + ) +} + +function ScrollBar({ + className, + orientation = "vertical", + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +export { ScrollArea, ScrollBar }