add rich editor for custom code

This commit is contained in:
Athou
2023-06-22 14:37:56 +02:00
parent aeaaeaee0e
commit f7786d9962
3 changed files with 60 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import { Trans } from "@lingui/macro"
import { Box, Button, Group, Stack, Textarea } from "@mantine/core"
import { Box, Button, Group, Input, Stack, useMantineTheme } from "@mantine/core"
import { useForm } from "@mantine/form"
import { Editor } from "@monaco-editor/react"
import { client, errorToStrings } from "app/client"
import { redirectToSelectedSource } from "app/slices/redirect"
import { useAppDispatch, useAppSelector } from "app/store"
@@ -16,8 +17,11 @@ interface FormData {
export function CustomCodeSettings() {
const settings = useAppSelector(state => state.user.settings)
const theme = useMantineTheme()
const dispatch = useAppDispatch()
const editorTheme = theme.colorScheme === "dark" ? "vs-dark" : "light"
const form = useForm<FormData>()
const { setValues } = form
@@ -55,31 +59,25 @@ export function CustomCodeSettings() {
<form onSubmit={form.onSubmit(saveCustomCode.execute)}>
<Stack>
<Textarea
autosize
minRows={4}
maxRows={15}
{...form.getInputProps("customCss")}
description={<Trans>Custom CSS rules that will be applied</Trans>}
styles={{
input: {
fontFamily: "monospace",
},
}}
/>
<Input.Wrapper description={<Trans>Custom CSS rules that will be applied</Trans>}>
<Editor
height="30vh"
defaultLanguage="css"
theme={editorTheme}
options={{ minimap: { enabled: false } }}
{...form.getInputProps("customCss")}
/>
</Input.Wrapper>
<Textarea
autosize
minRows={4}
maxRows={15}
{...form.getInputProps("customJs")}
description={<Trans>Custom JS code that will be executed on page load</Trans>}
styles={{
input: {
fontFamily: "monospace",
},
}}
/>
<Input.Wrapper description={<Trans>Custom JS code that will be executed on page load</Trans>}>
<Editor
height="30vh"
defaultLanguage="javascript"
theme={editorTheme}
options={{ minimap: { enabled: false } }}
{...form.getInputProps("customJs")}
/>
</Input.Wrapper>
<Group>
<Button variant="default" onClick={() => dispatch(redirectToSelectedSource())}>