feat: 更新依赖版本,添加PWA更新组件,优化Sidebar组件,增加footer支持

This commit is contained in:
xiongxiao
2026-03-22 13:54:30 +08:00
committed by cnb
parent 518a3f2864
commit dd100fd7ef
9 changed files with 175 additions and 37 deletions

View File

@@ -0,0 +1,60 @@
import { useState } from 'react';
import { useRegisterSW } from 'virtual:pwa-register/react';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card';
function PWAUpdate() {
const {
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onNeedRefresh() {
setNeedRefresh(true);
},
});
const [isLoading, setIsLoading] = useState(false);
const handleUpdate = async () => {
setIsLoading(true);
await updateServiceWorker(true);
setIsLoading(false);
};
const handleDismiss = () => {
setNeedRefresh(false);
};
if (!needRefresh) {
return null;
}
return (
<div className="fixed bottom-4 right-4 z-50">
<Card className="w-80 shadow-lg">
<CardHeader className="pb-3">
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="pt-0" />
<CardFooter className="gap-2">
<Button variant="outline" size="sm" onClick={handleDismiss}>
</Button>
<Button size="sm" onClick={handleUpdate} disabled={isLoading}>
{isLoading ? '更新中...' : '立即更新'}
</Button>
</CardFooter>
</Card>
</div>
);
}
export default PWAUpdate;