2023-08-31 08:17:52 -04:00
|
|
|
import { Popover, Transition } from '@headlessui/react'
|
2023-08-18 10:27:01 -04:00
|
|
|
import { ActionButton } from './ActionButton'
|
|
|
|
import { faHome } from '@fortawesome/free-solid-svg-icons'
|
2024-02-11 12:59:00 +11:00
|
|
|
import { type IndexLoaderData } from 'lib/types'
|
|
|
|
import { paths } from 'lib/paths'
|
2023-08-18 10:27:01 -04:00
|
|
|
import { isTauri } from '../lib/isTauri'
|
|
|
|
import { Link } from 'react-router-dom'
|
|
|
|
import { ExportButton } from './ExportButton'
|
2023-08-31 08:17:52 -04:00
|
|
|
import { Fragment } from 'react'
|
2023-10-16 13:28:41 -04:00
|
|
|
import { FileTree } from './FileTree'
|
2023-10-17 12:31:14 -04:00
|
|
|
import { sep } from '@tauri-apps/api/path'
|
2023-12-18 06:15:26 -05:00
|
|
|
import { Logo } from './Logo'
|
|
|
|
import { APP_NAME } from 'lib/constants'
|
2023-08-18 10:27:01 -04:00
|
|
|
|
|
|
|
const ProjectSidebarMenu = ({
|
|
|
|
project,
|
2023-10-16 13:28:41 -04:00
|
|
|
file,
|
2023-08-18 10:27:01 -04:00
|
|
|
renderAsLink = false,
|
|
|
|
}: {
|
|
|
|
renderAsLink?: boolean
|
2023-10-16 13:28:41 -04:00
|
|
|
project?: IndexLoaderData['project']
|
|
|
|
file?: IndexLoaderData['file']
|
2023-08-18 10:27:01 -04:00
|
|
|
}) => {
|
|
|
|
return renderAsLink ? (
|
|
|
|
<Link
|
2023-09-18 23:55:14 -04:00
|
|
|
to={paths.HOME}
|
2023-12-18 06:15:26 -05:00
|
|
|
className="rounded-sm h-9 mr-auto max-h-min min-w-max border-0 py-1 px-2 flex items-center gap-3 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-energy-50 dark:hover:bg-chalkboard-90"
|
2023-08-18 10:27:01 -04:00
|
|
|
data-testid="project-sidebar-link"
|
|
|
|
>
|
2023-12-18 06:15:26 -05:00
|
|
|
<Logo />
|
2023-08-18 10:27:01 -04:00
|
|
|
<span
|
2023-10-17 12:31:14 -04:00
|
|
|
className="hidden text-sm text-chalkboard-110 dark:text-chalkboard-20 whitespace-nowrap lg:block"
|
2023-08-18 10:27:01 -04:00
|
|
|
data-testid="project-sidebar-link-name"
|
|
|
|
>
|
2023-12-18 06:15:26 -05:00
|
|
|
{project?.name ? project.name : APP_NAME}
|
2023-08-18 10:27:01 -04:00
|
|
|
</span>
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
<Popover className="relative">
|
|
|
|
<Popover.Button
|
2023-12-18 06:15:26 -05:00
|
|
|
className="rounded-sm h-9 mr-auto max-h-min min-w-max border-0 py-1 px-2 flex items-center gap-3 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-energy-50 dark:hover:bg-chalkboard-90"
|
2023-08-18 10:27:01 -04:00
|
|
|
data-testid="project-sidebar-toggle"
|
|
|
|
>
|
2023-12-18 06:15:26 -05:00
|
|
|
<Logo />
|
2023-10-16 13:28:41 -04:00
|
|
|
<div className="flex flex-col items-start py-0.5">
|
2023-10-17 12:31:14 -04:00
|
|
|
<span className="hidden text-sm text-chalkboard-110 dark:text-chalkboard-20 whitespace-nowrap lg:block">
|
2023-10-16 13:28:41 -04:00
|
|
|
{isTauri() && file?.name
|
2023-10-17 12:31:14 -04:00
|
|
|
? file.name.slice(file.name.lastIndexOf(sep) + 1)
|
2023-12-18 06:15:26 -05:00
|
|
|
: APP_NAME}
|
2023-10-16 13:28:41 -04:00
|
|
|
</span>
|
|
|
|
{isTauri() && project?.name && (
|
2023-10-17 12:31:14 -04:00
|
|
|
<span className="hidden text-xs text-chalkboard-70 dark:text-chalkboard-40 whitespace-nowrap lg:block">
|
2023-10-16 13:28:41 -04:00
|
|
|
{project.name}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-08-18 10:27:01 -04:00
|
|
|
</Popover.Button>
|
2023-08-31 08:17:52 -04:00
|
|
|
<Transition
|
|
|
|
enter="duration-200 ease-out"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="duration-100 ease-in"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
as={Fragment}
|
|
|
|
>
|
2023-10-17 12:31:14 -04:00
|
|
|
<Popover.Overlay className="fixed inset-0 z-20 bg-chalkboard-110/50" />
|
2023-08-31 08:17:52 -04:00
|
|
|
</Transition>
|
2023-08-18 10:27:01 -04:00
|
|
|
|
2023-08-31 08:17:52 -04:00
|
|
|
<Transition
|
|
|
|
enter="duration-100 ease-out"
|
|
|
|
enterFrom="opacity-0 -translate-x-1/4"
|
|
|
|
enterTo="opacity-100 translate-x-0"
|
|
|
|
leave="duration-75 ease-in"
|
|
|
|
leaveFrom="opacity-100 translate-x-0"
|
|
|
|
leaveTo="opacity-0 -translate-x-4"
|
|
|
|
as={Fragment}
|
|
|
|
>
|
2023-10-16 13:28:41 -04:00
|
|
|
<Popover.Panel
|
2023-12-06 14:44:13 -05:00
|
|
|
className="fixed inset-0 right-auto z-30 grid w-64 h-screen max-h-screen grid-cols-1 border rounded-r-md shadow-md bg-chalkboard-10 dark:bg-chalkboard-100 border-chalkboard-40 dark:border-chalkboard-80"
|
2023-10-16 13:28:41 -04:00
|
|
|
style={{ gridTemplateRows: 'auto 1fr auto' }}
|
|
|
|
>
|
|
|
|
{({ close }) => (
|
|
|
|
<>
|
2023-12-06 14:44:13 -05:00
|
|
|
<div className="flex items-center gap-4 px-4 py-3">
|
2023-12-18 06:15:26 -05:00
|
|
|
<Logo />
|
2023-10-16 13:28:41 -04:00
|
|
|
<div>
|
|
|
|
<p
|
|
|
|
className="m-0 text-chalkboard-100 dark:text-energy-10 text-mono"
|
|
|
|
data-testid="projectName"
|
|
|
|
>
|
2023-12-18 06:15:26 -05:00
|
|
|
{project?.name ? project.name : APP_NAME}
|
2023-10-16 13:28:41 -04:00
|
|
|
</p>
|
|
|
|
{project?.entrypointMetadata && (
|
|
|
|
<p
|
2023-10-17 12:31:14 -04:00
|
|
|
className="m-0 text-xs text-chalkboard-100 dark:text-energy-40"
|
2023-10-16 13:28:41 -04:00
|
|
|
data-testid="createdAt"
|
|
|
|
>
|
|
|
|
Created{' '}
|
|
|
|
{project.entrypointMetadata.createdAt.toLocaleDateString()}
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{isTauri() ? (
|
|
|
|
<FileTree
|
|
|
|
file={file}
|
2023-12-06 14:44:13 -05:00
|
|
|
className="overflow-hidden border-0 border-y border-chalkboard-30 dark:border-chalkboard-80"
|
2023-10-16 13:28:41 -04:00
|
|
|
closePanel={close}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="flex-1 overflow-hidden" />
|
2023-08-31 08:17:52 -04:00
|
|
|
)}
|
2023-12-06 14:44:13 -05:00
|
|
|
<div className="flex flex-col gap-2 p-4 dark:bg-chalkboard-90">
|
2023-10-16 13:28:41 -04:00
|
|
|
<ExportButton
|
|
|
|
className={{
|
2023-12-06 14:44:13 -05:00
|
|
|
button: 'border-transparent dark:border-transparent',
|
2023-10-16 13:28:41 -04:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Export Model
|
|
|
|
</ExportButton>
|
|
|
|
{isTauri() && (
|
|
|
|
<ActionButton
|
|
|
|
Element="link"
|
|
|
|
to={paths.HOME}
|
|
|
|
icon={{
|
|
|
|
icon: faHome,
|
2023-12-06 14:44:13 -05:00
|
|
|
className: 'p-1',
|
|
|
|
size: 'sm',
|
2023-10-16 13:28:41 -04:00
|
|
|
}}
|
2023-12-06 14:44:13 -05:00
|
|
|
className="border-transparent dark:border-transparent hover:bg-energy-10/20 dark:hover:bg-chalkboard-90"
|
2023-10-16 13:28:41 -04:00
|
|
|
>
|
|
|
|
Go to Home
|
|
|
|
</ActionButton>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2023-08-31 08:17:52 -04:00
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
2023-08-18 10:27:01 -04:00
|
|
|
</Popover>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ProjectSidebarMenu
|