import { createSignal, Show } from 'solid-js'; import { Textarea, Label, Subtitle, Tooltip, CodeEditor, Button, ProBadge } from '@components'; import { useSettings, useLicense, useModal } from '@util/context'; export default function Advanced() { const { settings, importSettings, resetSettings, exportSettings, state } = useSettings(); const { isLocked, shakePromo } = useLicense(); const { fire, toast } = useModal(); const [resetting, setResetting] = createSignal(false); const handleInput = (field) => (e) => { if (isLocked()) { shakePromo(); return; } settings[field] = e.target.value; }; const handleImportSettings = async (e) => { const file = e.target.files[0]; e.target.value = null; if (!file || file.type !== 'application/json') { return fire({ title: 'Invalid JSON File!', content: 'Please upload a valid JSON file exported from AjaxPress.' }); } const reader = new FileReader(); reader.onload = async (event) => { try { const result = JSON.parse(event.target.result); if (!result || result.type !== 'ajaxpress_settings') { return fire({ title: 'Invalid JSON File!', content: 'Please upload a valid JSON file exported from AjaxPress.' }); } const isConfirmed = await fire({ title: 'Sure to import?', content: 'This will replace your current settings.', ok: 'Yes, import', reverse: true, }); if (!isConfirmed) return; await importSettings(result); toast('Settings imported!'); } catch (error) { return fire({ title: 'Invalid JSON File!', content: 'Please upload a valid JSON file exported from AjaxPress.' }); } }; reader.readAsText(file); }; const handleResetSettings = async () => { const isConfirmed = await fire({ title: 'Are you sure?', content: 'Are you sure to clear all the changes you have made to default?', ok: "I'm sure", }); if (!isConfirmed) return; const reConfirmed = await fire({ title: 'Caution!', content: 'This can NOT be undone, please make sure that you have exported backup.', ok: 'Yes, Clear', }); if (!reConfirmed) return; setResetting('Resetting'); await resetSettings(); setResetting(false); fire({ title: 'Successfully cleared!', content: 'All the changes you have made is clear now.', ok: true }); }; return (
.ajaxpress-progressbar {"{"}
border-radius: 4px;
{"}"}