forked from PostHog/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanContent.tsx
More file actions
46 lines (37 loc) · 1.13 KB
/
PlanContent.tsx
File metadata and controls
46 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Box } from "@radix-ui/themes";
import { useEffect, useRef } from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
const planScrollPosition = new Map<string, number>();
interface PlanContentProps {
id: string;
plan: string;
}
export function PlanContent({ id, plan }: PlanContentProps) {
const scrollRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = scrollRef.current;
if (!el) return;
const position = planScrollPosition.get(id);
if (position !== undefined) {
el.scrollTop = position;
}
const handleScroll = () => {
planScrollPosition.set(id, el.scrollTop);
};
el.addEventListener("scroll", handleScroll, { passive: true });
return () => {
el.removeEventListener("scroll", handleScroll);
};
}, [id]);
return (
<Box
ref={scrollRef}
className="max-h-[50vh] max-w-[750px] overflow-y-auto rounded-lg border-2 border-blue-6 bg-blue-2 p-4"
>
<Box className="plan-markdown text-blue-12">
<ReactMarkdown remarkPlugins={[remarkGfm]}>{plan}</ReactMarkdown>
</Box>
</Box>
);
}