Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | 5x 5x 3x 3x 3x 3x 3x 5x 5x 2x 2x 2x 2x 1x 1x 1x 1x 5x 1x 1x 1x | import RichMarkdown from "@/components/chat/RichMarkdown/RichMarkdown";
import {
MessageListConfig,
NoteConfig,
PinnedMessageConfig,
ShortcutsConfig,
} from "@/objects/Dashboard";
import { APP_ROUTES } from "@/routes/const";
import { ArrowUpRight, MessageSquareQuote, Quote, X } from "lucide-react";
import React from "react";
import { Link } from "react-router-dom";
import { WidgetBodyProps } from "./types";
import { parseServerDate } from "@/util/time";
// ─── Note ─────────────────────────────────────────────────────────────────────
export const NoteWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const config = widget.config as unknown as NoteConfig;
const markdown = (config?.markdown ?? "").trim();
if (!markdown) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
Empty note — open Configure to write something.
</p>
);
}
return <RichMarkdown content={markdown} />;
};
// ─── Shortcuts ────────────────────────────────────────────────────────────────
export const ShortcutsWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const config = widget.config as unknown as ShortcutsConfig;
const links = config?.links ?? [];
Iif (links.length === 0) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
No shortcuts yet.
</p>
);
}
return (
<ul className="space-y-1">
{links.map((link, index) => (
<li key={`${link.href}-${index}`}>
<Link
to={link.href}
className="group flex items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-xs text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700/60 transition-colors"
>
<span className="truncate">{link.label}</span>
<ArrowUpRight className="w-3.5 h-3.5 shrink-0 text-gray-300 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-300" />
</Link>
</li>
))}
</ul>
);
};
// ─── Pinned message ───────────────────────────────────────────────────────────
export const PinnedMessageWidgetBody: React.FC<WidgetBodyProps> = ({
widget,
}) => {
const config = widget.config as unknown as PinnedMessageConfig;
const content = (config?.content ?? "").trim();
if (!content) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
Nothing pinned yet.
</p>
);
}
// The conversation may have been deleted since the pin; the snapshot still
// renders, and the link is only offered when we have somewhere to send them.
const conversationId = config.conversation_id;
return (
<div className="h-full flex flex-col">
<div className="flex items-start gap-2 flex-1 min-h-0">
<Quote className="w-3.5 h-3.5 mt-0.5 shrink-0 text-gray-300 dark:text-gray-600" />
<div className="min-w-0 flex-1 overflow-auto">
<RichMarkdown content={content} />
</div>
</div>
<div className="mt-2 pt-2 border-t border-gray-100 dark:border-gray-700/60 flex items-center justify-between gap-2">
<span className="flex items-center gap-1 text-[11px] text-gray-400 dark:text-gray-500 truncate">
<MessageSquareQuote className="w-3 h-3 shrink-0" />
{config.source_label || `From a ${config.role} message`}
</span>
{conversationId && (
<Link
to={`${APP_ROUTES.USER.activity}?conversation=${conversationId}`}
className="text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:underline shrink-0"
>
Open chat
</Link>
)}
</div>
</div>
);
};
// ─── Saved messages ───────────────────────────────────────────────────────────
/** A running list of chat answers the user saved from conversations.
*
* Each entry keeps a link back to its conversation where one was recorded,
* so a saved answer stays traceable to where it came from.
*/
export const MessageListWidgetBody: React.FC<WidgetBodyProps> = ({
widget,
onRemoveItem,
}) => {
const config = widget.config as unknown as MessageListConfig;
const items = config?.items ?? [];
const [expanded, setExpanded] = React.useState<string | null>(null);
if (items.length === 0) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
Nothing saved yet. Use “Save to dashboard” on any chat message.
</p>
);
}
return (
<ul className="divide-y divide-gray-100 dark:divide-gray-700/60">
{items.map((item) => {
const open = expanded === item.id;
return (
<li key={item.id} className="group py-2 first:pt-0">
<div className="flex items-start gap-2">
<button
type="button"
onClick={() => setExpanded(open ? null : item.id)}
className="min-w-0 flex-1 text-left"
>
<div
className={
open
? "text-xs text-gray-700 dark:text-gray-200"
: "text-xs text-gray-700 dark:text-gray-200 line-clamp-3"
}
>
{open ? (
<RichMarkdown content={item.content} />
) : (
item.content
)}
</div>
</button>
{onRemoveItem && (
<button
type="button"
title="Remove from list"
onClick={() => onRemoveItem(item.id)}
className="shrink-0 rounded p-1 text-gray-300 opacity-0 group-hover:opacity-100 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-all"
>
<X className="w-3 h-3" />
</button>
)}
</div>
<div className="mt-1 flex items-center gap-2 text-[10px] text-gray-400 dark:text-gray-500">
<span className="truncate">
{item.source_label || item.role}
{item.saved_at ? ` · ${savedOn(item.saved_at)}` : ""}
</span>
{item.conversation_id && (
<Link
to={`${APP_ROUTES.USER.activity}?conversation=${item.conversation_id}`}
className="shrink-0 font-medium text-blue-600 dark:text-blue-400 hover:underline"
>
Open chat
</Link>
)}
</div>
</li>
);
})}
</ul>
);
};
const savedOn = (iso: string): string => {
const date = parseServerDate(iso);
Iif (Number.isNaN(date.getTime())) return "";
return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
};
|