diff --git a/app/components/ModelEditor.tsx b/app/components/ModelEditor.tsx index b319511..88f92c7 100644 --- a/app/components/ModelEditor.tsx +++ b/app/components/ModelEditor.tsx @@ -12,7 +12,13 @@ import { newModel } from 'casbin'; import { setError } from '@/app/utils/errorManager'; export const ModelEditor = ({ initialValue = '' }: { initialValue: string }) => { - const [modelText, setModelText] = useState(initialValue); + const [modelText, setModelText] = useState(''); + + useEffect(() => { + if (initialValue) { + setModelText(initialValue); + } + }, [initialValue]); const validateModel = useCallback(async (text: string) => { try { @@ -74,4 +80,4 @@ export const ModelEditor = ({ initialValue = '' }: { initialValue: string }) => ); -}; \ No newline at end of file +}; diff --git a/app/model-editor/layout.tsx b/app/model-editor/layout.tsx new file mode 100644 index 0000000..90954f9 --- /dev/null +++ b/app/model-editor/layout.tsx @@ -0,0 +1,9 @@ +import React from 'react'; + +export default function ModelEditorLayout({ + children, +}: { + children: React.ReactNode +}) { + return <>{children}>; +} diff --git a/app/model-editor/page.tsx b/app/model-editor/page.tsx index 440f316..cd562d5 100644 --- a/app/model-editor/page.tsx +++ b/app/model-editor/page.tsx @@ -1,16 +1,22 @@ 'use client'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { ModelEditor } from '../components/ModelEditor'; -const ModelEditorPage = ({ searchParams }: { searchParams: { model?: string } }) => { - const initialValue = searchParams.model ? decodeURIComponent(searchParams.model) : ''; +export default function ModelEditorPage() { + const [initialValue, setInitialValue] = useState(''); + + useEffect(() => { + const params = new URLSearchParams(window.location.search); + const modelParam = params.get('model'); + if (modelParam) { + setInitialValue(decodeURIComponent(modelParam)); + } + }, []); return (