Skip to content

Commit

Permalink
🔧 chore: modify the latest notice shown logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RylanBot committed Jun 26, 2024
1 parent 72d6074 commit 5d4b569
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions src/components/toolkit/LatestNotice.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import { useEffect, useState } from 'react';
import { IoIosCloseCircleOutline } from 'react-icons/io';
import { useEffect, useState } from "react";
import { IoIosCloseCircleOutline } from "react-icons/io";

import useLocale from '@/hooks/useLocale';
import useLocale from "@/hooks/useLocale";

import { version } from "@/../package.json";

const LatestNotice = () => {
const { locale } = useLocale();
const [showNotice, setShowNotice] = useState(true);
const { locale } = useLocale();
const [showNotice, setShowNotice] = useState(false);

useEffect(() => {
const hasRead = localStorage.getItem('notice-read');
if (hasRead === 'true') {
setShowNotice(false);
}
}, []);
useEffect(() => {
const lastSeenVersion = localStorage.getItem("notice-version");
if (lastSeenVersion !== version) {
setShowNotice(true);
}
}, []);

const handleClose = () => {
localStorage.setItem('notice-read', 'true');
setShowNotice(false);
};
const handleClose = () => {
localStorage.setItem("notice-version", version);
setShowNotice(false);
};

return (
<>
{showNotice && (
<div className='fixed top-72 right-12 bg-slate-500 text-white w-40 p-4 rounded-lg shadow-md'>
<div className='flex justify-center items-center mb-4'>
<p className='font-bold text-lg font-serif italic'>Notice</p>
<button
className='ml-auto'
onClick={handleClose}
>
<IoIosCloseCircleOutline />
</button>
</div>
<p>{locale.common.LATEST_NOTICE}</p>
</div>
)}
</>
);
return (
<>
{showNotice && (
<div className="fixed top-72 right-12 bg-slate-500 text-white w-40 p-4 rounded-lg shadow-md">
<div className="flex justify-center items-center mb-4">
<p className="font-bold text-lg font-serif italic">Notice</p>
<button className="ml-auto" onClick={handleClose}>
<IoIosCloseCircleOutline />
</button>
</div>
<p>
{locale.common.LATEST_NOTICE}
<span className="text-sky-200 font-bold text-sm italic">
- v{version}
</span>
</p>
</div>
)}
</>
);
};

export default LatestNotice;
export default LatestNotice;

0 comments on commit 5d4b569

Please sign in to comment.