From 6446634851e5ef688bd8932e7298ce652f333a37 Mon Sep 17 00:00:00 2001 From: Coki <92775570+HashCookie@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:52:02 +0800 Subject: [PATCH] feat: Support mobile view better (#144) * refactor: improve layout and responsiveness in editor component * feat: add custom configuration toggle and improve layout responsiveness * refactor: remove commented-out code in EditorScreen component * docs: update title in metadata * style: adjust padding in editor component --- app/components/editor/index.tsx | 282 ++++++++++++++++++-------------- app/layout.tsx | 2 +- app/page.tsx | 11 +- 3 files changed, 165 insertions(+), 130 deletions(-) diff --git a/app/components/editor/index.tsx b/app/components/editor/index.tsx index b69f093..1c91ba4 100755 --- a/app/components/editor/index.tsx +++ b/app/components/editor/index.tsx @@ -40,6 +40,7 @@ export const EditorScreen = () => { data: enforceContextData, }); const [casbinVersion, setCasbinVersion] = useState(''); + const [showCustomConfig, setShowCustomConfig] = useState(false); const sidePanelChatRef = useRef<{ openDrawer: (message: string) => void } | null>(null); const openDrawerWithMessage = (message: string) => { if (sidePanelChatRef.current) { @@ -90,8 +91,15 @@ export const EditorScreen = () => { const textClass = clsx(theme === 'dark' ? 'text-gray-200' : 'text-gray-800'); return ( -
-
+
+
-
{open &&
{t('Custom config')}
}
+
+ {(showCustomConfig || open) &&
{t('Custom config')}
} +
- {open && ( + {(showCustomConfig || open) && (
{
-
-
+
+
{t('Model')}
@@ -181,7 +192,34 @@ export const EditorScreen = () => { > {t('RESET')} +
+ +
+
{ EditorView.lineWrapping, buttonPlugin(openDrawerWithMessage, extractContent, 'model'), ]} - className={'function flex-grow'} + className={'function flex-grow h-[300px]'} value={modelText} />
-
+
{t('Request')}
@@ -302,14 +340,14 @@ export const EditorScreen = () => { bracketMatching: true, indentOnInput: true, }} - className={'function flex-grow '} + className={'function flex-grow h-[300px]'} value={request} />
-
+
{t('Enforcement Result')}
@@ -337,76 +375,74 @@ export const EditorScreen = () => { bracketMatching: true, indentOnInput: true, }} - className={'cursor-not-allowed flex-grow'} + className={'cursor-not-allowed flex-grow h-[300px]'} value={requestResult} />
-
- - - {!share ? ( - +
+
+ + + {!share ? ( - - ) : ( - - )} -
- {echo} -
-
- - + > + {t('COPY')} + + )} +
+ +
+
{echo}
+ +
+ + +
diff --git a/app/layout.tsx b/app/layout.tsx index dc33995..033dd28 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -17,7 +17,7 @@ import './globals.css'; import { LangProvider } from './context/LangContext'; export const metadata: Metadata = { - title: 'casbin-editor', + title: 'Casbin Policy Editor', description: 'web playground for casbin', }; diff --git a/app/page.tsx b/app/page.tsx index 7941c03..2fa0249 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -20,16 +20,15 @@ import { useLang } from '@/app/context/LangContext'; export default function Home() { const { theme } = useLang(); return ( -
-
+
+
-
- +
+ GitHub stars -
- Copyright © {new Date().getFullYear()} Casbin contributors. + Copyright © {new Date().getFullYear()} Casbin contributors.
);