2022-12-20 15:21:36 +09:00
|
|
|
import { Box, createStyles, Group, Header as MantineHeader, Indicator } from '@mantine/core';
|
2023-02-02 19:14:17 +09:00
|
|
|
import { useQuery } from '@tanstack/react-query';
|
2023-01-31 21:17:37 +01:00
|
|
|
import { REPO_URL } from '../../../../data/constants';
|
2023-02-22 21:59:49 +01:00
|
|
|
import { useEditModeInformationStore } from '../../../hooks/useEditModeInformation';
|
2023-01-31 21:17:37 +01:00
|
|
|
import DockerMenuButton from '../../../modules/Docker/DockerModule';
|
|
|
|
|
import { usePackageAttributesStore } from '../../../tools/client/zustands/usePackageAttributesStore';
|
2022-10-10 20:46:22 +02:00
|
|
|
import { Logo } from '../Logo';
|
2022-12-04 17:36:30 +01:00
|
|
|
import { useCardStyles } from '../useCardStyles';
|
2022-12-10 17:58:01 +01:00
|
|
|
import { ToggleEditModeAction } from './Actions/ToggleEditMode/ToggleEditMode';
|
2022-12-06 21:33:12 +01:00
|
|
|
import { Search } from './Search';
|
|
|
|
|
import { SettingsMenu } from './SettingsMenu';
|
2022-12-04 17:36:30 +01:00
|
|
|
|
|
|
|
|
export const HeaderHeight = 64;
|
2022-04-25 00:11:32 +02:00
|
|
|
|
2022-05-16 13:54:08 +02:00
|
|
|
export function Header(props: any) {
|
2022-12-04 17:36:30 +01:00
|
|
|
const { classes } = useStyles();
|
2023-02-10 23:37:08 +01:00
|
|
|
const { classes: cardClasses, cx } = useCardStyles(false);
|
2023-01-31 21:17:37 +01:00
|
|
|
const { attributes } = usePackageAttributesStore();
|
2023-02-22 21:59:49 +01:00
|
|
|
const { editModeEnabled } = useEditModeInformationStore();
|
2022-12-10 15:00:16 +01:00
|
|
|
|
2023-02-22 21:59:49 +01:00
|
|
|
const { data } = useQuery({
|
2023-01-31 11:45:52 +09:00
|
|
|
queryKey: ['github/latest'],
|
|
|
|
|
cacheTime: 1000 * 60 * 60 * 24,
|
|
|
|
|
staleTime: 1000 * 60 * 60 * 5,
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
fetch(`https://api.github.com/repos/${REPO_URL}/releases/latest`).then((res) => res.json()),
|
|
|
|
|
});
|
2023-02-02 18:59:09 +09:00
|
|
|
const newVersionAvailable =
|
|
|
|
|
data?.tag_name > `v${attributes.packageVersion}` ? data?.tag_name : undefined;
|
2022-12-20 15:21:36 +09:00
|
|
|
|
2022-04-25 00:11:32 +02:00
|
|
|
return (
|
2023-02-10 23:37:08 +01:00
|
|
|
<MantineHeader height="auto" className={cx(cardClasses.card, 'dashboard-header')}>
|
2022-11-29 20:30:53 +09:00
|
|
|
<Group p="xs" noWrap grow>
|
2023-02-10 23:37:08 +01:00
|
|
|
<Box className={cx(classes.hide, 'dashboard-header-logo-root')}>
|
2022-12-04 17:36:30 +01:00
|
|
|
<Logo />
|
|
|
|
|
</Box>
|
2023-02-22 21:59:49 +01:00
|
|
|
<Group
|
|
|
|
|
className="dashboard-header-group-right"
|
|
|
|
|
position="right"
|
|
|
|
|
style={{ maxWidth: 'none' }}
|
|
|
|
|
noWrap
|
|
|
|
|
>
|
2022-12-10 17:58:01 +01:00
|
|
|
<Search />
|
2023-02-22 21:59:49 +01:00
|
|
|
{!editModeEnabled && <ToggleEditModeAction />}
|
2023-03-21 11:40:33 +08:00
|
|
|
{!editModeEnabled && <DockerMenuButton />}
|
2023-01-31 11:45:52 +09:00
|
|
|
<Indicator
|
|
|
|
|
size={15}
|
|
|
|
|
color="blue"
|
|
|
|
|
withBorder
|
|
|
|
|
processing
|
|
|
|
|
disabled={newVersionAvailable === undefined}
|
|
|
|
|
>
|
2022-12-20 15:21:36 +09:00
|
|
|
<SettingsMenu newVersionAvailable={newVersionAvailable} />
|
|
|
|
|
</Indicator>
|
2022-05-04 07:12:22 +02:00
|
|
|
</Group>
|
2022-05-14 21:41:30 +02:00
|
|
|
</Group>
|
2022-12-04 17:36:30 +01:00
|
|
|
</MantineHeader>
|
2022-04-25 00:11:32 +02:00
|
|
|
);
|
|
|
|
|
}
|
2022-12-04 17:36:30 +01:00
|
|
|
|
|
|
|
|
const useStyles = createStyles((theme) => ({
|
|
|
|
|
hide: {
|
|
|
|
|
[theme.fn.smallerThan('xs')]: {
|
|
|
|
|
display: 'none',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}));
|