From d82c7ac9a7a88ba4fb4867bbc8a65ae1557b5722 Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Mon, 17 Jun 2024 00:42:03 +0530 Subject: [PATCH] Fix initial state bug. --- src/webview/frontend/App.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/webview/frontend/App.tsx b/src/webview/frontend/App.tsx index 6ee7d9b..f7af79c 100644 --- a/src/webview/frontend/App.tsx +++ b/src/webview/frontend/App.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useReducer } from 'react'; +import React, { useState, useEffect } from 'react'; import { createRoot } from 'react-dom/client'; import { Problem, @@ -40,10 +40,12 @@ function Judge(props: { const [webviewState, setWebviewState] = useState( () => { const vscodeState = vscodeApi.getState(); - console.log('Restored state:', vscodeState); - return { + const ret = { dialogCloseDate: vscodeState?.dialogCloseDate || Date.now(), }; + vscodeApi.setState(ret); + console.log('Restored to state:', ret); + return ret; }, ); @@ -595,7 +597,6 @@ function App() { const [deferSaveTimer, setDeferSaveTimer] = useState(null); const [, setSaving] = useState(false); const [showFallback, setShowFallback] = useState(false); - const [, forceUpdate] = useReducer((x) => x + 1, 0); // Save the problem const save = () => {