Skip to content

Commit

Permalink
feat: ✨ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrnoch committed Apr 6, 2024
1 parent 3470018 commit 8a818f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/screens/Dashboard/pages/Other/Templates/ManageTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TemplateRenderer from "@/shared/components/PdfRenderer";
import { Hr } from "@/shared/components/Menu/Hr";
import { createEffect, createSignal, on, onMount, type Component } from "solid-js";
import { Accessor, createEffect, createSignal, on, onMount, type Component } from "solid-js";
import PageHeader from "@/screens/Dashboard/components/PageHeader";
import { useI18n } from "@/i18n";
import { useParams } from "@solidjs/router";
import HeaderButton from "@/screens/Dashboard/components/PageHeader/HeaderButton";
import { createCodeMirror } from "solid-codemirror";
import { createCodeMirror, createEditorControlledValue } from "solid-codemirror";
import { highlightActiveLineGutter, lineNumbers } from "@codemirror/view";
import type { Extension } from "@codemirror/state";
import { liquid } from "@codemirror/lang-liquid";
Expand Down Expand Up @@ -69,7 +69,7 @@ const ManageTemplate: Component = () => {
]}
/>

<Editor defaultValue={templateCode()} onValueChange={(value) => setTemplateCode(value)} />
<Editor code={templateCode} onValueChange={(value) => setTemplateCode(value)} />

<Popover show={showRender()} onClose={() => setShowRender(false)} title="cus">
<div class="w-full lg:w-1/2 bg-red rounded-xl gap-4 flex flex-col p-4">
Expand All @@ -84,16 +84,16 @@ const ManageTemplate: Component = () => {

export default ManageTemplate;

const Editor: Component<{ onValueChange: (value: string) => void; defaultValue: string }> = (props) => {
const Editor: Component<{ onValueChange: (value: string) => void; code: Accessor<string> }> = (props) => {
const {
// editorView,
editorView,
ref: editorRef,
createExtension,
} = createCodeMirror({
/**
* The initial value of the editor
*/
value: props.defaultValue,
value: props.code(),
/**
* Fired whenever the editor code value changes.
*/
Expand All @@ -106,6 +106,8 @@ const Editor: Component<{ onValueChange: (value: string) => void; defaultValue:
return [lineNumbers(), highlightActiveLineGutter(), liquid(), material];
};

createEditorControlledValue(editorView, props.code);

createEffect(on(extensions, (extensions) => reconfigure(extensions)));

const reconfigure = createExtension(extensions());
Expand Down
3 changes: 2 additions & 1 deletion src/screens/Dashboard/pages/Other/Templates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const Templates: Component = () => {

const columns = [
{ field: "id", header: "ID" },
{ field: "type", header: "Type" },
{ field: "name", header: "Name" },
{ field: "templateType", header: "Type" },
];

const handleEdit = (item: Template) => {
Expand Down

0 comments on commit 8a818f0

Please sign in to comment.