Files
Homarr/src/components/layout/header/Header.tsx

58 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Box, createStyles, Group, Header as MantineHeader, Indicator } from '@mantine/core';
2022-12-23 17:44:51 +01:00
import { useEffect, useState } from 'react';
import { CURRENT_VERSION, REPO_URL } from '../../../../data/constants';
2022-12-10 15:00:16 +01:00
import { useConfigContext } from '../../../config/provider';
import { Logo } from '../Logo';
2022-12-04 17:36:30 +01:00
import { useCardStyles } from '../useCardStyles';
2023-01-06 12:11:47 +09:00
import DockerMenuButton from '../../../modules/Docker/DockerModule';
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();
2022-12-30 17:58:12 +01:00
const { classes: cardClasses } = useCardStyles(false);
2022-04-25 00:11:32 +02:00
2022-12-10 15:00:16 +01:00
const { config } = useConfigContext();
const [newVersionAvailable, setNewVersionAvailable] = useState<string>('');
useEffect(() => {
// Fetch Data here when component first mounted
fetch(`https://api.github.com/repos/${REPO_URL}/releases/latest`).then((res) => {
res.json().then((data) => {
if (data.tag_name > CURRENT_VERSION) {
setNewVersionAvailable(data.tag_name);
}
});
});
}, [CURRENT_VERSION]);
2022-04-25 00:11:32 +02:00
return (
<MantineHeader height="auto" className={cardClasses.card}>
2022-11-29 20:30:53 +09:00
<Group p="xs" noWrap grow>
2022-12-04 17:36:30 +01:00
<Box className={classes.hide}>
<Logo />
</Box>
<Group position="right" style={{ maxWidth: 'none' }} noWrap>
2022-12-10 17:58:01 +01:00
<Search />
<ToggleEditModeAction />
2022-12-23 17:44:51 +01:00
<DockerMenuButton />
<Indicator size={15} color="blue" withBorder processing disabled={!newVersionAvailable}>
<SettingsMenu newVersionAvailable={newVersionAvailable} />
</Indicator>
2022-05-04 07:12:22 +02:00
</Group>
</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',
},
},
}));