2023-05-08 12:36:58 +02:00
|
|
|
import { Trans } from "@lingui/macro"
|
2024-01-01 18:51:54 +01:00
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Divider,
|
|
|
|
|
Group,
|
|
|
|
|
type MantineColorScheme,
|
|
|
|
|
Menu,
|
|
|
|
|
SegmentedControl,
|
|
|
|
|
type SegmentedControlItem,
|
|
|
|
|
useMantineColorScheme,
|
|
|
|
|
} from "@mantine/core"
|
2023-03-06 14:08:48 +01:00
|
|
|
import { showNotification } from "@mantine/notifications"
|
|
|
|
|
import { client } from "app/client"
|
2023-12-28 22:11:03 +01:00
|
|
|
import { redirectToAbout, redirectToAdminUsers, redirectToDonate, redirectToMetrics, redirectToSettings } from "app/redirect/thunks"
|
2022-08-13 10:56:07 +02:00
|
|
|
import { useAppDispatch, useAppSelector } from "app/store"
|
2023-12-28 19:54:51 +01:00
|
|
|
import { type ViewMode } from "app/types"
|
2023-05-05 14:55:03 +02:00
|
|
|
import { useViewMode } from "hooks/useViewMode"
|
2024-01-01 18:51:54 +01:00
|
|
|
import { type ReactNode, useState } from "react"
|
2023-03-06 14:08:48 +01:00
|
|
|
import {
|
|
|
|
|
TbChartLine,
|
2023-05-26 08:28:23 +02:00
|
|
|
TbHeartFilled,
|
2023-03-06 14:08:48 +01:00
|
|
|
TbHelp,
|
|
|
|
|
TbLayoutList,
|
|
|
|
|
TbList,
|
2023-04-26 22:39:09 +02:00
|
|
|
TbListDetails,
|
2023-03-06 14:08:48 +01:00
|
|
|
TbMoon,
|
|
|
|
|
TbNotes,
|
|
|
|
|
TbPower,
|
|
|
|
|
TbSettings,
|
|
|
|
|
TbSun,
|
2024-01-01 18:51:54 +01:00
|
|
|
TbSunMoon,
|
2023-03-06 14:08:48 +01:00
|
|
|
TbUsers,
|
|
|
|
|
TbWorldDownload,
|
|
|
|
|
} from "react-icons/tb"
|
2022-08-13 10:56:07 +02:00
|
|
|
|
|
|
|
|
interface ProfileMenuProps {
|
|
|
|
|
control: React.ReactElement
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 18:51:54 +01:00
|
|
|
const ProfileMenuControlItem = ({ icon, label }: { icon: ReactNode; label: ReactNode }) => {
|
|
|
|
|
return (
|
|
|
|
|
<Group>
|
|
|
|
|
{icon}
|
|
|
|
|
<Box ml={6}>{label}</Box>
|
|
|
|
|
</Group>
|
|
|
|
|
)
|
2022-08-23 13:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-05 13:52:28 +02:00
|
|
|
const iconSize = 16
|
|
|
|
|
|
2024-01-01 18:51:54 +01:00
|
|
|
interface ColorSchemeControlItem extends SegmentedControlItem {
|
|
|
|
|
value: MantineColorScheme
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const colorSchemeData: ColorSchemeControlItem[] = [
|
|
|
|
|
{
|
|
|
|
|
value: "light",
|
|
|
|
|
label: <ProfileMenuControlItem icon={<TbSun size={iconSize} />} label={<Trans>Light</Trans>} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "dark",
|
|
|
|
|
label: <ProfileMenuControlItem icon={<TbMoon size={iconSize} />} label={<Trans>Dark</Trans>} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "auto",
|
|
|
|
|
label: <ProfileMenuControlItem icon={<TbSunMoon size={iconSize} />} label={<Trans>System</Trans>} />,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
interface ViewModeControlItem extends SegmentedControlItem {
|
|
|
|
|
value: ViewMode
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-23 13:42:28 +02:00
|
|
|
const viewModeData: ViewModeControlItem[] = [
|
|
|
|
|
{
|
|
|
|
|
value: "title",
|
2024-01-01 18:51:54 +01:00
|
|
|
label: <ProfileMenuControlItem icon={<TbList size={iconSize} />} label={<Trans>Compact</Trans>} />,
|
2022-08-23 13:42:28 +02:00
|
|
|
},
|
2022-09-05 13:52:28 +02:00
|
|
|
{
|
|
|
|
|
value: "cozy",
|
2024-01-01 18:51:54 +01:00
|
|
|
label: <ProfileMenuControlItem icon={<TbLayoutList size={iconSize} />} label={<Trans>Cozy</Trans>} />,
|
2022-09-05 13:52:28 +02:00
|
|
|
},
|
2023-04-26 22:39:09 +02:00
|
|
|
{
|
|
|
|
|
value: "detailed",
|
2024-01-01 18:51:54 +01:00
|
|
|
label: <ProfileMenuControlItem icon={<TbListDetails size={iconSize} />} label={<Trans>Detailed</Trans>} />,
|
2023-04-26 22:39:09 +02:00
|
|
|
},
|
2022-08-23 13:42:28 +02:00
|
|
|
{
|
|
|
|
|
value: "expanded",
|
2024-01-01 18:51:54 +01:00
|
|
|
label: <ProfileMenuControlItem icon={<TbNotes size={iconSize} />} label={<Trans>Expanded</Trans>} />,
|
2022-08-23 13:42:28 +02:00
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
2022-08-13 10:56:07 +02:00
|
|
|
export function ProfileMenu(props: ProfileMenuProps) {
|
|
|
|
|
const [opened, setOpened] = useState(false)
|
2023-04-27 13:44:11 +02:00
|
|
|
const { viewMode, setViewMode } = useViewMode()
|
2023-03-06 14:08:48 +01:00
|
|
|
const profile = useAppSelector(state => state.user.profile)
|
2022-08-13 10:56:07 +02:00
|
|
|
const admin = useAppSelector(state => state.user.profile?.admin)
|
|
|
|
|
const dispatch = useAppDispatch()
|
2024-01-01 18:51:54 +01:00
|
|
|
const { colorScheme, setColorScheme } = useMantineColorScheme()
|
2022-08-13 10:56:07 +02:00
|
|
|
|
|
|
|
|
const logout = () => {
|
|
|
|
|
window.location.href = "logout"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Menu position="bottom-end" closeOnItemClick={false} opened={opened} onChange={setOpened}>
|
|
|
|
|
<Menu.Target>{props.control}</Menu.Target>
|
|
|
|
|
<Menu.Dropdown>
|
2023-03-06 14:08:48 +01:00
|
|
|
{profile && <Menu.Label>{profile.name}</Menu.Label>}
|
2022-08-13 10:56:07 +02:00
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbSettings size={iconSize} />}
|
2022-08-13 10:56:07 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(redirectToSettings())
|
|
|
|
|
setOpened(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Trans>Settings</Trans>
|
|
|
|
|
</Menu.Item>
|
2023-03-06 14:08:48 +01:00
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbWorldDownload size={iconSize} />}
|
2023-12-28 19:54:51 +01:00
|
|
|
onClick={async () =>
|
|
|
|
|
await client.feed.refreshAll().then(() => {
|
2023-03-06 14:08:48 +01:00
|
|
|
showNotification({
|
2023-05-08 12:36:58 +02:00
|
|
|
message: <Trans>Your feeds have been queued for refresh.</Trans>,
|
2023-03-06 14:08:48 +01:00
|
|
|
color: "green",
|
|
|
|
|
autoClose: 1000,
|
|
|
|
|
})
|
|
|
|
|
setOpened(false)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Trans>Fetch all my feeds now</Trans>
|
|
|
|
|
</Menu.Item>
|
2022-08-23 13:42:28 +02:00
|
|
|
|
|
|
|
|
<Divider />
|
2023-05-26 08:28:23 +02:00
|
|
|
|
2022-08-23 13:42:28 +02:00
|
|
|
<Menu.Label>
|
2022-08-13 10:56:07 +02:00
|
|
|
<Trans>Theme</Trans>
|
2022-10-27 14:45:22 +02:00
|
|
|
</Menu.Label>
|
2024-01-01 18:51:54 +01:00
|
|
|
<SegmentedControl
|
|
|
|
|
fullWidth
|
|
|
|
|
orientation="vertical"
|
|
|
|
|
data={colorSchemeData}
|
|
|
|
|
value={colorScheme}
|
|
|
|
|
onChange={e => setColorScheme(e as MantineColorScheme)}
|
|
|
|
|
mb="xs"
|
|
|
|
|
/>
|
2022-10-27 14:45:22 +02:00
|
|
|
|
|
|
|
|
<Divider />
|
2023-05-26 08:28:23 +02:00
|
|
|
|
2022-10-27 14:45:22 +02:00
|
|
|
<Menu.Label>
|
|
|
|
|
<Trans>Display</Trans>
|
|
|
|
|
</Menu.Label>
|
2022-08-23 13:42:28 +02:00
|
|
|
<SegmentedControl
|
|
|
|
|
fullWidth
|
|
|
|
|
orientation="vertical"
|
|
|
|
|
data={viewModeData}
|
|
|
|
|
value={viewMode}
|
2023-04-27 13:44:11 +02:00
|
|
|
onChange={e => setViewMode(e as ViewMode)}
|
2022-08-23 13:42:28 +02:00
|
|
|
mb="xs"
|
|
|
|
|
/>
|
2022-08-13 10:56:07 +02:00
|
|
|
|
|
|
|
|
{admin && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<Menu.Label>
|
|
|
|
|
<Trans>Admin</Trans>
|
|
|
|
|
</Menu.Label>
|
|
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbUsers size={iconSize} />}
|
2022-08-13 10:56:07 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(redirectToAdminUsers())
|
|
|
|
|
setOpened(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Trans>Manage users</Trans>
|
|
|
|
|
</Menu.Item>
|
2022-08-14 18:15:40 +02:00
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbChartLine size={iconSize} />}
|
2022-08-14 18:15:40 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(redirectToMetrics())
|
|
|
|
|
setOpened(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Trans>Metrics</Trans>
|
|
|
|
|
</Menu.Item>
|
2022-08-13 10:56:07 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Divider />
|
2023-05-26 08:28:23 +02:00
|
|
|
|
|
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbHeartFilled size={iconSize} color="red" />}
|
2023-05-26 08:28:23 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(redirectToDonate())
|
|
|
|
|
setOpened(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Trans>Donate</Trans>
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
|
2022-08-15 13:26:45 +02:00
|
|
|
<Menu.Item
|
2023-12-29 23:09:30 +01:00
|
|
|
leftSection={<TbHelp size={iconSize} />}
|
2022-08-15 13:26:45 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(redirectToAbout())
|
|
|
|
|
setOpened(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Trans>About</Trans>
|
|
|
|
|
</Menu.Item>
|
2023-12-29 23:09:30 +01:00
|
|
|
<Menu.Item leftSection={<TbPower size={iconSize} />} onClick={logout}>
|
2022-08-13 10:56:07 +02:00
|
|
|
<Trans>Logout</Trans>
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
</Menu.Dropdown>
|
|
|
|
|
</Menu>
|
|
|
|
|
)
|
|
|
|
|
}
|