Skip to content

Commit 0c76067

Browse files
committed
Add new update notification on main dashboard
1 parent 7493d83 commit 0c76067

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"parser": "typescript",
5+
"singleQuote": true,
6+
"trailingComma": "es5",
7+
"useTabs": false,
8+
"endOfLine": "lf"
9+
}

.prettierrc.js

-1
This file was deleted.

components/Settings/SettingsMenu.tsx

+37-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import {
77
Text,
88
Tooltip,
99
SegmentedControl,
10+
Indicator,
11+
Alert,
1012
} from '@mantine/core';
1113
import { useColorScheme } from '@mantine/hooks';
12-
import { useState } from 'react';
13-
import { Settings as SettingsIcon } from 'tabler-icons-react';
14+
import { useEffect, useState } from 'react';
15+
import { AlertCircle, Settings as SettingsIcon } from 'tabler-icons-react';
16+
import { CURRENT_VERSION, REPO_URL } from '../../data/constants';
1417
import { useConfig } from '../../tools/state';
1518
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
1619
import SaveConfigComponent from '../Config/SaveConfig';
@@ -19,13 +22,23 @@ import ModuleEnabler from './ModuleEnabler';
1922
function SettingsMenu(props: any) {
2023
const { config, setConfig } = useConfig();
2124
const colorScheme = useColorScheme();
25+
const { current, latest } = props;
2226
const matches = [
2327
{ label: 'Google', value: 'https://google.com/search?q=' },
2428
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
2529
{ label: 'Bing', value: 'https://bing.com/search?q=' },
2630
];
31+
2732
return (
2833
<Group direction="column" grow>
34+
<Alert
35+
icon={<AlertCircle size={16} />}
36+
title="Update available"
37+
radius="lg"
38+
hidden={current === latest}
39+
>
40+
Version {latest} is available. Current : {current}
41+
</Alert>
2942
<Group>
3043
<SegmentedControl
3144
title="Search engine"
@@ -82,7 +95,20 @@ function SettingsMenu(props: any) {
8295
}
8396

8497
export function SettingsMenuButton(props: any) {
98+
const [update, setUpdate] = useState(false);
8599
const [opened, setOpened] = useState(false);
100+
const [latestVersion, setLatestVersion] = useState(CURRENT_VERSION);
101+
useEffect(() => {
102+
// Fetch Data here when component first mounted
103+
fetch(`https://api.github.com/repos/${REPO_URL}/releases/latest`).then((res) => {
104+
res.json().then((data) => {
105+
setLatestVersion(data.tag_name);
106+
if (data.tag_name !== CURRENT_VERSION) {
107+
setUpdate(true);
108+
}
109+
});
110+
});
111+
}, []);
86112
return (
87113
<>
88114
<Modal
@@ -91,7 +117,7 @@ export function SettingsMenuButton(props: any) {
91117
opened={props.opened || opened}
92118
onClose={() => setOpened(false)}
93119
>
94-
<SettingsMenu />
120+
<SettingsMenu current={CURRENT_VERSION} latest={latestVersion} />
95121
</Modal>
96122
<ActionIcon
97123
variant="default"
@@ -102,7 +128,14 @@ export function SettingsMenuButton(props: any) {
102128
onClick={() => setOpened(true)}
103129
>
104130
<Tooltip label="Settings">
105-
<SettingsIcon />
131+
<Indicator
132+
size={12}
133+
disabled={CURRENT_VERSION === latestVersion}
134+
offset={-3}
135+
position="top-end"
136+
>
137+
<SettingsIcon />
138+
</Indicator>
106139
</Tooltip>
107140
</ActionIcon>
108141
</>

data/constants.ts

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

0 commit comments

Comments
 (0)