mirror of
https://github.com/suitenumerique/meet.git
synced 2026-09-04 14:45:40 +00:00
⚡️(frontend) isolate the creation menu in a dedicated component
Avoid re-rendering the whole home page when interacting with the later meeting creation flow. Maintaining the modal open/close state at the parent level was causing the whole home page to re-render on every menu open/close state change.
This commit is contained in:
committed by
aleb_the_flash
parent
995e6fa41d
commit
8984d863df
@@ -147,18 +147,63 @@ const IntroText = styled('div', {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const Home = () => {
|
const CreateMeetingMenu = () => {
|
||||||
const { t } = useTranslation('home')
|
|
||||||
const { isLoggedIn } = useUser()
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
userChoices: { username },
|
userChoices: { username },
|
||||||
} = usePersistentUserChoices()
|
} = usePersistentUserChoices()
|
||||||
|
|
||||||
|
const { t } = useTranslation('home')
|
||||||
const { mutateAsync: createRoom } = useCreateRoom()
|
const { mutateAsync: createRoom } = useCreateRoom()
|
||||||
const [laterRoom, setLaterRoom] = useState<null | ApiRoom>(null)
|
const [laterRoom, setLaterRoom] = useState<null | ApiRoom>(null)
|
||||||
const [redirectFailed, setRedirectFailed] = useState(false)
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Menu>
|
||||||
|
<Button variant="primary" data-attr="create-meeting">
|
||||||
|
{t('createMeeting')}
|
||||||
|
</Button>
|
||||||
|
<RACMenu>
|
||||||
|
<MenuItem
|
||||||
|
className={menuRecipe({ icon: true, variant: 'light' }).item}
|
||||||
|
onAction={() => {
|
||||||
|
const slug = generateRoomId()
|
||||||
|
createRoom({ slug, username }).then((data) =>
|
||||||
|
navigateTo('room', data.slug, {
|
||||||
|
state: { create: true, initialRoomData: data },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
data-attr="create-option-instant"
|
||||||
|
>
|
||||||
|
<RiAddLine size={18} />
|
||||||
|
{t('createMenu.instantOption')}
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
className={menuRecipe({ icon: true, variant: 'light' }).item}
|
||||||
|
onAction={() => {
|
||||||
|
const slug = generateRoomId()
|
||||||
|
createRoom({ slug, username }).then(setLaterRoom)
|
||||||
|
}}
|
||||||
|
data-attr="create-option-later"
|
||||||
|
>
|
||||||
|
<RiLink size={18} />
|
||||||
|
{t('createMenu.laterOption')}
|
||||||
|
</MenuItem>
|
||||||
|
</RACMenu>
|
||||||
|
</Menu>
|
||||||
|
<LaterMeetingDialog
|
||||||
|
room={laterRoom}
|
||||||
|
onOpenChange={() => setLaterRoom(null)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const Home = () => {
|
||||||
|
const { t } = useTranslation('home')
|
||||||
|
const { isLoggedIn } = useUser()
|
||||||
|
|
||||||
|
const [redirectFailed, setRedirectFailed] = useState(false)
|
||||||
const { data } = useConfig()
|
const { data } = useConfig()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -201,45 +246,7 @@ const Home = () => {
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{isLoggedIn ? (
|
{isLoggedIn ? (
|
||||||
<Menu>
|
<CreateMeetingMenu />
|
||||||
<Button variant="primary" data-attr="create-meeting">
|
|
||||||
{t('createMeeting')}
|
|
||||||
</Button>
|
|
||||||
<RACMenu>
|
|
||||||
<MenuItem
|
|
||||||
className={
|
|
||||||
menuRecipe({ icon: true, variant: 'light' }).item
|
|
||||||
}
|
|
||||||
onAction={async () => {
|
|
||||||
const slug = generateRoomId()
|
|
||||||
createRoom({ slug, username }).then((data) =>
|
|
||||||
navigateTo('room', data.slug, {
|
|
||||||
state: { create: true, initialRoomData: data },
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
data-attr="create-option-instant"
|
|
||||||
>
|
|
||||||
<RiAddLine size={18} />
|
|
||||||
{t('createMenu.instantOption')}
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem
|
|
||||||
className={
|
|
||||||
menuRecipe({ icon: true, variant: 'light' }).item
|
|
||||||
}
|
|
||||||
onAction={() => {
|
|
||||||
const slug = generateRoomId()
|
|
||||||
createRoom({ slug, username }).then((data) =>
|
|
||||||
setLaterRoom(data)
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
data-attr="create-option-later"
|
|
||||||
>
|
|
||||||
<RiLink size={18} />
|
|
||||||
{t('createMenu.laterOption')}
|
|
||||||
</MenuItem>
|
|
||||||
</RACMenu>
|
|
||||||
</Menu>
|
|
||||||
) : (
|
) : (
|
||||||
<LoginButton proConnectHint={false} />
|
<LoginButton proConnectHint={false} />
|
||||||
)}
|
)}
|
||||||
@@ -265,10 +272,6 @@ const Home = () => {
|
|||||||
<IntroSlider />
|
<IntroSlider />
|
||||||
</RightColumn>
|
</RightColumn>
|
||||||
</Columns>
|
</Columns>
|
||||||
<LaterMeetingDialog
|
|
||||||
room={laterRoom}
|
|
||||||
onOpenChange={() => setLaterRoom(null)}
|
|
||||||
/>
|
|
||||||
</Screen>
|
</Screen>
|
||||||
</UserAware>
|
</UserAware>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user