added custom command view for flow

This commit is contained in:
fgrreloaded
2025-02-17 21:16:41 +05:30
parent 0908f47072
commit a0606e5661
2 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
"use client";
import { Check, Copy } from "lucide-react";
import { useState } from "react";
interface CommandDisplayProps {
command: string;
}
export function CommandDisplay({ command }: CommandDisplayProps) {
const [copied, setCopied] = useState(false);
const copyToClipboard = async () => {
await navigator.clipboard.writeText(command);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
<div className="relative group">
<div className="bg-gray-950/90 border border-gray-800 rounded-lg p-4 font-mono text-sm text-gray-300 overflow-x-auto">
<button
type="button"
onClick={copyToClipboard}
className="absolute right-4 top-1/2 -translate-y-1/2 p-2 rounded-md hover:bg-gray-800 transition-colors"
>
{copied ? (
<Check className="w-4 h-4 text-green-500" />
) : (
<Copy className="w-4 h-4 text-gray-400" />
)}
</button>
<pre className="pr-12">{command}</pre>
</div>
</div>
);
}

View File

@@ -12,6 +12,7 @@ import { useCallback, useState } from "react";
import { TechSelector } from "./TechSelector"; import { TechSelector } from "./TechSelector";
import "@xyflow/react/dist/style.css"; import "@xyflow/react/dist/style.css";
import { initialNodes } from "@/lib/constant"; import { initialNodes } from "@/lib/constant";
import { CommandDisplay } from "./CommandDisplay";
import { TechNodeComponent } from "./TechNodeComponent"; import { TechNodeComponent } from "./TechNodeComponent";
const initialEdges = [ const initialEdges = [
@@ -136,10 +137,29 @@ const CustomizableStack = () => {
[nodes, edges, setEdges, setNodes], [nodes, edges, setEdges, setNodes],
); );
const generateCommand = useCallback(() => {
const flags: string[] = ["-y"];
if (activeNodes.database !== "libsql") {
flags.splice(flags.indexOf("-y"), 1);
flags.push(`--database ${activeNodes.database}`);
}
if (activeNodes.auth !== "better-auth") {
flags.splice(flags.indexOf("-y"), 1);
flags.push("--no-auth");
}
return `npx create-better-t-stack my-app ${flags.join(" ")}`;
}, [activeNodes]);
return ( return (
<div className="relative w-full max-w-5xl mx-auto z-50"> <div className="relative w-full max-w-5xl mx-auto z-50 mt-24">
<TechSelector onSelect={handleTechSelect} activeNodes={activeNodes} /> <TechSelector onSelect={handleTechSelect} activeNodes={activeNodes} />
<div className="absolute top-4 right-4 z-50 max-w-xs bg-gray-950/10 p-4 rounded-xl border border-gray-800 backdrop-blur-3xl"> <div className="absolute -top-16 left-1/2 -translate-x-1/2 z-50 w-96">
<CommandDisplay command={generateCommand()} />
</div>
<div className="bg-gray-950/10 p-4 absolute top-4 right-4 z-50 w-96 rounded-xl border border-gray-800 backdrop-blur-3xl">
<div className="text-sm text-gray-300"> <div className="text-sm text-gray-300">
Select technologies from the left panel to customize your stack. The Select technologies from the left panel to customize your stack. The
graph will automatically update connections. graph will automatically update connections.