diff --git a/src/transitions/TransitionAnimation.tsx b/src/transitions/TransitionAnimation.tsx index 7f343416..a965d6ed 100644 --- a/src/transitions/TransitionAnimation.tsx +++ b/src/transitions/TransitionAnimation.tsx @@ -1,36 +1,42 @@ -import { useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { Transition } from 'react-transition-group'; import { TransitionAnimationProps } from './TransitionAnimation.types'; import { getTransitionAnimationStyle } from './TransitionAnimationStyles'; -export function TransitionAnimation(props: TransitionAnimationProps): JSX.Element +export const TransitionAnimation: FC = props => { const { type = null, inProp = false, timeout = 300, className = null, children = null } = props; - const [ showChild, setShowChild ] = useState(false); - const [ timeoutInstance, setTimeoutInstance ] = useState(null); + const [ isChildrenVisible, setChildrenVisible ] = useState(false); useEffect(() => { + let timeoutData: ReturnType = null; + if(inProp) { - clearTimeout(timeoutInstance); - setShowChild(true); + setChildrenVisible(true); } else { - setTimeoutInstance(setTimeout(() => { - setShowChild(false); - clearTimeout(timeoutInstance); - }, timeout)); + timeoutData = setTimeout(() => + { + setChildrenVisible(false); + clearTimeout(timeout); + }, timeout); } - }, [ inProp ]) + + return () => + { + if(timeoutData) clearTimeout(timeoutData); + } + }, [ inProp, timeout ]); return ( - {state => ( + { state => (
- { showChild && children } + { isChildrenVisible && children }
)}
diff --git a/src/transitions/TransitionAnimation.types.ts b/src/transitions/TransitionAnimation.types.ts index cde99356..b7f1ed31 100644 --- a/src/transitions/TransitionAnimation.types.ts +++ b/src/transitions/TransitionAnimation.types.ts @@ -1,12 +1,9 @@ -import { ReactNode } from 'react'; - export interface TransitionAnimationProps { type: string; inProp: boolean; timeout?: number; className?: string; - children?: ReactNode; } export class TransitionAnimationTypes diff --git a/src/views/purse/PurseView.tsx b/src/views/purse/PurseView.tsx index ca154ff5..6bf73add 100644 --- a/src/views/purse/PurseView.tsx +++ b/src/views/purse/PurseView.tsx @@ -34,7 +34,7 @@ export const PurseView: FC = props => { if(displayedCurrencies.indexOf(currency.type) === -1) return null; - return + return ; }) } diff --git a/src/views/purse/currency/CurrencyView.tsx b/src/views/purse/currency/CurrencyView.tsx index ccf2ba52..c00f6a45 100644 --- a/src/views/purse/currency/CurrencyView.tsx +++ b/src/views/purse/currency/CurrencyView.tsx @@ -1,6 +1,3 @@ -import { useEffect, useState } from 'react'; -import { TransitionAnimation } from '../../../transitions/TransitionAnimation'; -import { TransitionAnimationTypes } from '../../../transitions/TransitionAnimation.types'; import { CurrencyIcon } from '../../../utils/currency-icon/CurrencyIcon'; import { CurrencyViewProps } from './CurrencyView.types'; @@ -8,21 +5,14 @@ export function CurrencyView(props: CurrencyViewProps): JSX.Element { const { currency = null } = props; - const [ showUp, setShowUp ] = useState(false); - - useEffect(() => - { - setShowUp(true); - }, [ currency ]) - return ( - -
-
-
{ currency.amount }
-
+
+
+
{ currency.amount }
+
+
- +
); } diff --git a/src/views/toolbar/ToolbarView.tsx b/src/views/toolbar/ToolbarView.tsx index 68ed82f4..aa977565 100644 --- a/src/views/toolbar/ToolbarView.tsx +++ b/src/views/toolbar/ToolbarView.tsx @@ -1,4 +1,3 @@ -import classNames from 'classnames'; import { UserInfoEvent } from 'nitro-renderer/src/nitro/communication/messages/incoming/user/data/UserInfoEvent'; import { UserInfoDataParser } from 'nitro-renderer/src/nitro/communication/messages/parser/user/data/UserInfoDataParser'; import { MouseEvent, useCallback, useState } from 'react'; @@ -15,8 +14,8 @@ export function ToolbarView(props: ToolbarViewProps): JSX.Element { const { isInRoom } = props; - const [ userInfo, setUserInfo ] = useState(null); - const [ expandMeToolbar, setExpandMeToolbar ] = useState(false); + const [ userInfo, setUserInfo ] = useState(null); + const [ isMeExpanded, setMeExpanded ] = useState(false); const unseenInventoryCount = 0; const unseenFriendListCount = 0; @@ -31,8 +30,6 @@ export function ToolbarView(props: ToolbarViewProps): JSX.Element function handleToolbarItemClick(event: MouseEvent, item: string): void { - event.preventDefault(); - switch(item) { case ToolbarViewItems.NAVIGATOR_ITEM: @@ -52,20 +49,23 @@ export function ToolbarView(props: ToolbarViewProps): JSX.Element function toggleMeToolbar(): void { - setExpandMeToolbar((value) => !value); + setMeExpanded(prevValue => + { + return !prevValue; + }); } CreateMessageHook(UserInfoEvent, onUserInfoEvent); return ( <> - { - - } + + +
-
+
{ userInfo && }
diff --git a/src/views/toolbar/me/ToolbarMeView.tsx b/src/views/toolbar/me/ToolbarMeView.tsx index 6308d718..7ce487a6 100644 --- a/src/views/toolbar/me/ToolbarMeView.tsx +++ b/src/views/toolbar/me/ToolbarMeView.tsx @@ -1,33 +1,61 @@ +import { MouseEventType } from 'nitro-renderer'; +import { useEffect, useRef } from 'react'; import { ToolbarMeViewProps } from './ToolbarMeView.types'; export function ToolbarMeView(props: ToolbarMeViewProps): JSX.Element { - return (
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- + const { setMeExpanded = null } = props; + + const elementRef = useRef(); + + useEffect(() => + { + function onClick(event: MouseEvent): void + { + const element = elementRef.current; + + if((event.target !== element) && !element.contains((event.target as Node))) + { + setMeExpanded(false); + } + } + + document.addEventListener(MouseEventType.MOUSE_CLICK, onClick); + + return () => + { + document.removeEventListener(MouseEventType.MOUSE_CLICK, onClick); + } + }, [ elementRef, setMeExpanded ]); + + return ( +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
-
); + ); } diff --git a/src/views/toolbar/me/ToolbarMeView.types.ts b/src/views/toolbar/me/ToolbarMeView.types.ts index a9d8cff7..6a3a9076 100644 --- a/src/views/toolbar/me/ToolbarMeView.types.ts +++ b/src/views/toolbar/me/ToolbarMeView.types.ts @@ -1,2 +1,6 @@ +import { Dispatch, SetStateAction } from 'react'; + export interface ToolbarMeViewProps -{} +{ + setMeExpanded: Dispatch>; +}