mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added announcement close button state storage to sessionStorage (#16683)
refs TryGhost/Team#3071
This commit is contained in:
parent
0addb5543f
commit
a282857379
1 changed files with 16 additions and 2 deletions
|
@ -4,7 +4,12 @@ import './AnnouncementBar.css';
|
|||
import {ReactComponent as CloseIcon} from '../icons/clear.svg';
|
||||
|
||||
export function AnnouncementBar({settings}) {
|
||||
const [visible, setVisible] = React.useState(true);
|
||||
const [visible, setVisible] = React.useState(isBarVisible());
|
||||
|
||||
const handleButtonClick = () => {
|
||||
setBarVisibility();
|
||||
setVisible(false);
|
||||
};
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
|
@ -18,9 +23,18 @@ export function AnnouncementBar({settings}) {
|
|||
return (
|
||||
<div className={className}>
|
||||
<div className="gh-announcement-bar-content" dangerouslySetInnerHTML={{__html: settings?.announcement}}></div>
|
||||
<button onClick={() => setVisible(false)}>
|
||||
<button onClick={handleButtonClick}>
|
||||
<CloseIcon />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const BAR_STORAGE_KEY = 'isAnnouncementBarVisible';
|
||||
function setBarVisibility(state = 'true') {
|
||||
sessionStorage.setItem(BAR_STORAGE_KEY, state);
|
||||
}
|
||||
|
||||
function isBarVisible() {
|
||||
return !sessionStorage.getItem(BAR_STORAGE_KEY);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue