Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | import React, { useContext, useEffect, useMemo, useRef } from "react"; import styled, { ThemeContext } from "styled-components"; import debounce from "lodash/debounce"; import useResizable from "ui/hooks/use-resizable"; import useWindowSize from "ui/hooks/use-window-size"; import { SplitPaneHorizontalDivider } from "ui/splitpane/SplitPaneDivider"; import editorActions from "store/features/editor/editorActions"; import { backgroundSelectors, tilesetSelectors, } from "store/features/entities/entitiesState"; import { NavigatorBackgrounds } from "components/backgrounds/NavigatorBackgrounds"; import BackgroundViewer from "components/backgrounds/BackgroundViewer"; import BackgroundPreviewSettings from "components/backgrounds/BackgroundPreviewSettings"; import { useAppDispatch, useAppSelector } from "store/hooks"; const Wrapper = styled.div` display: flex; width: 100%; `; const ImagesPage = () => { const dispatch = useAppDispatch(); const themeContext = useContext(ThemeContext); const selectedId = useAppSelector((state) => state.navigation.id); const navigatorSidebarWidth = useAppSelector( (state) => state.editor.navigatorSidebarWidth ); const windowSize = useWindowSize(); const prevWindowWidthRef = useRef<number>(0); const windowWidth = windowSize.width || 0; const windowHeight = windowSize.height || 0; const minCenterPaneWidth = 0; const allBackgrounds = useAppSelector((state) => backgroundSelectors.selectAll(state) ); const background = useAppSelector( (state) => backgroundSelectors.selectById(state, selectedId) || tilesetSelectors.selectById(state, selectedId) ); const lastBackgroundId = useRef(""); useEffect(() => { Iif (background) { lastBackgroundId.current = background.id; } }, [background]); const viewBackgroundId = useMemo( () => background?.id || lastBackgroundId.current || allBackgrounds[0]?.id, [allBackgrounds, background] ); const [leftPaneWidth, setLeftPaneSize, startLeftPaneResize] = useResizable({ initialSize: navigatorSidebarWidth, direction: "right", minSize: 50, maxSize: Math.max(101, windowWidth - minCenterPaneWidth - 200), onResizeComplete: (v) => { Iif (v < 200) { setLeftPaneSize(200); } }, }); useEffect(() => { prevWindowWidthRef.current = windowWidth; }); const prevWidth = prevWindowWidthRef.current; useEffect(() => { Iif (windowWidth !== prevWidth) { const panelsTotalWidth = leftPaneWidth + minCenterPaneWidth; const widthOverflow = panelsTotalWidth - windowWidth; Iif (widthOverflow > 0) { setLeftPaneSize(leftPaneWidth - 0.5 * widthOverflow); } } }, [windowWidth, prevWidth, leftPaneWidth, setLeftPaneSize]); const debouncedStoreWidths = useRef( debounce((leftPaneWidth: number) => { dispatch(editorActions.resizeNavigatorSidebar(leftPaneWidth)); }, 100) ); useEffect(() => debouncedStoreWidths.current(leftPaneWidth), [leftPaneWidth]); return ( <Wrapper> <div style={{ transition: "opacity 0.3s ease-in-out", width: Math.max(200, leftPaneWidth), background: themeContext?.colors.sidebar.background, overflow: "hidden", position: "relative", }} > <div style={{ minWidth: 200, position: "relative", width: "100%", height: "100%", }} > <NavigatorBackgrounds height={windowHeight - 38} selectedId={selectedId || background?.id || ""} /> </div> </div> <SplitPaneHorizontalDivider onMouseDown={startLeftPaneResize} /> <div style={{ flex: "1 1 0", minWidth: 0, overflow: "hidden", background: themeContext?.colors.background, color: themeContext?.colors.text, height: windowHeight - 38, position: "relative", display: "flex", flexDirection: "column", }} > <div style={{ flexGrow: 1, position: "relative" }}> <BackgroundPreviewSettings backgroundId={background?.id || ""} /> <BackgroundViewer backgroundId={viewBackgroundId || ""} /> </div> </div> </Wrapper> ); }; export default ImagesPage; |