This commit is contained in:
Jan Prochazka 2020-12-31 18:19:53 +01:00
parent 4cc1da3319
commit fbd254bafc
3 changed files with 15 additions and 8 deletions

View File

@ -11,14 +11,14 @@ export default function useStorage(key, storageObject, initialValue) {
return item ? JSON.parse(item) : initialValue; return item ? JSON.parse(item) : initialValue;
} catch (error) { } catch (error) {
// If error also return initialValue // If error also return initialValue
console.log(error); console.error(error);
return initialValue; return initialValue;
} }
}); });
// Return a wrapped version of useState's setter function that ... // Return a wrapped version of useState's setter function that ...
// ... persists the new value to localStorage. // ... persists the new value to localStorage.
const setValue = value => { const setValue = (value) => {
try { try {
// Allow value to be a function so we have same API as useState // Allow value to be a function so we have same API as useState
const valueToStore = value instanceof Function ? value(storedValue) : value; const valueToStore = value instanceof Function ? value(storedValue) : value;
@ -28,7 +28,8 @@ export default function useStorage(key, storageObject, initialValue) {
storageObject.setItem(key, JSON.stringify(valueToStore)); storageObject.setItem(key, JSON.stringify(valueToStore));
} catch (error) { } catch (error) {
// A more advanced implementation would handle the error case // A more advanced implementation would handle the error case
console.log(error); console.error(error);
console.log('Error saving storage value', key, value);
} }
}; };

View File

@ -80,6 +80,12 @@ export function TabControl({ children, activePageIndex = undefined, activePageLa
} }
}, [activePageLabel]); }, [activePageLabel]);
React.useEffect(() => {
if (childrenArray.length > 0 && (value < 0 || value >= childrenArray.length)) {
setValue(0);
}
});
const theme = useTheme(); const theme = useTheme();
// // cleanup closed tabs // // cleanup closed tabs

View File

@ -142,11 +142,11 @@ export default function ToolBar({ toolbarPortalRef }) {
))} ))}
<ToolbarDropDownButton icon="icon add" text="New"> <ToolbarDropDownButton icon="icon add" text="New">
{config.runAsPortal == false && <DropDownMenuItem onClick={modalState.open}>Connection</DropDownMenuItem>} {config.runAsPortal == false && <DropDownMenuItem onClick={modalState.open}>Connection</DropDownMenuItem>}
<DropDownMenuItem onClick={newQuery}>SQL query</DropDownMenuItem> <DropDownMenuItem onClick={() => newQuery()}>SQL query</DropDownMenuItem>
{!!currentDatabase && <DropDownMenuItem onClick={newQueryDesign}>Query designer</DropDownMenuItem>} {!!currentDatabase && <DropDownMenuItem onClick={() => newQueryDesign()}>Query designer</DropDownMenuItem>}
<DropDownMenuItem onClick={newFreeTable}>Free table editor</DropDownMenuItem> <DropDownMenuItem onClick={() => newFreeTable()}>Free table editor</DropDownMenuItem>
<DropDownMenuItem onClick={newMarkdown}>Markdown page</DropDownMenuItem> <DropDownMenuItem onClick={() => newMarkdown()}>Markdown page</DropDownMenuItem>
<DropDownMenuItem onClick={newShell}>JavaScript shell script</DropDownMenuItem> <DropDownMenuItem onClick={() => newShell()}>JavaScript shell script</DropDownMenuItem>
</ToolbarDropDownButton> </ToolbarDropDownButton>
<ToolbarButton onClick={showImport} icon="icon import"> <ToolbarButton onClick={showImport} icon="icon import">