mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-05 09:33:07 +00:00
feat: add markdown preview functionality to ContextView component
- Implemented a toggle button to switch between edit and preview modes for markdown files. - Added a new state to manage preview mode and a utility function to identify markdown file types. - Enhanced the rendering logic to display markdown content in a preview card when in preview mode.
This commit is contained in:
@@ -17,6 +17,8 @@ import {
|
|||||||
File,
|
File,
|
||||||
X,
|
X,
|
||||||
BookOpen,
|
BookOpen,
|
||||||
|
EditIcon,
|
||||||
|
Eye,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
useKeyboardShortcuts,
|
useKeyboardShortcuts,
|
||||||
@@ -34,6 +36,7 @@ import {
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Markdown } from "../ui/markdown";
|
||||||
|
|
||||||
interface ContextFile {
|
interface ContextFile {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -60,6 +63,7 @@ export function ContextView() {
|
|||||||
);
|
);
|
||||||
const [newFileContent, setNewFileContent] = useState("");
|
const [newFileContent, setNewFileContent] = useState("");
|
||||||
const [isDropHovering, setIsDropHovering] = useState(false);
|
const [isDropHovering, setIsDropHovering] = useState(false);
|
||||||
|
const [isPreviewMode, setIsPreviewMode] = useState(false);
|
||||||
|
|
||||||
// Keyboard shortcuts for this view
|
// Keyboard shortcuts for this view
|
||||||
const contextShortcuts: KeyboardShortcut[] = useMemo(
|
const contextShortcuts: KeyboardShortcut[] = useMemo(
|
||||||
@@ -80,6 +84,11 @@ export function ContextView() {
|
|||||||
return `${currentProject.path}/.automaker/context`;
|
return `${currentProject.path}/.automaker/context`;
|
||||||
}, [currentProject]);
|
}, [currentProject]);
|
||||||
|
|
||||||
|
const isMarkdownFile = (filename: string): boolean => {
|
||||||
|
const ext = filename.toLowerCase().substring(filename.lastIndexOf("."));
|
||||||
|
return ext === ".md" || ext === ".markdown";
|
||||||
|
};
|
||||||
|
|
||||||
// Determine if a file is an image based on extension
|
// Determine if a file is an image based on extension
|
||||||
const isImageFile = (filename: string): boolean => {
|
const isImageFile = (filename: string): boolean => {
|
||||||
const imageExtensions = [
|
const imageExtensions = [
|
||||||
@@ -151,6 +160,7 @@ export function ContextView() {
|
|||||||
// Could add a confirmation dialog here
|
// Could add a confirmation dialog here
|
||||||
}
|
}
|
||||||
loadFileContent(file);
|
loadFileContent(file);
|
||||||
|
setIsPreviewMode(isMarkdownFile(file.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save current file
|
// Save current file
|
||||||
@@ -448,6 +458,27 @@ export function ContextView() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
{selectedFile.type === "text" &&
|
||||||
|
isMarkdownFile(selectedFile.name) && (
|
||||||
|
<Button
|
||||||
|
variant={"outline"}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setIsPreviewMode(!isPreviewMode)}
|
||||||
|
data-testid="toggle-preview-mode"
|
||||||
|
>
|
||||||
|
{isPreviewMode ? (
|
||||||
|
<>
|
||||||
|
<EditIcon className="w-4 h-4 mr-2" />
|
||||||
|
Edit
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Eye className="w-4 h-4 mr-2" />
|
||||||
|
Preview
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{selectedFile.type === "text" && (
|
{selectedFile.type === "text" && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -484,6 +515,10 @@ export function ContextView() {
|
|||||||
className="max-w-full max-h-full object-contain"
|
className="max-w-full max-h-full object-contain"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : isPreviewMode ? (
|
||||||
|
<Card className="h-full overflow-auto p-4" data-testid="markdown-preview">
|
||||||
|
<Markdown>{editedContent}</Markdown>
|
||||||
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
<Card className="h-full overflow-hidden">
|
<Card className="h-full overflow-hidden">
|
||||||
<textarea
|
<textarea
|
||||||
|
|||||||
Reference in New Issue
Block a user