diff --git a/.github/workflows/firebase-hosting-mege.yml b/.github/workflows/firebase-hosting-mege.yml index 0518376..ef3d093 100644 --- a/.github/workflows/firebase-hosting-mege.yml +++ b/.github/workflows/firebase-hosting-mege.yml @@ -18,3 +18,5 @@ jobs: firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LIFE_TRINKET }}' channelId: live projectId: life-trinket + - name: Set READ_ACCESS environment variable + run: echo "REPO_READ_ACCESS_TOKEN=${{ secrets.REPO_READ_ACCESS_TOKEN }}" >> $GITHUB_ENV diff --git a/package.json b/package.json index 30ad687..fcf8ec1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "life-trinket", "private": true, - "version": "0.5.0", + "version": "0.5.1", "type": "commonjs", "engines": { "node": ">=18", diff --git a/src/Components/Misc/SettingsModal.tsx b/src/Components/Misc/SettingsModal.tsx index 12150de..6f2eb71 100644 --- a/src/Components/Misc/SettingsModal.tsx +++ b/src/Components/Misc/SettingsModal.tsx @@ -4,6 +4,7 @@ import { useGlobalSettings } from '../../Hooks/useGlobalSettings'; import { ModalWrapper } from './InfoModal'; import { Separator } from './Separator'; import { Paragraph } from './TextComponents'; +import { useEffect, useRef, useState } from 'react'; const SettingContainer = twc.div`w-full flex flex-col`; @@ -20,6 +21,43 @@ type SettingsModalProps = { export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => { const { settings, setSettings, isPWA } = useGlobalSettings(); + const [isLatestVersion, setIsLatestVersion] = useState(false); + // latestVersion ref + const newVersion = useRef(undefined); + + useEffect(() => { + async function checkIfLatestVersion() { + console.log('checking latest version'); + + try { + const result = await fetch( + 'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest', + { + headers: { + Authorization: `Bearer ${process.env.REPO_READ_ACCESS_TOKEN}`, + Accept: 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28', + }, + } + ); + const data = await result.json(); + + /* @ts-expect-error is defined in vite.config.ts*/ + if (data.name === APP_VERSION) { + console.log('latestVersion true'); + + newVersion.current = data.name; + setIsLatestVersion(true); + return; + } + console.log('latestVersion false'); + setIsLatestVersion(false); + } catch (error) { + console.log('error getting latest version string', error); + } + } + checkIfLatestVersion(); + }, []); return ( @@ -98,18 +136,36 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => { )} - {/* @ts-expect-error is defined in vite.config.ts*/} - Version: {APP_VERSION} + + {/* @ts-expect-error is defined in vite.config.ts*/} + Current version: {APP_VERSION}{' '} + {isLatestVersion && ( + (latest) + )} + + {!isLatestVersion && ( + + New version ({newVersion.current}) is available!{' '} + + )} + + {!isLatestVersion && ( - + )} -