mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Move full screen hotkey to floating to prevent tab rerenders
This commit is contained in:
parent
a86049f822
commit
876ae7f70f
@ -1,42 +1,21 @@
|
|||||||
import { MdPhotoLibrary } from 'react-icons/md';
|
import { MdPhotoLibrary } from 'react-icons/md';
|
||||||
import { RootState, useAppDispatch, useAppSelector } from 'app/store';
|
import { useAppDispatch, useAppSelector } from 'app/store';
|
||||||
import IAIIconButton from 'common/components/IAIIconButton';
|
import IAIIconButton from 'common/components/IAIIconButton';
|
||||||
import {
|
import { setShouldShowGallery } from 'features/gallery/store/gallerySlice';
|
||||||
GalleryState,
|
|
||||||
setShouldShowGallery,
|
|
||||||
} from 'features/gallery/store/gallerySlice';
|
|
||||||
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
import { activeTabNameSelector } from 'features/options/store/optionsSelectors';
|
import { floatingSelector } from './FloatingOptionsPanelButtons';
|
||||||
import _ from 'lodash';
|
import { setShouldShowOptionsPanel } from 'features/options/store/optionsSlice';
|
||||||
|
|
||||||
const floatingGallerySelcetor = createSelector(
|
|
||||||
[(state: RootState) => state.gallery, activeTabNameSelector],
|
|
||||||
(gallery: GalleryState, activeTabName) => {
|
|
||||||
const { shouldShowGallery, shouldHoldGalleryOpen, shouldPinGallery } =
|
|
||||||
gallery;
|
|
||||||
|
|
||||||
const shouldShowGalleryButton =
|
|
||||||
!(shouldShowGallery || (shouldHoldGalleryOpen && !shouldPinGallery)) &&
|
|
||||||
['txt2img', 'img2img', 'unifiedCanvas'].includes(activeTabName);
|
|
||||||
|
|
||||||
return {
|
|
||||||
shouldPinGallery,
|
|
||||||
shouldShowGalleryButton,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
memoizeOptions: {
|
|
||||||
resultEqualityCheck: _.isEqual,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const FloatingGalleryButton = () => {
|
const FloatingGalleryButton = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { shouldShowGalleryButton, shouldPinGallery } = useAppSelector(
|
const {
|
||||||
floatingGallerySelcetor
|
shouldShowGallery,
|
||||||
);
|
shouldShowGalleryButton,
|
||||||
|
shouldPinGallery,
|
||||||
|
shouldShowOptionsPanel,
|
||||||
|
shouldPinOptionsPanel,
|
||||||
|
} = useAppSelector(floatingSelector);
|
||||||
|
|
||||||
const handleShowGallery = () => {
|
const handleShowGallery = () => {
|
||||||
dispatch(setShouldShowGallery(true));
|
dispatch(setShouldShowGallery(true));
|
||||||
@ -45,6 +24,22 @@ const FloatingGalleryButton = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useHotkeys(
|
||||||
|
'f',
|
||||||
|
() => {
|
||||||
|
if (shouldShowGallery || shouldShowOptionsPanel) {
|
||||||
|
dispatch(setShouldShowOptionsPanel(false));
|
||||||
|
dispatch(setShouldShowGallery(false));
|
||||||
|
} else {
|
||||||
|
dispatch(setShouldShowOptionsPanel(true));
|
||||||
|
dispatch(setShouldShowGallery(true));
|
||||||
|
}
|
||||||
|
if (shouldPinGallery || shouldPinOptionsPanel)
|
||||||
|
setTimeout(() => dispatch(setDoesCanvasNeedScaling(true)), 400);
|
||||||
|
},
|
||||||
|
[shouldShowGallery, shouldShowOptionsPanel]
|
||||||
|
);
|
||||||
|
|
||||||
return shouldShowGalleryButton ? (
|
return shouldShowGalleryButton ? (
|
||||||
<IAIIconButton
|
<IAIIconButton
|
||||||
tooltip="Show Gallery (G)"
|
tooltip="Show Gallery (G)"
|
||||||
|
@ -11,27 +11,47 @@ import _ from 'lodash';
|
|||||||
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
||||||
import { FaSlidersH } from 'react-icons/fa';
|
import { FaSlidersH } from 'react-icons/fa';
|
||||||
import { activeTabNameSelector } from 'features/options/store/optionsSelectors';
|
import { activeTabNameSelector } from 'features/options/store/optionsSelectors';
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
import {
|
||||||
|
GalleryState,
|
||||||
|
setShouldShowGallery,
|
||||||
|
} from 'features/gallery/store/gallerySlice';
|
||||||
|
|
||||||
const floatingOptionsSelector = createSelector(
|
export const floatingSelector = createSelector(
|
||||||
[(state: RootState) => state.options, activeTabNameSelector],
|
[
|
||||||
(options: OptionsState, activeTabName) => {
|
(state: RootState) => state.options,
|
||||||
|
(state: RootState) => state.gallery,
|
||||||
|
activeTabNameSelector,
|
||||||
|
],
|
||||||
|
(options: OptionsState, gallery: GalleryState, activeTabName) => {
|
||||||
const {
|
const {
|
||||||
shouldPinOptionsPanel,
|
shouldPinOptionsPanel,
|
||||||
shouldShowOptionsPanel,
|
shouldShowOptionsPanel,
|
||||||
shouldHoldOptionsPanelOpen,
|
shouldHoldOptionsPanelOpen,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const { shouldShowGallery, shouldPinGallery, shouldHoldGalleryOpen } =
|
||||||
|
gallery;
|
||||||
|
|
||||||
const shouldShowOptionsPanelButton =
|
const shouldShowOptionsPanelButton =
|
||||||
!(
|
!(
|
||||||
shouldShowOptionsPanel ||
|
shouldShowOptionsPanel ||
|
||||||
(shouldHoldOptionsPanelOpen && !shouldPinOptionsPanel)
|
(shouldHoldOptionsPanelOpen && !shouldPinOptionsPanel)
|
||||||
) && ['txt2img', 'img2img', 'unifiedCanvas'].includes(activeTabName);
|
) && ['txt2img', 'img2img', 'unifiedCanvas'].includes(activeTabName);
|
||||||
|
|
||||||
|
const shouldShowGalleryButton =
|
||||||
|
!(shouldShowGallery || (shouldHoldGalleryOpen && !shouldPinGallery)) &&
|
||||||
|
['txt2img', 'img2img', 'unifiedCanvas'].includes(activeTabName);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
shouldPinOptionsPanel,
|
shouldPinOptionsPanel,
|
||||||
shouldShowProcessButtons:
|
shouldShowProcessButtons:
|
||||||
!shouldPinOptionsPanel || !shouldShowOptionsPanel,
|
!shouldPinOptionsPanel || !shouldShowOptionsPanel,
|
||||||
shouldShowOptionsPanelButton,
|
shouldShowOptionsPanelButton,
|
||||||
|
shouldShowOptionsPanel,
|
||||||
|
shouldShowGallery,
|
||||||
|
shouldPinGallery,
|
||||||
|
shouldShowGalleryButton,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ memoizeOptions: { resultEqualityCheck: _.isEqual } }
|
{ memoizeOptions: { resultEqualityCheck: _.isEqual } }
|
||||||
@ -40,10 +60,13 @@ const floatingOptionsSelector = createSelector(
|
|||||||
const FloatingOptionsPanelButtons = () => {
|
const FloatingOptionsPanelButtons = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const {
|
const {
|
||||||
|
shouldShowOptionsPanel,
|
||||||
shouldShowOptionsPanelButton,
|
shouldShowOptionsPanelButton,
|
||||||
shouldShowProcessButtons,
|
shouldShowProcessButtons,
|
||||||
shouldPinOptionsPanel,
|
shouldPinOptionsPanel,
|
||||||
} = useAppSelector(floatingOptionsSelector);
|
shouldShowGallery,
|
||||||
|
shouldPinGallery,
|
||||||
|
} = useAppSelector(floatingSelector);
|
||||||
|
|
||||||
const handleShowOptionsPanel = () => {
|
const handleShowOptionsPanel = () => {
|
||||||
dispatch(setShouldShowOptionsPanel(true));
|
dispatch(setShouldShowOptionsPanel(true));
|
||||||
@ -52,6 +75,22 @@ const FloatingOptionsPanelButtons = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useHotkeys(
|
||||||
|
'f',
|
||||||
|
() => {
|
||||||
|
if (shouldShowGallery || shouldShowOptionsPanel) {
|
||||||
|
dispatch(setShouldShowOptionsPanel(false));
|
||||||
|
dispatch(setShouldShowGallery(false));
|
||||||
|
} else {
|
||||||
|
dispatch(setShouldShowOptionsPanel(true));
|
||||||
|
dispatch(setShouldShowGallery(true));
|
||||||
|
}
|
||||||
|
if (shouldPinGallery || shouldPinOptionsPanel)
|
||||||
|
setTimeout(() => dispatch(setDoesCanvasNeedScaling(true)), 400);
|
||||||
|
},
|
||||||
|
[shouldShowGallery, shouldShowOptionsPanel]
|
||||||
|
);
|
||||||
|
|
||||||
return shouldShowOptionsPanelButton ? (
|
return shouldShowOptionsPanelButton ? (
|
||||||
<div className="show-hide-button-options">
|
<div className="show-hide-button-options">
|
||||||
<IAIIconButton
|
<IAIIconButton
|
||||||
|
@ -10,22 +10,15 @@ import NodesIcon from 'common/icons/NodesIcon';
|
|||||||
import PostprocessingIcon from 'common/icons/PostprocessingIcon';
|
import PostprocessingIcon from 'common/icons/PostprocessingIcon';
|
||||||
import TextToImageIcon from 'common/icons/TextToImageIcon';
|
import TextToImageIcon from 'common/icons/TextToImageIcon';
|
||||||
import {
|
import {
|
||||||
OptionsState,
|
|
||||||
setActiveTab,
|
setActiveTab,
|
||||||
setIsLightBoxOpen,
|
setIsLightBoxOpen,
|
||||||
setShouldShowOptionsPanel,
|
|
||||||
} from 'features/options/store/optionsSlice';
|
} from 'features/options/store/optionsSlice';
|
||||||
import ImageToImageWorkarea from './ImageToImage';
|
import ImageToImageWorkarea from './ImageToImage';
|
||||||
import TextToImageWorkarea from './TextToImage';
|
import TextToImageWorkarea from './TextToImage';
|
||||||
import Lightbox from 'features/lightbox/components/Lightbox';
|
import Lightbox from 'features/lightbox/components/Lightbox';
|
||||||
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
import { setDoesCanvasNeedScaling } from 'features/canvas/store/canvasSlice';
|
||||||
import UnifiedCanvasWorkarea from './UnifiedCanvas/UnifiedCanvasWorkarea';
|
import UnifiedCanvasWorkarea from './UnifiedCanvas/UnifiedCanvasWorkarea';
|
||||||
import {
|
|
||||||
GalleryState,
|
|
||||||
setShouldShowGallery,
|
|
||||||
} from 'features/gallery/store/gallerySlice';
|
|
||||||
import UnifiedCanvasIcon from 'common/icons/UnifiedCanvasIcon';
|
import UnifiedCanvasIcon from 'common/icons/UnifiedCanvasIcon';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
|
||||||
import TrainingWIP from 'common/components/WorkInProgress/Training';
|
import TrainingWIP from 'common/components/WorkInProgress/Training';
|
||||||
import TrainingIcon from 'common/icons/TrainingIcon';
|
import TrainingIcon from 'common/icons/TrainingIcon';
|
||||||
|
|
||||||
@ -69,26 +62,6 @@ export const tabMap = _.map(tabDict, (tab, key) => key);
|
|||||||
const tabMapTypes = [...tabMap] as const;
|
const tabMapTypes = [...tabMap] as const;
|
||||||
export type InvokeTabName = typeof tabMapTypes[number];
|
export type InvokeTabName = typeof tabMapTypes[number];
|
||||||
|
|
||||||
const fullScreenSelector = createSelector(
|
|
||||||
[(state: RootState) => state.gallery, (state: RootState) => state.options],
|
|
||||||
(gallery: GalleryState, options: OptionsState) => {
|
|
||||||
const { shouldShowGallery, shouldPinGallery } = gallery;
|
|
||||||
const { shouldShowOptionsPanel, shouldPinOptionsPanel } = options;
|
|
||||||
|
|
||||||
return {
|
|
||||||
shouldShowGallery,
|
|
||||||
shouldPinGallery,
|
|
||||||
shouldShowOptionsPanel,
|
|
||||||
shouldPinOptionsPanel,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
memoizeOptions: {
|
|
||||||
resultEqualityCheck: _.isEqual,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default function InvokeTabs() {
|
export default function InvokeTabs() {
|
||||||
const activeTab = useAppSelector(
|
const activeTab = useAppSelector(
|
||||||
(state: RootState) => state.options.activeTab
|
(state: RootState) => state.options.activeTab
|
||||||
@ -97,13 +70,6 @@ export default function InvokeTabs() {
|
|||||||
(state: RootState) => state.options.isLightBoxOpen
|
(state: RootState) => state.options.isLightBoxOpen
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
|
||||||
shouldPinGallery,
|
|
||||||
shouldShowGallery,
|
|
||||||
shouldPinOptionsPanel,
|
|
||||||
shouldShowOptionsPanel,
|
|
||||||
} = useAppSelector(fullScreenSelector);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
useHotkeys('1', () => {
|
useHotkeys('1', () => {
|
||||||
@ -139,22 +105,6 @@ export default function InvokeTabs() {
|
|||||||
[isLightBoxOpen]
|
[isLightBoxOpen]
|
||||||
);
|
);
|
||||||
|
|
||||||
useHotkeys(
|
|
||||||
'f',
|
|
||||||
() => {
|
|
||||||
if (shouldShowGallery || shouldShowOptionsPanel) {
|
|
||||||
dispatch(setShouldShowOptionsPanel(false));
|
|
||||||
dispatch(setShouldShowGallery(false));
|
|
||||||
} else {
|
|
||||||
dispatch(setShouldShowOptionsPanel(true));
|
|
||||||
dispatch(setShouldShowGallery(true));
|
|
||||||
}
|
|
||||||
if (shouldPinGallery || shouldPinOptionsPanel)
|
|
||||||
setTimeout(() => dispatch(setDoesCanvasNeedScaling(true)), 400);
|
|
||||||
},
|
|
||||||
[shouldShowGallery, shouldShowOptionsPanel]
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderTabs = () => {
|
const renderTabs = () => {
|
||||||
const tabsToRender: ReactElement[] = [];
|
const tabsToRender: ReactElement[] = [];
|
||||||
Object.keys(tabDict).forEach((key) => {
|
Object.keys(tabDict).forEach((key) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user