forked from Archives/Athou_commafeed
monaco mobile support is poor, fallback to textarea
This commit is contained in:
36
commafeed-client/src/components/code/CodeEditor.tsx
Normal file
36
commafeed-client/src/components/code/CodeEditor.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Input, Textarea } from "@mantine/core"
|
||||||
|
import RichCodeEditor from "components/code/RichCodeEditor"
|
||||||
|
import { useMobile } from "hooks/useMobile"
|
||||||
|
import { ReactNode } from "react"
|
||||||
|
|
||||||
|
interface CodeEditorProps {
|
||||||
|
description?: ReactNode
|
||||||
|
language: "css" | "javascript"
|
||||||
|
value: string
|
||||||
|
onChange: (value: string | undefined) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CodeEditor(props: CodeEditorProps) {
|
||||||
|
const mobile = useMobile()
|
||||||
|
|
||||||
|
return mobile ? (
|
||||||
|
// monaco mobile support is poor, fallback to textarea
|
||||||
|
<Textarea
|
||||||
|
autosize
|
||||||
|
minRows={4}
|
||||||
|
maxRows={15}
|
||||||
|
description={props.description}
|
||||||
|
styles={{
|
||||||
|
input: {
|
||||||
|
fontFamily: "monospace",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
value={props.value}
|
||||||
|
onChange={e => props.onChange(e.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Input.Wrapper description={props.description}>
|
||||||
|
<RichCodeEditor height="30vh" language={props.language} value={props.value} onChange={props.onChange} />
|
||||||
|
</Input.Wrapper>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Trans } from "@lingui/macro"
|
import { Trans } from "@lingui/macro"
|
||||||
import { Box, Button, Group, Input, Stack } from "@mantine/core"
|
import { Box, Button, Group, Stack } from "@mantine/core"
|
||||||
import { useForm } from "@mantine/form"
|
import { useForm } from "@mantine/form"
|
||||||
import { client, errorToStrings } from "app/client"
|
import { client, errorToStrings } from "app/client"
|
||||||
import { redirectToSelectedSource } from "app/slices/redirect"
|
import { redirectToSelectedSource } from "app/slices/redirect"
|
||||||
import { useAppDispatch, useAppSelector } from "app/store"
|
import { useAppDispatch, useAppSelector } from "app/store"
|
||||||
import { Alert } from "components/Alert"
|
import { Alert } from "components/Alert"
|
||||||
import RichCodeEditor from "components/RichCodeEditor"
|
import { CodeEditor } from "components/code/CodeEditor"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
import { useAsyncCallback } from "react-async-hook"
|
import { useAsyncCallback } from "react-async-hook"
|
||||||
import { TbDeviceFloppy } from "react-icons/tb"
|
import { TbDeviceFloppy } from "react-icons/tb"
|
||||||
@@ -56,13 +56,17 @@ export function CustomCodeSettings() {
|
|||||||
|
|
||||||
<form onSubmit={form.onSubmit(saveCustomCode.execute)}>
|
<form onSubmit={form.onSubmit(saveCustomCode.execute)}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Input.Wrapper description={<Trans>Custom CSS rules that will be applied</Trans>}>
|
<CodeEditor
|
||||||
<RichCodeEditor height="30vh" language="css" {...form.getInputProps("customCss")} />
|
description={<Trans>Custom CSS rules that will be applied</Trans>}
|
||||||
</Input.Wrapper>
|
language="css"
|
||||||
|
{...form.getInputProps("customCss")}
|
||||||
|
/>
|
||||||
|
|
||||||
<Input.Wrapper description={<Trans>Custom JS code that will be executed on page load</Trans>}>
|
<CodeEditor
|
||||||
<RichCodeEditor height="30vh" language="javascript" {...form.getInputProps("customJs")} />
|
description={<Trans>Custom JS code that will be executed on page load</Trans>}
|
||||||
</Input.Wrapper>
|
language="javascript"
|
||||||
|
{...form.getInputProps("customJs")}
|
||||||
|
/>
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<Button variant="default" onClick={() => dispatch(redirectToSelectedSource())}>
|
<Button variant="default" onClick={() => dispatch(redirectToSelectedSource())}>
|
||||||
|
|||||||
Reference in New Issue
Block a user