Skip to content

Commit 84d4fd9

Browse files
committed
wip reveal minimized windows
1 parent 7835ec8 commit 84d4fd9

4 files changed

Lines changed: 46 additions & 17 deletions

File tree

src/components/BorderedApp/BorderedApp.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function BorderedApp({
2929
minDimensions = { height: 350, width: 350 },
3030
menus,
3131
zIndex,
32+
hidden,
3233
}: React.PropsWithChildren<BorderedAppProps>) {
3334
const winMan = useWindowManagerStore();
3435
const settings = useSystemSettings();
@@ -57,6 +58,8 @@ function BorderedApp({
5758
winMan.closeWindow(type, id);
5859
}
5960

61+
console.log("Hidden", hidden);
62+
6063
return (
6164
<div
6265
className="bordered-app"
@@ -67,6 +70,8 @@ function BorderedApp({
6770
height: initialDimensions.height,
6871
zIndex,
6972
backgroundColor: settings.mainColor,
73+
display: hidden === true ? "none" : "grid",
74+
color: hidden === true ? "black" : "green",
7075
}}
7176
>
7277
<div className="bordered-app__corner-nw" ref={resizeHandleNW} />

src/components/Content/Content.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ function Content({}: ContentProps) {
1111
return (
1212
<div id="content__container">
1313
<div id="content" ref={winMan.contentRef}>
14-
{winMan.getWindowDefinitions().map((definition) => (
15-
<definition.component {...definition.props} key={definition.key}>
16-
{definition.children}
17-
</definition.component>
18-
))}
14+
{winMan.getWindowDefinitions().map((definition) => {
15+
console.log(definition);
16+
return (
17+
<definition.component {...definition.props} key={definition.key}>
18+
{definition.children}
19+
</definition.component>
20+
);
21+
})}
1922
</div>
2023
</div>
2124
);

src/hooks/useWindowMinMax.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MutableRefObject } from "react";
1+
import { MutableRefObject, useEffect, useRef } from "react";
22
import useWindowManagerStore from "../stores/windowManagerStore";
33
import { Rect } from "./useDragToResize";
44

@@ -12,6 +12,9 @@ interface UseWindowMinMaxProps {
1212
}
1313
function useWindowMinMax({ windowRect, windowRef }: UseWindowMinMaxProps) {
1414
const winMan = useWindowManagerStore();
15+
const oldTransition = useRef<string>("");
16+
const oldTransform = useRef<string>("");
17+
const oldOpacity = useRef<string>("");
1518

1619
function maximize() {
1720
const boundary = winMan.contentRef.current?.getBoundingClientRect();
@@ -33,24 +36,37 @@ function useWindowMinMax({ windowRect, windowRef }: UseWindowMinMaxProps) {
3336
const window = windowRef.current;
3437
if (!window) return;
3538

36-
const oldTransition = window.style.transition;
37-
const oldTransform = window.style.transform;
38-
const oldOpacity = window.style.opacity;
39+
oldTransition.current = window.style.transition;
40+
oldTransform.current = window.style.transform;
41+
oldOpacity.current = window.style.opacity;
3942

4043
window.style.transition = "all 0.2s linear";
4144
window.style.opacity = "0";
4245
window.style.transform = "scale(0.5) translate(0, 500%)";
4346

44-
window.addEventListener("transitionend", (e) => {
45-
if (e.target === window) {
46-
window.style.display = "none";
47-
window.style.transition = oldTransition;
48-
window.style.transform = oldTransform;
49-
window.style.opacity = oldOpacity;
47+
window.addEventListener("transitionend", handleTransitionEnd);
48+
}
49+
50+
function handleTransitionEnd(e: TransitionEvent) {
51+
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;
5060
}
51-
});
61+
}
5262
}
5363

64+
useEffect(() => {
65+
return () => {
66+
window.removeEventListener("transitionend", handleTransitionEnd);
67+
};
68+
});
69+
5470
return {
5571
maximize,
5672
minimize,

src/stores/windowManagerStore.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { create } from "zustand";
33

44
export interface BaseProps {
55
zIndex?: number;
6+
hidden?: boolean;
67
children?: React.ReactNode;
78
}
89

@@ -92,7 +93,10 @@ const useWindowManagerStore = create<WindowManagerStoreState>()((set, get) => ({
9293
// To do this, we sort them so we're processing the one with the lowest zindex first
9394
Array.from(windowsOfType.values())
9495
.sort((a, b) => (a.props.zIndex ?? 0) - (b.props.zIndex ?? 0))
95-
.forEach((window) => (window.props.zIndex = ++highestZIndex));
96+
.forEach((window) => {
97+
window.props.zIndex = ++highestZIndex;
98+
window.props.hidden = false;
99+
});
96100

97101
set({ windowsMap });
98102
},
@@ -111,6 +115,7 @@ const useWindowManagerStore = create<WindowManagerStoreState>()((set, get) => ({
111115
// Increase the zindex counter and set the window to have this zindex
112116
highestZIndex++;
113117
window.props.zIndex = highestZIndex;
118+
window.props.hidden = false;
114119

115120
set({ windowsMap, highestZIndex });
116121
},

0 commit comments

Comments
 (0)