Add new update notification on main dashboard

This commit is contained in:
Aj - Thomas
2022-05-12 02:41:13 +02:00
parent 7493d83147
commit 0c7606793a
4 changed files with 48 additions and 5 deletions

9
.prettierrc Normal file
View File

@@ -0,0 +1,9 @@
{
"printWidth": 100,
"tabWidth": 2,
"parser": "typescript",
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"endOfLine": "lf"
}

View File

@@ -1 +0,0 @@
module.exports = require('eslint-config-mantine/.prettierrc.js');

View File

@@ -7,10 +7,13 @@ import {
Text, Text,
Tooltip, Tooltip,
SegmentedControl, SegmentedControl,
Indicator,
Alert,
} from '@mantine/core'; } from '@mantine/core';
import { useColorScheme } from '@mantine/hooks'; import { useColorScheme } from '@mantine/hooks';
import { useState } from 'react'; import { useEffect, useState } from 'react';
import { Settings as SettingsIcon } from 'tabler-icons-react'; import { AlertCircle, Settings as SettingsIcon } from 'tabler-icons-react';
import { CURRENT_VERSION, REPO_URL } from '../../data/constants';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch'; import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
import SaveConfigComponent from '../Config/SaveConfig'; import SaveConfigComponent from '../Config/SaveConfig';
@@ -19,13 +22,23 @@ import ModuleEnabler from './ModuleEnabler';
function SettingsMenu(props: any) { function SettingsMenu(props: any) {
const { config, setConfig } = useConfig(); const { config, setConfig } = useConfig();
const colorScheme = useColorScheme(); const colorScheme = useColorScheme();
const { current, latest } = props;
const matches = [ const matches = [
{ label: 'Google', value: 'https://google.com/search?q=' }, { label: 'Google', value: 'https://google.com/search?q=' },
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' }, { label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
{ label: 'Bing', value: 'https://bing.com/search?q=' }, { label: 'Bing', value: 'https://bing.com/search?q=' },
]; ];
return ( return (
<Group direction="column" grow> <Group direction="column" grow>
<Alert
icon={<AlertCircle size={16} />}
title="Update available"
radius="lg"
hidden={current === latest}
>
Version {latest} is available. Current : {current}
</Alert>
<Group> <Group>
<SegmentedControl <SegmentedControl
title="Search engine" title="Search engine"
@@ -82,7 +95,20 @@ function SettingsMenu(props: any) {
} }
export function SettingsMenuButton(props: any) { export function SettingsMenuButton(props: any) {
const [update, setUpdate] = useState(false);
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
const [latestVersion, setLatestVersion] = useState(CURRENT_VERSION);
useEffect(() => {
// Fetch Data here when component first mounted
fetch(`https://api.github.com/repos/${REPO_URL}/releases/latest`).then((res) => {
res.json().then((data) => {
setLatestVersion(data.tag_name);
if (data.tag_name !== CURRENT_VERSION) {
setUpdate(true);
}
});
});
}, []);
return ( return (
<> <>
<Modal <Modal
@@ -91,7 +117,7 @@ export function SettingsMenuButton(props: any) {
opened={props.opened || opened} opened={props.opened || opened}
onClose={() => setOpened(false)} onClose={() => setOpened(false)}
> >
<SettingsMenu /> <SettingsMenu current={CURRENT_VERSION} latest={latestVersion} />
</Modal> </Modal>
<ActionIcon <ActionIcon
variant="default" variant="default"
@@ -102,7 +128,14 @@ export function SettingsMenuButton(props: any) {
onClick={() => setOpened(true)} onClick={() => setOpened(true)}
> >
<Tooltip label="Settings"> <Tooltip label="Settings">
<SettingsIcon /> <Indicator
size={12}
disabled={CURRENT_VERSION === latestVersion}
offset={-3}
position="top-end"
>
<SettingsIcon />
</Indicator>
</Tooltip> </Tooltip>
</ActionIcon> </ActionIcon>
</> </>

2
data/constants.ts Normal file
View File

@@ -0,0 +1,2 @@
export const REPO_URL = 'ajnart/myhomepage';
export const CURRENT_VERSION = 'v0.1.5';