2021-07-10 16:14:49 +00:00
|
|
|
import * as React from 'react'
|
2021-07-11 12:51:01 +00:00
|
|
|
import { ExitIcon, HamburgerMenuIcon } from '@radix-ui/react-icons'
|
2021-07-14 13:45:24 +00:00
|
|
|
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
2021-07-10 16:14:49 +00:00
|
|
|
import { memo } from 'react'
|
|
|
|
import {
|
|
|
|
FloatingContainer,
|
|
|
|
DropdownMenuRoot,
|
|
|
|
MenuContent,
|
|
|
|
IconButton,
|
|
|
|
breakpoints,
|
|
|
|
DropdownMenuButton,
|
|
|
|
DropdownMenuSubMenu,
|
|
|
|
DropdownMenuDivider,
|
2021-07-10 20:39:29 +00:00
|
|
|
DropdownMenuCheckboxItem,
|
2021-07-11 12:51:01 +00:00
|
|
|
IconWrapper,
|
|
|
|
Kbd,
|
2021-07-10 16:14:49 +00:00
|
|
|
} from '../shared'
|
2021-07-10 20:39:29 +00:00
|
|
|
import state, { useSelector } from 'state'
|
2021-07-10 16:14:49 +00:00
|
|
|
import { commandKey } from 'utils'
|
2021-07-11 12:51:01 +00:00
|
|
|
import { signOut } from 'next-auth/client'
|
2021-07-14 08:04:07 +00:00
|
|
|
import { useTheme } from 'next-themes'
|
2021-07-10 16:14:49 +00:00
|
|
|
|
|
|
|
const handleNew = () => state.send('CREATED_NEW_PROJECT')
|
|
|
|
const handleSave = () => state.send('SAVED')
|
|
|
|
const handleLoad = () => state.send('LOADED_FROM_FILE_STSTEM')
|
2021-07-11 12:51:01 +00:00
|
|
|
const toggleDebugMode = () => state.send('TOGGLED_DEBUG_MODE')
|
2021-07-10 16:14:49 +00:00
|
|
|
|
|
|
|
function Menu() {
|
|
|
|
return (
|
|
|
|
<FloatingContainer>
|
|
|
|
<DropdownMenuRoot>
|
2021-07-14 13:45:24 +00:00
|
|
|
<DropdownMenu.Trigger as={IconButton} bp={breakpoints}>
|
2021-07-10 16:14:49 +00:00
|
|
|
<HamburgerMenuIcon />
|
2021-07-14 13:45:24 +00:00
|
|
|
</DropdownMenu.Trigger>
|
|
|
|
<DropdownMenu.Content as={MenuContent} sideOffset={8} align="end">
|
|
|
|
<DropdownMenuButton onSelect={handleNew} disabled={true}>
|
2021-07-10 16:14:49 +00:00
|
|
|
<span>New Project</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>N</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
</Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuButton>
|
|
|
|
<DropdownMenuDivider />
|
|
|
|
<DropdownMenuButton onSelect={handleLoad}>
|
|
|
|
<span>Open...</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>L</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
</Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuButton>
|
|
|
|
<RecentFiles />
|
|
|
|
<DropdownMenuDivider />
|
|
|
|
<DropdownMenuButton onSelect={handleSave}>
|
|
|
|
<span>Save</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>S</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
</Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuButton>
|
|
|
|
<DropdownMenuButton onSelect={handleSave}>
|
|
|
|
<span>Save As...</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
<span>⇧</span>
|
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>S</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
</Kbd>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuButton>
|
|
|
|
<DropdownMenuDivider />
|
|
|
|
<Preferences />
|
2021-07-11 12:51:01 +00:00
|
|
|
<DropdownMenuDivider />
|
|
|
|
<DropdownMenuButton onSelect={signOut}>
|
|
|
|
<span>Sign Out</span>
|
|
|
|
<IconWrapper size="small">
|
|
|
|
<ExitIcon />
|
|
|
|
</IconWrapper>
|
|
|
|
</DropdownMenuButton>
|
2021-07-14 13:45:24 +00:00
|
|
|
</DropdownMenu.Content>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuRoot>
|
|
|
|
</FloatingContainer>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(Menu)
|
|
|
|
|
|
|
|
function RecentFiles() {
|
|
|
|
return (
|
2021-07-14 13:45:24 +00:00
|
|
|
<DropdownMenuSubMenu label="Open Recent..." disabled={true}>
|
2021-07-10 16:14:49 +00:00
|
|
|
<DropdownMenuButton>
|
|
|
|
<span>Project A</span>
|
|
|
|
</DropdownMenuButton>
|
|
|
|
<DropdownMenuButton>
|
|
|
|
<span>Project B</span>
|
|
|
|
</DropdownMenuButton>
|
|
|
|
<DropdownMenuButton>
|
|
|
|
<span>Project C</span>
|
|
|
|
</DropdownMenuButton>
|
|
|
|
</DropdownMenuSubMenu>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function Preferences() {
|
2021-07-14 08:04:07 +00:00
|
|
|
const { theme, setTheme } = useTheme()
|
|
|
|
|
2021-07-11 12:51:01 +00:00
|
|
|
const isDebugMode = useSelector((s) => s.data.settings.isDebugMode)
|
2021-07-14 08:04:07 +00:00
|
|
|
const isDarkMode = theme === 'dark'
|
2021-07-10 20:39:29 +00:00
|
|
|
|
2021-07-10 16:14:49 +00:00
|
|
|
return (
|
|
|
|
<DropdownMenuSubMenu label="Preferences">
|
2021-07-10 20:39:29 +00:00
|
|
|
<DropdownMenuCheckboxItem
|
|
|
|
checked={isDarkMode}
|
2021-07-14 08:04:07 +00:00
|
|
|
onCheckedChange={() => setTheme(isDarkMode ? 'light' : 'dark')}
|
2021-07-10 20:39:29 +00:00
|
|
|
>
|
|
|
|
<span>Dark Mode</span>
|
|
|
|
</DropdownMenuCheckboxItem>
|
2021-07-11 12:51:01 +00:00
|
|
|
<DropdownMenuCheckboxItem
|
|
|
|
checked={isDebugMode}
|
|
|
|
onCheckedChange={toggleDebugMode}
|
|
|
|
>
|
|
|
|
<span>Debug Mode</span>
|
|
|
|
</DropdownMenuCheckboxItem>
|
2021-07-10 16:14:49 +00:00
|
|
|
</DropdownMenuSubMenu>
|
|
|
|
)
|
|
|
|
}
|