Files
Quic/ui/src/components/layout/MainMenu.tsx
T

160 lines
4.8 KiB
TypeScript

import React from 'react'
import { NavLink } from 'react-router-dom'
import { useQuery, gql } from '@apollo/client'
import { authToken } from '../../helpers/authentication'
import { useTranslation } from 'react-i18next'
import { mapboxEnabledQuery } from '../../__generated__/mapboxEnabledQuery'
import { tailwindClassNames } from '../../helpers/utils'
import { faceDetectionEnabled } from './__generated__/faceDetectionEnabled'
export const MAPBOX_QUERY = gql`
query mapboxEnabledQuery {
mapboxToken
}
`
export const FACE_DETECTION_ENABLED_QUERY = gql`
query faceDetectionEnabled {
siteInfo {
faceDetectionEnabled
}
}
`
type MenuButtonProps = {
to: string
exact: boolean
label: string
background: string
activeClasses?: string
className?: string
icon?: React.ReactNode
}
const MenuButton = ({
to,
exact,
label,
background,
icon,
activeClasses,
className,
}: MenuButtonProps) => {
return (
<NavLink
to={to}
end={exact}
className={({ isActive }) =>
tailwindClassNames(
`rounded-lg my-2 outline-none`,
className,
{
activeClasses: isActive,
}
)
}
>
<li className="flex items-center">
<div
className={`w-12 h-12 p-1.5 lg:w-8 lg:h-8 lg:p-1 w-full h-full rounded-lg`}
style={{ backgroundColor: background }}
>
{icon}
</div>
<span className="hidden lg:block ml-2">{label}</span>
</li>
</NavLink>
)
}
const MenuSeparator = () => (
<hr className="hidden lg:block my-3 border-gray-200 dark:border-dark-border" />
)
export const MainMenu = () => {
const { t } = useTranslation()
const mapboxQuery = authToken()
? useQuery<mapboxEnabledQuery>(MAPBOX_QUERY)
: null
const faceDetectionEnabledQuery = authToken()
? useQuery<faceDetectionEnabled>(FACE_DETECTION_ENABLED_QUERY)
: null
const mapboxEnabled = !!mapboxQuery?.data?.mapboxToken
const faceDetectionEnabled =
!!faceDetectionEnabledQuery?.data?.siteInfo?.faceDetectionEnabled
return (
<div className="fixed w-full bottom-0 lg:bottom-auto lg:top-16 z-30 bg-dark-bg lg:w-[240px] lg:ml-0 lg:mr-5 flex-shrink-0">
<ul className="flex justify-around py-2 px-2 max-w-lg mx-auto lg:flex-col lg:p-0">
<MenuButton
to="/timeline"
exact
label={t('sidemenu.photos', 'Timeline')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="3" y="3" width="18" height="18" rx="2" />
<circle cx="8.5" cy="8.5" r="1.5" />
<path d="m21 15-5-5L5 21" />
</svg>
}
/>
<MenuButton
to="/albums"
exact
label={t('sidemenu.albums', 'Albums')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z" />
</svg>
}
/>
<MenuButton
to="/settings"
exact
label={t('sidemenu.settings', 'Settings')}
background="#000000"
activeClasses="bg-[#1a1a1a] dark:bg-[#1a1a1a]"
className="focus:ring-0 shadow-none"
icon={
<svg
viewBox="0 0 24 24"
fill="none"
stroke="white"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<circle cx="12" cy="12" r="3" />
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
</svg>
}
/>
</ul>
</div>
)
}
export default MainMenu