[dyad] Make headline sections collapsible - wrote 1 file(s)
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import type { HeadlineNode } from "@/app/actions";
|
import type { HeadlineNode } from "@/app/actions";
|
||||||
import { KeywordHighlighter } from "./keyword-highlighter";
|
import { KeywordHighlighter } from "./keyword-highlighter";
|
||||||
|
import { ChevronDown } from "lucide-react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
interface HeadlineTreeProps {
|
interface HeadlineTreeProps {
|
||||||
headlines: HeadlineNode[];
|
headlines: HeadlineNode[];
|
||||||
@@ -18,11 +21,19 @@ const HeadlineNodeDisplay = ({
|
|||||||
level: number;
|
level: number;
|
||||||
keyword?: string | null;
|
keyword?: string | null;
|
||||||
}) => {
|
}) => {
|
||||||
|
const isCollapsible =
|
||||||
|
node.level === 2 && node.children && node.children.length > 0;
|
||||||
|
const [isCollapsed, setIsCollapsed] = useState(true);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className="flex items-center gap-3 py-2.5 pr-4 border-t"
|
className={cn(
|
||||||
|
"flex items-center gap-3 py-2.5 pr-4 border-t",
|
||||||
|
isCollapsible && "cursor-pointer hover:bg-muted/50"
|
||||||
|
)}
|
||||||
style={{ paddingLeft: `${16 + level * 24}px` }}
|
style={{ paddingLeft: `${16 + level * 24}px` }}
|
||||||
|
onClick={() => isCollapsible && setIsCollapsed(!isCollapsed)}
|
||||||
>
|
>
|
||||||
<Badge
|
<Badge
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -36,8 +47,18 @@ const HeadlineNodeDisplay = ({
|
|||||||
<p className="text-sm text-muted-foreground flex-shrink-0 w-10 text-right">
|
<p className="text-sm text-muted-foreground flex-shrink-0 w-10 text-right">
|
||||||
{node.length}
|
{node.length}
|
||||||
</p>
|
</p>
|
||||||
|
{isCollapsible && (
|
||||||
|
<ChevronDown
|
||||||
|
className={cn(
|
||||||
|
"h-4 w-4 text-muted-foreground transition-transform",
|
||||||
|
!isCollapsed && "rotate-180"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{node.children?.map((child, index) => (
|
{node.children &&
|
||||||
|
(!isCollapsible || !isCollapsed) &&
|
||||||
|
node.children.map((child, index) => (
|
||||||
<HeadlineNodeDisplay
|
<HeadlineNodeDisplay
|
||||||
key={index}
|
key={index}
|
||||||
node={child}
|
node={child}
|
||||||
|
|||||||
Reference in New Issue
Block a user