Add login gate, calculation history, and AI markdown download.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { RotateCw } from "lucide-react";
|
||||
import { Download, RotateCw } from "lucide-react";
|
||||
import Markdown from "react-markdown";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TaijiIcon } from "@/components/svg/taiji";
|
||||
import { downloadMarkdown } from "@/lib/history/storage";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function ResultAI({
|
||||
@@ -12,6 +13,8 @@ function ResultAI({
|
||||
error,
|
||||
panel = false,
|
||||
emptyHint = "完成左侧填写并起卦/排盘后,点击「AI 解读」",
|
||||
downloadFilename,
|
||||
downloadPreamble,
|
||||
}: {
|
||||
completion: string;
|
||||
isLoading: boolean;
|
||||
@@ -19,6 +22,8 @@ function ResultAI({
|
||||
error: string;
|
||||
panel?: boolean;
|
||||
emptyHint?: string;
|
||||
downloadFilename?: string;
|
||||
downloadPreamble?: string;
|
||||
}) {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const [autoScroll, setAutoScroll] = useState(false);
|
||||
@@ -44,6 +49,16 @@ function ResultAI({
|
||||
}
|
||||
}
|
||||
|
||||
function handleDownload() {
|
||||
if (!completion || !downloadFilename) {
|
||||
return;
|
||||
}
|
||||
const body = downloadPreamble
|
||||
? `${downloadPreamble}\n\n---\n\n${completion}`
|
||||
: completion;
|
||||
downloadMarkdown(body, downloadFilename);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -93,10 +108,18 @@ function ResultAI({
|
||||
</div>
|
||||
)}
|
||||
{!isLoading && (completion || error) && (
|
||||
<Button onClick={onCompletion} size="sm" variant="outline" className="mt-4">
|
||||
<RotateCw size={16} className="mr-1" />
|
||||
重新生成
|
||||
</Button>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{completion && downloadFilename && (
|
||||
<Button size="sm" variant="outline" onClick={handleDownload}>
|
||||
<Download size={16} className="mr-1" />
|
||||
下载 Markdown
|
||||
</Button>
|
||||
)}
|
||||
<Button onClick={onCompletion} size="sm" variant="outline">
|
||||
<RotateCw size={16} className="mr-1" />
|
||||
重新生成
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user