Skip to content

Commit

Permalink
Add new update notification on main dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnart committed May 12, 2022
1 parent 7493d83 commit 0c76067
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 100,
"tabWidth": 2,
"parser": "typescript",
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"endOfLine": "lf"
}
1 change: 0 additions & 1 deletion .prettierrc.js

This file was deleted.

41 changes: 37 additions & 4 deletions components/Settings/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
Text,
Tooltip,
SegmentedControl,
Indicator,
Alert,
} from '@mantine/core';
import { useColorScheme } from '@mantine/hooks';
import { useState } from 'react';
import { Settings as SettingsIcon } from 'tabler-icons-react';
import { useEffect, useState } from 'react';
import { AlertCircle, Settings as SettingsIcon } from 'tabler-icons-react';
import { CURRENT_VERSION, REPO_URL } from '../../data/constants';
import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
import SaveConfigComponent from '../Config/SaveConfig';
Expand All @@ -19,13 +22,23 @@ import ModuleEnabler from './ModuleEnabler';
function SettingsMenu(props: any) {
const { config, setConfig } = useConfig();
const colorScheme = useColorScheme();
const { current, latest } = props;
const matches = [
{ label: 'Google', value: 'https://google.com/search?q=' },
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
{ label: 'Bing', value: 'https://bing.com/search?q=' },
];

return (
<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>
<SegmentedControl
title="Search engine"
Expand Down Expand Up @@ -82,7 +95,20 @@ function SettingsMenu(props: any) {
}

export function SettingsMenuButton(props: any) {
const [update, setUpdate] = 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 (
<>
<Modal
Expand All @@ -91,7 +117,7 @@ export function SettingsMenuButton(props: any) {
opened={props.opened || opened}
onClose={() => setOpened(false)}
>
<SettingsMenu />
<SettingsMenu current={CURRENT_VERSION} latest={latestVersion} />
</Modal>
<ActionIcon
variant="default"
Expand All @@ -102,7 +128,14 @@ export function SettingsMenuButton(props: any) {
onClick={() => setOpened(true)}
>
<Tooltip label="Settings">
<SettingsIcon />
<Indicator
size={12}
disabled={CURRENT_VERSION === latestVersion}
offset={-3}
position="top-end"
>
<SettingsIcon />
</Indicator>
</Tooltip>
</ActionIcon>
</>
Expand Down
2 changes: 2 additions & 0 deletions data/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const REPO_URL = 'ajnart/myhomepage';
export const CURRENT_VERSION = 'v0.1.5';

0 comments on commit 0c76067

Please sign in to comment.