-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 chore: modify the latest notice shown logic
- Loading branch information
Showing
1 changed file
with
38 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |