From e6ab88a839a273d914846ed71775aa350f887250 Mon Sep 17 00:00:00 2001 From: Coki <92775570+HashCookie@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:27:10 +0800 Subject: [PATCH] feat: update share functionality to include comparison engines state (#215) --- app/components/editor/hooks/useIndex.tsx | 6 ++++++ app/components/editor/hooks/useShareInfo.tsx | 1 + app/components/editor/index.tsx | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/components/editor/hooks/useIndex.tsx b/app/components/editor/hooks/useIndex.tsx index facddcb..11ff561 100644 --- a/app/components/editor/hooks/useIndex.tsx +++ b/app/components/editor/hooks/useIndex.tsx @@ -14,6 +14,7 @@ export default function useIndex() { const [share, setShare] = useState(''); const [enforceContextData, setEnforceContextData] = useState(new Map(defaultEnforceContextData)); const [selectedEngine, setSelectedEngine] = useState('node'); + const [comparisonEngines, setComparisonEngines] = useState([]); const loadState = useRef<{ loadedHash?: string; }>({}); @@ -54,6 +55,9 @@ export default function useIndex() { if (shared?.selectedEngine) { setSelectedEngine(shared.selectedEngine); } + if (shared?.comparisonEngines) { + setComparisonEngines(shared.comparisonEngines); + } }; useEffect(() => { @@ -121,5 +125,7 @@ export default function useIndex() { handleShare, selectedEngine, setSelectedEngine, + comparisonEngines, + setComparisonEngines, }; } diff --git a/app/components/editor/hooks/useShareInfo.tsx b/app/components/editor/hooks/useShareInfo.tsx index 2750857..c6dd7c3 100644 --- a/app/components/editor/hooks/useShareInfo.tsx +++ b/app/components/editor/hooks/useShareInfo.tsx @@ -29,6 +29,7 @@ export interface ShareFormat { requestResult?: object; enforceContext?: string; selectedEngine?: string; + comparisonEngines?: string[]; } async function dpaste(content: string) { diff --git a/app/components/editor/index.tsx b/app/components/editor/index.tsx index ca5a3a2..8b48d36 100755 --- a/app/components/editor/index.tsx +++ b/app/components/editor/index.tsx @@ -52,6 +52,8 @@ export const EditorScreen = () => { handleShare, selectedEngine, setSelectedEngine, + comparisonEngines, + setComparisonEngines, } = useIndex(); const { enforcer } = useRunTest(); const { shareInfo } = useShareInfo(); @@ -61,7 +63,6 @@ export const EditorScreen = () => { const [showCustomConfig, setShowCustomConfig] = useState(false); const [isLoading, setIsLoading] = useState(false); const [requestResults, setRequestResults] = useState({}); - const [comparisonEngines, setComparisonEngines] = useState([]); const skipNextEffectRef = useRef(false); const sidePanelChatRef = useRef<{ openDrawer: (message: string) => void } | null>(null); const { setupEnforceContextData, setupHandleEnforceContextChange } = useSetupEnforceContext({ @@ -457,6 +458,7 @@ export const EditorScreen = () => { request, requestResult: Array.from(enforceContextData.entries()), selectedEngine, + comparisonEngines, }); }} >