mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +02:00
refactor(v2): announcement bar bad spelling + minor refactors (#3343)
This commit is contained in:
parent
3ccca399f1
commit
b86806460c
2 changed files with 17 additions and 11 deletions
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {useState, useEffect} from 'react';
|
||||
import {useState, useEffect, useCallback} from 'react';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
const STORAGE_DISMISS_KEY = 'docusaurus.announcement.dismiss';
|
||||
|
@ -15,23 +15,29 @@ const useAnnouncementBar = (): {
|
|||
isAnnouncementBarClosed: boolean;
|
||||
closeAnnouncementBar: () => void;
|
||||
} => {
|
||||
const {
|
||||
siteConfig: {
|
||||
themeConfig: {announcementBar: {id = 'annoucement-bar'} = {}} = {},
|
||||
} = {},
|
||||
} = useDocusaurusContext();
|
||||
const {announcementBar} = useDocusaurusContext().siteConfig.themeConfig;
|
||||
|
||||
const [isClosed, setClosed] = useState(true);
|
||||
const handleClose = () => {
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
localStorage.setItem(STORAGE_DISMISS_KEY, 'true');
|
||||
setClosed(true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
if (!announcementBar) {
|
||||
return;
|
||||
}
|
||||
const {id} = announcementBar;
|
||||
|
||||
let viewedId = localStorage.getItem(STORAGE_ID_KEY);
|
||||
|
||||
// retrocompatibility due to spelling mistake of default id
|
||||
// see https://github.com/facebook/docusaurus/issues/3338
|
||||
if (viewedId === 'annoucement-bar') {
|
||||
viewedId = 'announcement-bar';
|
||||
}
|
||||
|
||||
const viewedId = localStorage.getItem(STORAGE_ID_KEY);
|
||||
const isNewAnnouncement = id !== viewedId;
|
||||
|
||||
localStorage.setItem(STORAGE_ID_KEY, id);
|
||||
|
|
|
@ -166,7 +166,7 @@ const ThemeConfigSchema = Joi.object({
|
|||
colorMode: ColorModeSchema,
|
||||
image: Joi.string(),
|
||||
announcementBar: Joi.object({
|
||||
id: Joi.string(),
|
||||
id: Joi.string().default('announcement-bar'),
|
||||
content: Joi.string(),
|
||||
backgroundColor: Joi.string().default('#fff'),
|
||||
textColor: Joi.string().default('#000'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue