1- import { MutableRefObject } from "react" ;
1+ import { MutableRefObject , useEffect , useRef } from "react" ;
22import useWindowManagerStore from "../stores/windowManagerStore" ;
33import { Rect } from "./useDragToResize" ;
44
@@ -12,6 +12,9 @@ interface UseWindowMinMaxProps {
1212}
1313function 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,
0 commit comments