1- import { useState , useRef , memo } from 'react' ;
1+ import { useRef , memo } from 'react' ;
22import { type Retro } from '../../shared/api-entities' ;
33import { type RetroPagePropsT } from '../RetroRouter' ;
44import { ArchivePopup } from './ArchivePopup' ;
55import { Header } from '../common/Header' ;
66import { Popup } from '../common/Popup' ;
77import { useEvent } from '../../hooks/useEvent' ;
88import { useWindowSize , type Size } from '../../hooks/env/useWindowSize' ;
9+ import { useBoolean } from '../../hooks/useBoolean' ;
910import { clearCovered } from '../../actions/retro' ;
1011import { archiveService } from '../../api/api' ;
1112import { OPTIONS } from '../../helpers/optionManager' ;
@@ -37,12 +38,8 @@ const isSmallScreen = ({ width }: Size) => width <= 800;
3738export const RetroPage = memo (
3839 ( { retroToken, retro, retroDispatch, group } : PropsT ) => {
3940 const smallScreen = useWindowSize ( isSmallScreen ) ;
40- const [ archivePopupVisible , setArchivePopupVisible ] = useState ( false ) ;
41- const showArchivePopup = useEvent ( ( ) => setArchivePopupVisible ( true ) ) ;
42- const hideArchivePopup = useEvent ( ( ) => setArchivePopupVisible ( false ) ) ;
43- const [ invitePopupVisible , setInvitePopupVisible ] = useState ( false ) ;
44- const showInvitePopup = useEvent ( ( ) => setInvitePopupVisible ( true ) ) ;
45- const hideInvitePopup = useEvent ( ( ) => setInvitePopupVisible ( false ) ) ;
41+ const archivePopupVisible = useBoolean ( false ) ;
42+ const invitePopupVisible = useBoolean ( false ) ;
4643
4744 const isArchiving = useRef ( false ) ;
4845 const performArchive = useEvent ( ( ) => {
@@ -56,7 +53,7 @@ export const RetroPage = memo(
5653 . then ( ( ) => {
5754 isArchiving . current = false ;
5855 retroDispatch ! ( clearCovered ( ) ) ;
59- hideArchivePopup ( ) ;
56+ archivePopupVisible . setFalse ( ) ;
6057 } )
6158 . catch ( ( e ) => {
6259 // TODO: report failure to user
@@ -76,14 +73,16 @@ export const RetroPage = memo(
7673 ) ;
7774
7875 const links = [
79- { label : 'Invite' , action : showInvitePopup } ,
76+ { label : 'Invite' , action : invitePopupVisible . setTrue } ,
8077 retroDispatch
8178 ? {
8279 label : 'Settings' ,
8380 action : `/retros/${ encodeURIComponent ( retro . slug ) } /settings` ,
8481 }
8582 : null ,
86- canArchive ? { label : 'Create Archive' , action : showArchivePopup } : null ,
83+ canArchive
84+ ? { label : 'Create Archive' , action : archivePopupVisible . setTrue }
85+ : null ,
8786 {
8887 label : 'Archives' ,
8988 action : `/retros/${ encodeURIComponent ( retro . slug ) } /archives` ,
@@ -112,28 +111,31 @@ export const RetroPage = memo(
112111 retroState = { getState ( group , retro ) }
113112 group = { group }
114113 dispatch = { retroDispatch ?? undefined }
115- onComplete = { canArchive ? showArchivePopup : undefined }
114+ onComplete = { canArchive ? archivePopupVisible . setTrue : undefined }
116115 archive = { false }
117116 />
118117 < Popup
119118 title = "Create Archive"
120- isOpen = { Boolean ( retroDispatch && archivePopupVisible ) }
121- keys = { { Enter : performArchive , Escape : hideArchivePopup } }
122- onClose = { hideArchivePopup }
119+ isOpen = { Boolean ( retroDispatch ) && archivePopupVisible . value }
120+ keys = { { Enter : performArchive , Escape : archivePopupVisible . setFalse } }
121+ onClose = { archivePopupVisible . setFalse }
123122 >
124123 < ArchivePopup
125124 onConfirm = { performArchive }
126- onCancel = { hideArchivePopup }
125+ onCancel = { archivePopupVisible . setFalse }
127126 />
128127 </ Popup >
129128 < Popup
130129 title = "Invite"
131130 hideTitle
132- isOpen = { invitePopupVisible }
133- keys = { { Enter : hideInvitePopup , Escape : hideInvitePopup } }
134- onClose = { hideInvitePopup }
131+ isOpen = { invitePopupVisible . value }
132+ keys = { {
133+ Enter : invitePopupVisible . setFalse ,
134+ Escape : invitePopupVisible . setFalse ,
135+ } }
136+ onClose = { invitePopupVisible . setFalse }
135137 >
136- < InvitePopup onClose = { hideInvitePopup } />
138+ < InvitePopup onClose = { invitePopupVisible . setFalse } />
137139 </ Popup >
138140 </ article >
139141 ) ;
0 commit comments