Skip to content

Commit 090ee24

Browse files
committed
Fix minimize/reveal windows
1 parent 4d8ae83 commit 090ee24

6 files changed

Lines changed: 33 additions & 17 deletions

File tree

src/components/BorderedApp/BorderedApp.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ function BorderedApp({
5252
} = usePositionableElement({
5353
elementRef: appRef,
5454
minDimensions,
55+
windowType: type,
56+
windowId: id,
5557
});
5658

5759
function onClickClose() {
5860
winMan.closeWindow(type, id);
5961
}
6062

61-
console.log("Hidden", hidden);
62-
6363
return (
6464
<div
6565
className="bordered-app"
@@ -71,7 +71,6 @@ function BorderedApp({
7171
zIndex,
7272
backgroundColor: settings.mainColor,
7373
display: hidden === true ? "none" : "grid",
74-
color: hidden === true ? "black" : "green",
7574
}}
7675
>
7776
<div className="bordered-app__corner-nw" ref={resizeHandleNW} />

src/components/Content/Content.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function Content({}: ContentProps) {
1212
<div id="content__container">
1313
<div id="content" ref={winMan.contentRef}>
1414
{winMan.getWindowDefinitions().map((definition) => {
15-
console.log(definition);
1615
return (
1716
<definition.component {...definition.props} key={definition.key}>
1817
{definition.children}

src/hooks/useDetectMouseDownOutside.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ function useDetectMouseDownOutside<Element extends HTMLElement>({
3737
return;
3838
}
3939

40-
console.log(elementRef.current);
41-
4240
let call = true;
4341
function process(children: HTMLCollection) {
4442
for (const child of children) {

src/hooks/usePositionableElement.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import useWindowMinMax from "./useWindowMinMax";
66
interface UsePositionableElementProps {
77
elementRef: React.RefObject<HTMLElement>;
88
minDimensions: Dimensions;
9+
windowType: string;
10+
windowId: string;
911
}
1012

1113
/**
@@ -17,6 +19,8 @@ interface UsePositionableElementProps {
1719
function usePositionableElement({
1820
elementRef,
1921
minDimensions,
22+
windowType,
23+
windowId,
2024
}: UsePositionableElementProps) {
2125
// Hold a single ref for the elements rect,
2226
// so we dont have to call getBoundingClientRect every
@@ -65,6 +69,8 @@ function usePositionableElement({
6569
const { maximize, minimize } = useWindowMinMax({
6670
windowRef: elementRef,
6771
windowRect: elementRect,
72+
windowType,
73+
windowId,
6874
});
6975

7076
return {

src/hooks/useWindowMinMax.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ function toPx(value: number) {
99
interface UseWindowMinMaxProps {
1010
windowRef: React.RefObject<HTMLElement>;
1111
windowRect: MutableRefObject<Partial<Rect>>;
12+
windowType: string;
13+
windowId: string;
1214
}
13-
function useWindowMinMax({ windowRect, windowRef }: UseWindowMinMaxProps) {
15+
function useWindowMinMax({
16+
windowRect,
17+
windowRef,
18+
windowId,
19+
windowType,
20+
}: UseWindowMinMaxProps) {
1421
const winMan = useWindowManagerStore();
1522
const oldTransition = useRef<string>("");
1623
const oldTransform = useRef<string>("");
@@ -49,16 +56,14 @@ function useWindowMinMax({ windowRect, windowRef }: UseWindowMinMaxProps) {
4956

5057
function handleTransitionEnd(e: TransitionEvent) {
5158
const window = windowRef.current;
52-
if (!window) return;
53-
if (e.target === window) {
54-
console.log("Setting no display");
55-
if (window.style) {
56-
window.style.display = "inline";
57-
window.style.transition = oldTransition.current;
58-
window.style.transform = oldTransform.current;
59-
window.style.opacity = oldOpacity.current;
60-
}
61-
}
59+
if (!window?.style) return;
60+
if (e.target !== window) return;
61+
62+
window.style.display = "none";
63+
window.style.transition = oldTransition.current;
64+
window.style.transform = oldTransform.current;
65+
window.style.opacity = oldOpacity.current;
66+
winMan.hideWindow(windowType, windowId);
6267
}
6368

6469
useEffect(() => {

src/stores/windowManagerStore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface WindowManagerStoreState {
2828
focusWindowsOfType: (windowType: string) => void;
2929
focusWindow: (windowType: string, windowId: string) => void;
3030
windowsOfTypeExist: (windowType: string) => boolean;
31+
hideWindow: (windowType: string, windowId: string) => void;
3132
}
3233

3334
const useWindowManagerStore = create<WindowManagerStoreState>()((set, get) => ({
@@ -122,6 +123,14 @@ const useWindowManagerStore = create<WindowManagerStoreState>()((set, get) => ({
122123
windowsOfTypeExist(windowType) {
123124
return (get().windowsMap.get(windowType)?.size ?? 0) > 0;
124125
},
126+
hideWindow(windowType, windowId) {
127+
const windowsMap = get().windowsMap;
128+
const windowsOfType = windowsMap.get(windowType);
129+
const window = windowsOfType?.get(windowId);
130+
if (!windowsOfType || !window) return;
131+
window.props.hidden = true;
132+
set({ windowsMap });
133+
},
125134
}));
126135

127136
export default useWindowManagerStore;

0 commit comments

Comments
 (0)