Awakened_RiShre / src /components /DeployModal.tsx
usrrootkali's picture
Update src/components/DeployModal.tsx
7155832 verified
Raw History Blame Contribute Delete
10.2 kB
import React, { useState } from 'react';
import { Project } from '../types';
import { exportProjectAsZip } from '../utils/exportZip';
import {
UploadCloud,
X,
ExternalLink,
Download,
Copy,
Check,
} from 'lucide-react';
interface DeployModalProps {
isOpen: boolean;
onClose: () => void;
currentProject: Project;
}
export const DeployModal: React.FC<DeployModalProps> = ({
isOpen,
onClose,
currentProject,
}) => {
const [copied, setCopied] = useState(false);
const [isExporting, setIsExporting] = useState(false);
const [selectedFormat, setSelectedFormat] = useState<'project' | 'template' | 'python'>('project');
if (!isOpen) return null;
const projectYamlSnippet = `---
title: ${currentProject.name || 'RiShre – AI Vibe Coding Platform'}
emoji: ⚡
colorFrom: purple
colorTo: fuchsia
sdk: static
pinned: false
app_build_command: npm run build
app_file: build/index.html
license: mit
---`;
const templateYamlSnippet = `---
title: ${currentProject.name || 'RiShre – AI Vibe Coding Platform'}
emoji: ⚡
colorFrom: purple
colorTo: fuchsia
sdk: static
pinned: false
app_file: index.html
license: mit
---`;
const pythonYamlSnippet = `---
title: ${currentProject.name || 'RiShre – AI Vibe Coding Platform'}
emoji: ⚡
colorFrom: purple
colorTo: fuchsia
sdk: docker
pinned: false
app_file: app.py
---`;
const activeSnippet =
selectedFormat === 'project'
? projectYamlSnippet
: selectedFormat === 'template'
? templateYamlSnippet
: pythonYamlSnippet;
const handleCopyYaml = () => {
navigator.clipboard.writeText(activeSnippet);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
const handleDownloadBundle = async () => {
setIsExporting(true);
try {
await exportProjectAsZip(currentProject);
} finally {
setIsExporting(false);
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-md p-4 animate-in fade-in">
<div className="w-full max-w-xl bg-[#0c061a] border border-purple-500/30 rounded-3xl shadow-[0_0_60px_rgba(168,85,247,0.25)] overflow-hidden flex flex-col">
{/* Header */}
<div className="px-6 py-4 bg-[#120826]/90 border-b border-purple-500/25 flex items-center justify-between">
<div className="flex items-center gap-2.5">
<div className="w-6 h-6 rounded-lg bg-gradient-to-tr from-purple-600 to-fuchsia-500 flex items-center justify-center shadow-[0_0_10px_rgba(168,85,247,0.4)]">
<UploadCloud className="w-3.5 h-3.5 text-white" />
</div>
<h2 className="text-sm font-bold text-white tracking-wide">
Deploy to Hugging Face Spaces (Static)
</h2>
</div>
<button
onClick={onClose}
aria-label="Close"
className="p-1 rounded-lg text-purple-300 hover:text-white transition-colors cursor-pointer"
>
<X className="w-4 h-4" />
</button>
</div>
{/* Content */}
<div className="p-6 space-y-5 overflow-y-auto max-h-[75vh] text-xs leading-relaxed text-purple-200">
<p>
RiShre projects are completely self-contained static web applications optimized for{' '}
<strong className="text-white">Hugging Face Static Spaces</strong> with free CPU hosting!
</p>
<div className="space-y-3">
<div className="flex gap-3 items-start bg-[#120826] p-4 rounded-2xl border border-purple-500/25">
<span className="w-6 h-6 rounded-full bg-purple-500/20 text-fuchsia-400 font-bold font-mono flex items-center justify-center shrink-0 border border-purple-500/40">
1
</span>
<div className="flex-1">
<h4 className="font-bold text-white mb-1">Create a New Space on Hugging Face</h4>
<p className="text-purple-300/80 mb-2">
Go to Hugging Face and choose the <strong className="text-fuchsia-300">Static SDK</strong> on the free tier.
</p>
<a
href="https://huggingface.co/new-space"
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-purple-600/30 hover:bg-purple-600/50 border border-purple-400/40 text-purple-200 text-xs font-semibold transition-colors"
>
<span>Open Hugging Face New Space</span>
<ExternalLink className="w-3.5 h-3.5 text-fuchsia-400" />
</a>
</div>
</div>
<div className="flex gap-3 items-start bg-[#120826] p-4 rounded-2xl border border-purple-500/25">
<span className="w-6 h-6 rounded-full bg-purple-500/20 text-fuchsia-400 font-bold font-mono flex items-center justify-center shrink-0 border border-purple-500/40">
2
</span>
<div className="flex-1">
<h4 className="font-bold text-white mb-1">Hugging Face Space README Metadata</h4>
<div className="flex items-center gap-1.5 mb-2.5">
<button
onClick={() => setSelectedFormat('project')}
className={`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all cursor-pointer ${
selectedFormat === 'project'
? 'bg-purple-600 text-white shadow-[0_0_10px_rgba(168,85,247,0.4)]'
: 'bg-[#180b33] text-purple-300 hover:text-white border border-purple-500/20'
}`}
>
HF Build (npm run build)
</button>
<button
onClick={() => setSelectedFormat('template')}
className={`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all cursor-pointer ${
selectedFormat === 'template'
? 'bg-purple-600 text-white shadow-[0_0_10px_rgba(168,85,247,0.4)]'
: 'bg-[#180b33] text-purple-300 hover:text-white border border-purple-500/20'
}`}
>
Direct Static
</button>
<button
onClick={() => setSelectedFormat('python')}
className={`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all cursor-pointer ${
selectedFormat === 'python'
? 'bg-purple-600 text-white shadow-[0_0_10px_rgba(168,85,247,0.4)]'
: 'bg-[#180b33] text-purple-300 hover:text-white border border-purple-500/20'
}`}
>
Docker (app.py)
</button>
</div>
<div className="relative bg-[#080314] border border-purple-500/30 rounded-xl p-3 font-mono text-[11px] text-fuchsia-300">
<pre className="overflow-x-auto whitespace-pre">{activeSnippet}</pre>
<button
onClick={handleCopyYaml}
className="absolute top-2 right-2 p-1.5 rounded-lg bg-[#1a0a38] hover:bg-[#26104f] text-purple-200 transition-colors cursor-pointer border border-purple-500/30"
title="Copy YAML"
>
{copied ? <Check className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5 text-purple-300" />}
</button>
</div>
<div className="mt-2.5 p-2.5 rounded-xl bg-purple-950/40 border border-purple-500/20 text-[11px] text-purple-300/90 leading-relaxed">
<span className="text-fuchsia-400 font-bold">💡 Important Space Tip:</span> Static Spaces (<code className="text-white">sdk: static</code>) serve pure web files directly. Make sure <code className="text-fuchsia-300">app_file: index.html</code> is used. If set to <code className="text-red-300">app_file: app.py</code>, Hugging Face displays the raw Python text instead of executing your website!
</div>
</div>
</div>
<div className="flex gap-3 items-start bg-[#120826] p-4 rounded-2xl border border-purple-500/25">
<span className="w-6 h-6 rounded-full bg-purple-500/20 text-fuchsia-400 font-bold font-mono flex items-center justify-center shrink-0 border border-purple-500/40">
3
</span>
<div className="flex-1">
<h4 className="font-bold text-white mb-1">Download & Push Project ZIP</h4>
<p className="text-purple-300/80 mb-2">
Download the ZIP package containing your project files along with the pre-configured <code>README.md</code>, then drag-and-drop or <code>git push</code> it to your new Hugging Face Space.
</p>
<button
onClick={handleDownloadBundle}
disabled={isExporting}
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-xl bg-gradient-to-r from-purple-600 via-fuchsia-600 to-pink-500 hover:from-purple-500 hover:to-pink-500 text-white font-bold text-xs uppercase tracking-wider transition-all shadow-[0_0_20px_rgba(168,85,247,0.4)] cursor-pointer active:scale-95"
>
<Download className="w-4 h-4" />
<span>{isExporting ? 'Generating ZIP...' : 'Download Space Package ZIP'}</span>
</button>
</div>
</div>
</div>
</div>
{/* Footer */}
<div className="px-6 py-4 bg-[#0a0517] border-t border-purple-500/25 flex justify-end">
<button
onClick={onClose}
className="px-5 py-2 rounded-xl bg-[#1b0c38] hover:bg-[#281254] text-xs font-semibold text-purple-200 hover:text-white transition-colors cursor-pointer border border-purple-500/30"
>
Got It
</button>
</div>
</div>
</div>
);
};