-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
154 lines (139 loc) · 6.08 KB
/
App.tsx
File metadata and controls
154 lines (139 loc) · 6.08 KB
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
import React, { useState, useEffect } from 'react';
import ConfigPanel from './components/ConfigPanel';
import Editor from './components/Editor';
import Preview from './components/Preview';
import { GithubConfig, GeneratedArticle, AppStatus, AlertMessage } from './types';
import { generateArticleFromText } from './services/geminiService';
import { uploadToGithub } from './services/githubService';
import { Layout, CheckCircle, AlertTriangle } from 'lucide-react';
const CONFIG_KEY = 'autoblog_gh_config';
const App: React.FC = () => {
const [config, setConfig] = useState<GithubConfig | null>(null);
const [status, setStatus] = useState<AppStatus>(AppStatus.IDLE);
const [article, setArticle] = useState<GeneratedArticle | null>(null);
const [alert, setAlert] = useState<AlertMessage | null>(null);
useEffect(() => {
const savedConfig = localStorage.getItem(CONFIG_KEY);
if (savedConfig) {
setConfig(JSON.parse(savedConfig));
}
}, []);
const handleSaveConfig = (newConfig: GithubConfig) => {
setConfig(newConfig);
localStorage.setItem(CONFIG_KEY, JSON.stringify(newConfig));
setAlert({ type: 'success', text: 'Konfigurace byla úspěšně uložena.' });
setTimeout(() => setAlert(null), 3000);
};
const handleGenerate = async (rawText: string) => {
// Note: Config is optional for generation, we only need it for upload.
setStatus(AppStatus.GENERATING);
setAlert(null);
try {
const generatedData = await generateArticleFromText(rawText);
setArticle(generatedData);
setStatus(AppStatus.REVIEW);
} catch (error) {
console.error(error);
setAlert({ type: 'error', text: 'Chyba při generování obsahu. Zkontrolujte API klíč.' });
setStatus(AppStatus.IDLE);
}
};
const handleUpload = async (fileName: string, content: string) => {
if (!config) {
setAlert({ type: 'error', text: 'GitHub není nastaven. Klikněte na ikonu nastavení vpravo nahoře.' });
return;
}
setStatus(AppStatus.UPLOADING);
try {
await uploadToGithub(config, fileName, content);
setStatus(AppStatus.SUCCESS);
setAlert({ type: 'success', text: 'Článek byl úspěšně nahrán na GitHub! Vercel by měl začít build.' });
} catch (error: any) {
console.error(error);
setAlert({ type: 'error', text: `Chyba při nahrávání: ${error.message}` });
setStatus(AppStatus.REVIEW); // Let user try again
}
};
const handleReset = () => {
setArticle(null);
setStatus(AppStatus.IDLE);
setAlert(null);
};
return (
<div className="min-h-screen bg-slate-100 flex flex-col font-sans">
{/* Header */}
<header className="bg-white border-b border-gray-200 sticky top-0 z-40">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="bg-indigo-600 p-2 rounded-lg">
<Layout className="w-5 h-5 text-white" />
</div>
<h1 className="text-xl font-bold text-gray-900 tracking-tight">AutoBlog Publisher</h1>
</div>
<div className="text-sm text-gray-500 hidden sm:block">
Gemini AI → GitHub → Vercel
</div>
</div>
</header>
{/* Main Content */}
<main className="flex-1 max-w-7xl w-full mx-auto px-4 sm:px-6 lg:px-8 py-8">
{/* Global Alerts */}
{alert && (
<div className={`mb-6 p-4 rounded-lg flex items-center gap-3 shadow-sm animate-fade-in ${
alert.type === 'success' ? 'bg-green-50 text-green-800 border border-green-200' :
alert.type === 'error' ? 'bg-red-50 text-red-800 border border-red-200' :
'bg-blue-50 text-blue-800 border border-blue-200'
}`}>
{alert.type === 'success' ? <CheckCircle className="w-5 h-5" /> : <AlertTriangle className="w-5 h-5" />}
<span className="font-medium">{alert.text}</span>
</div>
)}
{/* Success State */}
{status === AppStatus.SUCCESS ? (
<div className="max-w-md mx-auto mt-20 text-center">
<div className="w-20 h-20 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-6">
<CheckCircle className="w-10 h-10 text-green-600" />
</div>
<h2 className="text-2xl font-bold text-gray-900 mb-2">Publikováno!</h2>
<p className="text-gray-600 mb-8">Váš článek byl odeslán do repozitáře. Za chvíli bude živě na webu.</p>
<button
onClick={handleReset}
className="bg-indigo-600 text-white px-6 py-3 rounded-lg font-medium hover:bg-indigo-700 transition"
>
Vytvořit další článek
</button>
</div>
) : (
/* Editor Layout */
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 h-[calc(100vh-160px)] min-h-[600px]">
<div className="h-full">
<Editor
onGenerate={handleGenerate}
isGenerating={status === AppStatus.GENERATING}
/>
</div>
<div className="h-full">
{article ? (
<Preview
article={article}
onUpload={handleUpload}
isUploading={status === AppStatus.UPLOADING}
onReset={handleReset}
/>
) : (
<div className="h-full bg-white/50 border-2 border-dashed border-gray-300 rounded-xl flex flex-col items-center justify-center text-gray-400 p-8 text-center">
<Layout className="w-16 h-16 mb-4 opacity-20" />
<p className="text-lg font-medium">Zde se objeví náhled článku</p>
<p className="text-sm">Vygenerujte obsah vlevo pro zobrazení náhledu a editoru.</p>
</div>
)}
</div>
</div>
)}
</main>
{/* Settings Modal */}
<ConfigPanel onSave={handleSaveConfig} initialConfig={config} />
</div>
);
};
export default App;