Skip to content

Commit

Permalink
feat(web): add check new version
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Mar 3, 2024
1 parent e655bca commit 7590d30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
50 changes: 43 additions & 7 deletions apps/web/src/components/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Badge,
Image,
Link,
Navbar,
Expand All @@ -11,6 +12,7 @@ import { ThemeSwitcher } from './ThemeSwitcher';
import { GitHubIcon } from './GitHubIcon';
import { useLocation } from 'react-router-dom';
import { appVersion } from '@web/utils/env';
import { useEffect, useState } from 'react';

const navbarItemLink = [
{
Expand All @@ -29,18 +31,52 @@ const navbarItemLink = [

const Nav = () => {
const { pathname } = useLocation();
const [releaseVersion, setReleaseVersion] = useState(appVersion);

useEffect(() => {
fetch('https://api.github.com/repos/cooderl/wewe-rss/releases/latest')
.then((res) => res.json())
.then((data) => {
setReleaseVersion(data.name.replace('v', ''));
});
}, []);

const isFoundNewVersion = releaseVersion > appVersion;
console.log('isFoundNewVersion: ', isFoundNewVersion);

return (
<div>
<Navbar isBordered>
<Tooltip content={`当前版本: v${appVersion}`} placement="left">
<Tooltip
content={
<div className="p-1">
{isFoundNewVersion && (
<Link
href={`https://github.com/cooderl/wewe-rss/releases/latest`}
target="_blank"
className="mb-1 block text-medium"
>
发现新版本:v{releaseVersion}
</Link>
)}
当前版本: v{appVersion}
</div>
}
placement="left"
>
<NavbarBrand className="cursor-default">
<Image
width={28}
alt="WeWe RSS"
className="mr-2"
src="https://r2-assets.111965.xyz/wewe-rss.png"
></Image>
<Badge
content={isFoundNewVersion ? '' : null}
color="danger"
size="sm"
>
<Image
width={28}
alt="WeWe RSS"
className="mr-2"
src="https://r2-assets.111965.xyz/wewe-rss.png"
></Image>
</Badge>
<p className="font-bold text-inherit">WeWe RSS</p>
</NavbarBrand>
</Tooltip>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const isProd = process.env.NODE_ENV === 'production';
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV);

const packageJson = JSON.parse(
readFileSync(resolve(__dirname, '..', '..', './package.json'), 'utf-8'),
readFileSync(resolve(__dirname, './package.json'), 'utf-8'),
);

// https://vitejs.dev/config/
Expand Down

0 comments on commit 7590d30

Please sign in to comment.