x
This commit is contained in:
1 parent
512a988d17
commit
7f384182ae
3 files changed
-82
No files matched your search
@@ -14,7 +14,6 @@ export default function ArticleEditPage() {
|
|||||||
|
|
||||||
const [loading, setLoading] = useState(!isNew)
|
const [loading, setLoading] = useState(!isNew)
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [uploading, setUploading] = useState(false)
|
|
||||||
|
|
||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
const [slug, setSlug] = useState('')
|
const [slug, setSlug] = useState('')
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export default function PageBuilderPage() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [editingSection, setEditingSection] = useState<Partial<PageSection> | null>(null);
|
const [editingSection, setEditingSection] = useState<Partial<PageSection> | null>(null);
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
|
||||||
const [uploadTarget, setUploadTarget] = useState<{ type: 'main' | 'slide'; index?: number } | null>(null);
|
const [uploadTarget, setUploadTarget] = useState<{ type: 'main' | 'slide'; index?: number } | null>(null);
|
||||||
const [saveStatus, setSaveStatus] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle');
|
const [saveStatus, setSaveStatus] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle');
|
||||||
|
|
||||||
@@ -402,56 +401,6 @@ export default function PageBuilderPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpload = async (file: File) => {
|
|
||||||
setIsUploading(true);
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', file);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_BASE}/upload`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData
|
|
||||||
});
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.url) {
|
|
||||||
if (uploadTarget?.type === 'slide' && typeof uploadTarget.index === 'number') {
|
|
||||||
const idx = uploadTarget.index;
|
|
||||||
setEditingSection(prev => {
|
|
||||||
if (!prev) return null;
|
|
||||||
const currentSlides = [...(prev.payload?.slides || [])];
|
|
||||||
currentSlides[idx] = {
|
|
||||||
...currentSlides[idx],
|
|
||||||
imageUrl: data.url
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
payload: {
|
|
||||||
...(prev.payload || {}),
|
|
||||||
slides: currentSlides
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setEditingSection(prev => {
|
|
||||||
if (!prev) return null;
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
payload: {
|
|
||||||
...(prev.payload || {}),
|
|
||||||
imageUrl: data.url
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Upload error:', err);
|
|
||||||
} finally {
|
|
||||||
setIsUploading(false);
|
|
||||||
setUploadTarget(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const openAddModal = () => {
|
const openAddModal = () => {
|
||||||
setEditingSection({
|
setEditingSection({
|
||||||
type: 'HERO',
|
type: 'HERO',
|
||||||
@@ -2021,7 +1970,6 @@ export default function PageBuilderPage() {
|
|||||||
<div className="p-6 bg-night-950/50 border-t border-white/5 flex flex-col sm:flex-row gap-4 shrink-0">
|
<div className="p-6 bg-night-950/50 border-t border-white/5 flex flex-col sm:flex-row gap-4 shrink-0">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isUploading}
|
|
||||||
className="flex-1 px-8 py-3 bg-cyan-glow text-night-900 hover:bg-cyan-glow/80 disabled:opacity-50 font-bold rounded-xl transition-all"
|
className="flex-1 px-8 py-3 bg-cyan-glow text-night-900 hover:bg-cyan-glow/80 disabled:opacity-50 font-bold rounded-xl transition-all"
|
||||||
>
|
>
|
||||||
{editingSection.id ? 'Save Block Settings' : 'Create Block'}
|
{editingSection.id ? 'Save Block Settings' : 'Create Block'}
|
||||||
|
|||||||
@@ -161,10 +161,6 @@ export default function ProductEditPage() {
|
|||||||
setVariants(updated)
|
setVariants(updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAddImage = () => {
|
|
||||||
setImages([...images, { url: '', order: images.length }])
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleRemoveImage = (index: number) => {
|
const handleRemoveImage = (index: number) => {
|
||||||
setImages(images.filter((_, i) => i !== index))
|
setImages(images.filter((_, i) => i !== index))
|
||||||
}
|
}
|
||||||
@@ -175,31 +171,6 @@ export default function ProductEditPage() {
|
|||||||
setImages(updated)
|
setImages(updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = e.target.files?.[0]
|
|
||||||
if (!file) return
|
|
||||||
|
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('file', file)
|
|
||||||
|
|
||||||
try {
|
|
||||||
setSaving(true)
|
|
||||||
const res = await fetch(`${API_BASE}/upload`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Upload failed')
|
|
||||||
|
|
||||||
const data = await res.json()
|
|
||||||
// Add the new uploaded image to the list
|
|
||||||
setImages([...images, { url: data.url, order: images.length }])
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.message)
|
|
||||||
} finally {
|
|
||||||
setSaving(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSave = async (e: React.FormEvent) => {
|
const handleSave = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
|
|||||||
Reference in new issue
Block a user