import CodeEditor from '../components/CodeEditor'; import { useEffect, useState } from 'react'; import ColorPicker from 'react-best-gradient-color-picker'; import Accordion from '../components/Accordian'; import Switch from '../components/Switch'; import { sendThemeUpdate } from '../hooks/ThemeManagment'; import { PlusIcon, XMarkIcon } from '@heroicons/react/24/outline'; import localforage from 'localforage'; import { v4 as uuidv4 } from 'uuid'; import { CustomTheme } from '../types/CustomThemes'; function ThemeCreator({ themeID }: { themeID?: string }) { const [theme, setTheme] = useState({ id: uuidv4(), name: '', description: '', defaultColour: '', CanChangeColour: true, CustomCSS: '', CustomImages: [] }); useEffect(() => { if (themeID) { localforage.getItem(themeID).then((theme) => { if (theme) { setTheme(theme as CustomTheme); } }); } }); const generateImageId = () => { return '_' + Math.random().toString(36).substr(2, 9); }; const handleImageUpload = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = async () => { const imageBlob = await fetch(reader.result as string).then(res => res.blob()); const imageId = generateImageId(); const variableName = `custom-image-${theme.CustomImages.length}`; const updatedTheme = { ...theme, CustomImages: [...theme.CustomImages, { id: imageId, blob: imageBlob, variableName }], }; setTheme(updatedTheme); sendThemeUpdate(updatedTheme, false, true); }; reader.readAsDataURL(file); } }; const handleRemoveImage = (imageId: string) => { const updatedTheme = { ...theme, CustomImages: theme.CustomImages.filter((image) => image.id !== imageId), }; setTheme(updatedTheme); }; const handleImageVariableChange = (imageId: string, variableName: string) => { const updatedTheme = { ...theme, CustomImages: theme.CustomImages.map((image) => image.id === imageId ? { ...image, variableName } : image ), }; setTheme(updatedTheme); }; function CodeUpdate(value: string) { setTheme((prevTheme) => ({ ...prevTheme, CustomCSS: value, })); } const saveTheme = async () => { sendThemeUpdate(theme, true) }; useEffect(() => { sendThemeUpdate(theme); }, [theme]); return (

Theme Creator

Theme Name
setTheme({ ...theme, name: e.target.value })} className='w-full p-2 mb-4 transition-all duration-300 rounded-lg focus:outline-none ring-0 focus:ring-1 ring-zinc-100 dark:ring-zinc-700 dark:bg-zinc-900 dark:text-white' />
Description (optional)