optimalization

This commit is contained in:
Jan Prochazka 2021-01-18 17:34:20 +01:00
parent cc049368e3
commit 22d37bda5d
2 changed files with 9 additions and 1 deletions

View File

@ -95,11 +95,15 @@ export { OpenedTabsProvider, useOpenedTabs, useSetOpenedTabs };
export function useUpdateDatabaseForTab(tabVisible, conid, database) {
const connection = useConnectionInfo({ conid });
const setDb = useSetCurrentDatabase();
const currentDb = useCurrentDatabase();
const previousTabVisible = usePrevious(!!(tabVisible && connection));
if (!conid || !database) return;
if (!previousTabVisible && tabVisible && connection) {
if (currentDb && currentDb.connection && currentDb.connection._id == conid && currentDb.name == database) {
return;
}
setDb({
name: database,
connection,

View File

@ -6,7 +6,7 @@ import FavoritesWidget from './FavoritesWidget';
import FilesWidget from './FilesWidget';
import PluginsWidget from './PluginsWidget';
export default function WidgetContainer() {
function WidgetContainerCore() {
const currentWidget = useCurrentWidget();
if (currentWidget === 'database') return <DatabaseWidget />;
if (currentWidget === 'file') return <FilesWidget />;
@ -15,3 +15,7 @@ export default function WidgetContainer() {
if (currentWidget === 'favorites') return <FavoritesWidget />;
return null;
}
const WidgetContainer = React.memo(WidgetContainerCore);
export default WidgetContainer;