forked from microbit-foundation/cctd-ml-machine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull up dialogs to prevent odd behaviours
- Loading branch information
1 parent
ff7c692
commit 2d8bd1a
Showing
8 changed files
with
224 additions
and
173 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { HStack, MenuDivider, useDisclosure } from "@chakra-ui/react"; | ||
import { ReactNode, useMemo } from "react"; | ||
import { useIntl } from "react-intl"; | ||
import { useLocation } from "react-router"; | ||
import { useStore } from "../../store"; | ||
import AboutDialog from "../AboutDialog"; | ||
import ConnectFirstDialog from "../ConnectFirstDialog"; | ||
import FeedbackForm from "../FeedbackForm"; | ||
import HelpMenu from "../HelpMenu"; | ||
import HelpMenuItems, { tourMap } from "../HelpMenuItems"; | ||
import { LanguageDialog } from "../LanguageDialog"; | ||
import LanguageMenuItem from "../LanguageMenuItem"; | ||
import { SettingsDialog } from "../SettingsDialog"; | ||
import SettingsMenu from "../SettingsMenu"; | ||
import SettingsMenuItem from "../SettingsMenuItem"; | ||
import ToolbarMenu from "../ToolbarMenu"; | ||
|
||
interface ItemsRightProps { | ||
menuItems?: ReactNode; | ||
toolbarItems?: ReactNode; | ||
} | ||
|
||
const ItemsRight = ({ menuItems, toolbarItems }: ItemsRightProps) => { | ||
const intl = useIntl(); | ||
const languageDisclosure = useDisclosure(); | ||
const settingsDisclosure = useDisclosure(); | ||
const aboutDialogDisclosure = useDisclosure(); | ||
const feedbackDisclosure = useDisclosure(); | ||
const connectFirstDisclosure = useDisclosure(); | ||
const setPostConnectTourTrigger = useStore( | ||
(s) => s.setPostConnectTourTrigger | ||
); | ||
const tourTriggerName = tourMap[useLocation().pathname]; | ||
const tourTrigger = useMemo(() => { | ||
switch (tourTriggerName) { | ||
case "TrainModel": { | ||
return { | ||
name: tourTriggerName, | ||
delayedUntilConnection: true, | ||
}; | ||
} | ||
case "Connect": { | ||
return { name: tourTriggerName }; | ||
} | ||
default: { | ||
return undefined; | ||
} | ||
} | ||
}, [tourTriggerName]); | ||
return ( | ||
<> | ||
<LanguageDialog | ||
isOpen={languageDisclosure.isOpen} | ||
onClose={languageDisclosure.onClose} | ||
/> | ||
<SettingsDialog | ||
isOpen={settingsDisclosure.isOpen} | ||
onClose={settingsDisclosure.onClose} | ||
/> | ||
<ConnectFirstDialog | ||
isOpen={connectFirstDisclosure.isOpen} | ||
onClose={connectFirstDisclosure.onClose} | ||
onChooseConnect={() => setPostConnectTourTrigger(tourTrigger)} | ||
explanationTextId="connect-to-tour-body" | ||
options={{ postConnectTourTrigger: tourTrigger }} | ||
/> | ||
<AboutDialog | ||
isOpen={aboutDialogDisclosure.isOpen} | ||
onClose={aboutDialogDisclosure.onClose} | ||
/> | ||
<FeedbackForm | ||
isOpen={feedbackDisclosure.isOpen} | ||
onClose={feedbackDisclosure.onClose} | ||
/> | ||
<HStack spacing={3} display={{ base: "none", lg: "flex" }}> | ||
{toolbarItems} | ||
<SettingsMenu | ||
onLanguageDialogOpen={languageDisclosure.onOpen} | ||
onSettingsDialogOpen={settingsDisclosure.onOpen} | ||
/> | ||
</HStack> | ||
<HelpMenu | ||
display={{ base: "none", md: "block", lg: "block" }} | ||
onAboutDialogOpen={aboutDialogDisclosure.onOpen} | ||
onConnectFirstDialogOpen={connectFirstDisclosure.onOpen} | ||
onFeedbackOpen={feedbackDisclosure.onOpen} | ||
tourTrigger={tourTrigger} | ||
/> | ||
<ToolbarMenu | ||
display={{ base: "none", md: "block", lg: "none" }} | ||
variant="plain" | ||
label={intl.formatMessage({ id: "main-menu" })} | ||
> | ||
{menuItems} | ||
<LanguageMenuItem onOpen={languageDisclosure.onOpen} /> | ||
<SettingsMenuItem onOpen={settingsDisclosure.onOpen} /> | ||
</ToolbarMenu> | ||
{/* Toolbar items when sm window size. */} | ||
<ToolbarMenu | ||
display={{ base: "block", md: "none" }} | ||
variant="plain" | ||
label={intl.formatMessage({ id: "main-menu" })} | ||
> | ||
{menuItems} | ||
<LanguageMenuItem onOpen={languageDisclosure.onOpen} /> | ||
<SettingsMenuItem onOpen={settingsDisclosure.onOpen} /> | ||
<MenuDivider /> | ||
<HelpMenuItems | ||
onAboutDialogOpen={aboutDialogDisclosure.onOpen} | ||
onConnectFirstDialogOpen={connectFirstDisclosure.onOpen} | ||
onFeedbackOpen={feedbackDisclosure.onOpen} | ||
tourTrigger={tourTrigger} | ||
/> | ||
</ToolbarMenu> | ||
</> | ||
); | ||
}; | ||
|
||
export default ItemsRight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.