mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Update preview version Merge latest from Composer Support creating new files Update version to 2.9.0 preview Add minor fixes Update autocomplete call and prefix logic Merge Project mode into 2.9.0-preview Squashed commits from: commita762629deeAuthor: Logan Yang <logancyang@gmail.com> Date: Tue Mar 25 16:29:31 2025 -0700 Add projectEnabled flag to CustomModel interface To commit1694357823Author: wyh <emt934841028@gmail.com> Date: Wed Feb 19 14:45:22 2025 +0800 feat: Support project-based feature. Fix package vulnerabilities Prerelease 250325 Update label for PROJECT_CHAIN to "Plus Projects (alpha)" in BasicSettings component
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import React, { useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Check, Loader2 } from "lucide-react";
|
|
|
|
interface CodeBlockProps {
|
|
code: string;
|
|
path?: string;
|
|
onApply?: (path: string, code: string) => Promise<void>;
|
|
}
|
|
|
|
export const CodeBlock: React.FC<CodeBlockProps> = ({ code, path, onApply }) => {
|
|
const [isApplying, setIsApplying] = useState(false);
|
|
|
|
const handleApply = async () => {
|
|
if (!path || !onApply) return;
|
|
|
|
setIsApplying(true);
|
|
try {
|
|
await onApply(path, code);
|
|
} finally {
|
|
setIsApplying(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="border border-border border-solid rounded-md my-2 flex flex-col overflow-hidden">
|
|
{path && (
|
|
<div className="flex justify-between items-center border-[0px] border-b border-border border-solid gap-2 p-2 overflow-hidden">
|
|
<div className="text-xs p-1 text-muted-foreground truncate flex-1">{path}</div>
|
|
{onApply && (
|
|
<Button
|
|
className="text-muted"
|
|
variant="ghost2"
|
|
size="fit"
|
|
onClick={handleApply}
|
|
disabled={isApplying}
|
|
>
|
|
{isApplying ? (
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
) : (
|
|
<Check className="h-4 w-4" />
|
|
)}
|
|
Apply
|
|
</Button>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
<pre className="m-0 border-none">
|
|
<code>{code}</code>
|
|
</pre>
|
|
</div>
|
|
);
|
|
};
|