mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
more tooltips
This commit is contained in:
@@ -1,13 +1,48 @@
|
|||||||
import { IModuleItem } from "@/features/local/modules/IModuleItem";
|
import { IModuleItem } from "@/features/local/modules/IModuleItem";
|
||||||
import { getModuleItemUrl } from "@/services/urlUtils";
|
import { getModuleItemUrl } from "@/services/urlUtils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ReactNode, useRef, useState } from "react";
|
import { ReactNode } from "react";
|
||||||
import { useCourseContext } from "../../context/courseContext";
|
import { useCourseContext } from "../../context/courseContext";
|
||||||
|
import { useTooltip } from "@/components/useTooltip";
|
||||||
|
import MarkdownDisplay from "@/components/MarkdownDisplay";
|
||||||
import { DraggableItem } from "../../context/drag/draggingContext";
|
import { DraggableItem } from "../../context/drag/draggingContext";
|
||||||
import ClientOnly from "@/components/ClientOnly";
|
import ClientOnly from "@/components/ClientOnly";
|
||||||
import { useDragStyleContext } from "../../context/drag/dragStyleContext";
|
import { useDragStyleContext } from "../../context/drag/dragStyleContext";
|
||||||
import { Tooltip } from "../../../../../components/Tooltip";
|
import { Tooltip } from "../../../../../components/Tooltip";
|
||||||
|
|
||||||
|
function getPreviewContent(
|
||||||
|
type: "assignment" | "page" | "quiz",
|
||||||
|
item: IModuleItem
|
||||||
|
): ReactNode {
|
||||||
|
if (type === "assignment" && "description" in item) {
|
||||||
|
const assignment = item as {
|
||||||
|
description: string;
|
||||||
|
githubClassroomAssignmentShareLink?: string;
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<MarkdownDisplay
|
||||||
|
markdown={assignment.description}
|
||||||
|
replaceText={[
|
||||||
|
{
|
||||||
|
source: "insert_github_classroom_url",
|
||||||
|
destination: assignment.githubClassroomAssignmentShareLink || "",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (type === "page" && "text" in item) {
|
||||||
|
return <MarkdownDisplay markdown={item.text as string} />;
|
||||||
|
} else if (type === "quiz" && "questions" in item) {
|
||||||
|
const quiz = item as { questions: { text: string }[] };
|
||||||
|
return quiz.questions.map((q, i: number) => (
|
||||||
|
<div key={i} className="">
|
||||||
|
<MarkdownDisplay markdown={q.text as string} />
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function ItemInDay({
|
export function ItemInDay({
|
||||||
type,
|
type,
|
||||||
moduleName,
|
moduleName,
|
||||||
@@ -23,8 +58,8 @@ export function ItemInDay({
|
|||||||
}) {
|
}) {
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
const { setIsDragging } = useDragStyleContext();
|
const { setIsDragging } = useDragStyleContext();
|
||||||
const linkRef = useRef<HTMLAnchorElement>(null);
|
const { visible, targetRef, showTooltip, hideTooltip } = useTooltip(500);
|
||||||
const [tooltipVisible, setTooltipVisible] = useState(false);
|
|
||||||
return (
|
return (
|
||||||
<div className={" relative group "}>
|
<div className={" relative group "}>
|
||||||
<Link
|
<Link
|
||||||
@@ -52,18 +87,26 @@ export function ItemInDay({
|
|||||||
);
|
);
|
||||||
setIsDragging(true);
|
setIsDragging(true);
|
||||||
}}
|
}}
|
||||||
onMouseEnter={() => setTooltipVisible(true)}
|
onMouseEnter={showTooltip}
|
||||||
onMouseLeave={() => setTooltipVisible(false)}
|
onMouseLeave={hideTooltip}
|
||||||
ref={linkRef}
|
ref={targetRef}
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Link>
|
</Link>
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
|
{status === "published" ? (
|
||||||
|
getPreviewContent(type, item) && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
message={message}
|
message={
|
||||||
targetRef={linkRef}
|
<div className="max-w-md">{getPreviewContent(type, item)}</div>
|
||||||
visible={tooltipVisible && status === "incomplete"}
|
}
|
||||||
|
targetRef={targetRef}
|
||||||
|
visible={visible}
|
||||||
/>
|
/>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<Tooltip message={message} targetRef={targetRef} visible={visible} />
|
||||||
|
)}
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user