diff --git a/app/components/editor/hooks/useIndex.tsx b/app/components/editor/hooks/useIndex.tsx index a49aff5..586260b 100644 --- a/app/components/editor/hooks/useIndex.tsx +++ b/app/components/editor/hooks/useIndex.tsx @@ -44,7 +44,7 @@ export default function useIndex() { const hash = window.location.hash.slice(1); if (hash && hash !== loadState.current.loadedHash) { loadState.current.loadedHash = hash; - setEcho(
Loading Shared Content...
); + setEcho(
Loading Shared Content...
); fetch(`https://dpaste.com/${hash}.txt`) .then((resp) => { return resp.ok ? resp.text() : Promise.reject(`HTTP error: ${resp.status}`); @@ -54,10 +54,10 @@ export default function useIndex() { loadState.current.content = parsed; const newModelKind = parsed?.modelKind && parsed.modelKind in example ? (parsed.modelKind as ModelKind) : 'basic'; setModelKind(newModelKind); - setEcho(
Shared Content Loaded.
); + setEcho(
Shared Content Loaded.
); }) .catch((error) => { - return setEcho(
Failed to load: {error}
); + return setEcho(
Failed to load: {error}
); }); } }, []); @@ -79,7 +79,7 @@ export default function useIndex() { } else { const currentPath = window.location.origin + window.location.pathname; setShare(v as string); - setEcho(
{`Shared at ${currentPath}#${v}`}
); + setEcho(
{`Shared at ${currentPath}#${v}`}
); } } diff --git a/app/components/editor/hooks/useRunTest.tsx b/app/components/editor/hooks/useRunTest.tsx index 60e2542..1a9bab3 100755 --- a/app/components/editor/hooks/useRunTest.tsx +++ b/app/components/editor/hooks/useRunTest.tsx @@ -181,11 +181,11 @@ async function enforcer(props: RunTestProps) { setError(null); - props.onResponse(
{'Done in ' + (stopTime - startTime).toFixed(2) + 'ms'}
); + props.onResponse(
{'Done in ' + (stopTime - startTime).toFixed(2) + 'ms'}
); props.onResponse(result); } catch (e) { const errorMessage = (e as any).message; - props.onResponse(
{errorMessage}
); + props.onResponse(
{errorMessage}
); props.onResponse([]); setError(errorMessage); } diff --git a/app/components/editor/hooks/useShareInfo.tsx b/app/components/editor/hooks/useShareInfo.tsx index d2aa692..6f782e5 100644 --- a/app/components/editor/hooks/useShareInfo.tsx +++ b/app/components/editor/hooks/useShareInfo.tsx @@ -42,7 +42,7 @@ export default function useShareInfo() { function shareInfo(props: ShareProps) { if (sharing) return; setSharing(true); - props.onResponse(
Sharing...
); + props.onResponse(
Sharing...
); // Create an object that contains only non-null values const shareContent: ShareFormat = { @@ -58,7 +58,7 @@ export default function useShareInfo() { // Check if there are any non-null values to share if (Object.keys(shareContent).length === 0) { setSharing(false); - props.onResponse(
No content to share
); + props.onResponse(
No content to share
); return; } @@ -70,7 +70,7 @@ export default function useShareInfo() { }) .catch((error) => { setSharing(false); - props.onResponse(
Error sharing content: {error.message}
); + props.onResponse(
Error sharing content: {error.message}
); }); } diff --git a/app/components/editor/index.tsx b/app/components/editor/index.tsx index c82405c..cdc3064 100755 --- a/app/components/editor/index.tsx +++ b/app/components/editor/index.tsx @@ -11,7 +11,6 @@ import { go } from '@codemirror/legacy-modes/mode/go'; import { EditorView } from '@codemirror/view'; import { CasbinConfSupport } from '@/app/components/editor/casbin-mode/casbin-conf'; import { CasbinPolicySupport } from '@/app/components/editor/casbin-mode/casbin-csv'; -import { Config } from 'casbin'; import { javascriptLanguage } from '@codemirror/lang-javascript'; import useRunTest from '@/app/components/editor/hooks/useRunTest'; import useShareInfo from '@/app/components/editor/hooks/useShareInfo'; @@ -25,6 +24,7 @@ import { useLang } from '@/app/context/LangContext'; import LanguageMenu from '@/app/components/LanguageMenu'; import { linter, lintGutter } from '@codemirror/lint'; import { casbinLinter } from '@/app/utils/casbinLinter'; +import { toast, Toaster } from 'react-hot-toast'; export const EditorScreen = () => { const { @@ -54,6 +54,7 @@ export const EditorScreen = () => { return message; }; const { t, lang, theme, toggleTheme } = useLang(); + const [isContentLoaded, setIsContentLoaded] = useState(false); useEffect(() => { const fetchCasbinVersion = async () => { @@ -65,7 +66,8 @@ export const EditorScreen = () => { }, []); useEffect(() => { - if (modelKind) { + if (modelKind && modelText) { + setIsContentLoaded(true); enforcer({ modelKind, model: modelText, @@ -94,6 +96,7 @@ export const EditorScreen = () => { return (
+
{
-