File size: 10,181 Bytes
ffe328b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a09e386
ffe328b
 
 
a09e386
 
ffe328b
a09e386
 
ffe328b
 
7155832
 
 
ffe328b
 
a09e386
7155832
 
 
 
 
a09e386
7155832
 
a09e386
 
 
 
 
 
 
7155832
a09e386
7155832
a09e386
 
 
 
 
 
 
 
 
ffe328b
a09e386
ffe328b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a09e386
 
 
 
 
 
 
 
 
7155832
a09e386
 
 
 
 
 
 
 
 
7155832
a09e386
 
 
 
 
 
 
 
 
7155832
a09e386
 
ffe328b
a09e386
ffe328b
 
 
 
 
 
 
 
7155832
 
 
ffe328b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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>
  );
};