mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-24 06:27:02 +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.
|
* 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';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
||||||
const STORAGE_DISMISS_KEY = 'docusaurus.announcement.dismiss';
|
const STORAGE_DISMISS_KEY = 'docusaurus.announcement.dismiss';
|
||||||
|
@ -15,23 +15,29 @@ const useAnnouncementBar = (): {
|
||||||
isAnnouncementBarClosed: boolean;
|
isAnnouncementBarClosed: boolean;
|
||||||
closeAnnouncementBar: () => void;
|
closeAnnouncementBar: () => void;
|
||||||
} => {
|
} => {
|
||||||
const {
|
const {announcementBar} = useDocusaurusContext().siteConfig.themeConfig;
|
||||||
siteConfig: {
|
|
||||||
themeConfig: {announcementBar: {id = 'annoucement-bar'} = {}} = {},
|
|
||||||
} = {},
|
|
||||||
} = useDocusaurusContext();
|
|
||||||
const [isClosed, setClosed] = useState(true);
|
const [isClosed, setClosed] = useState(true);
|
||||||
const handleClose = () => {
|
|
||||||
|
const handleClose = useCallback(() => {
|
||||||
localStorage.setItem(STORAGE_DISMISS_KEY, 'true');
|
localStorage.setItem(STORAGE_DISMISS_KEY, 'true');
|
||||||
setClosed(true);
|
setClosed(true);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) {
|
if (!announcementBar) {
|
||||||
return;
|
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;
|
const isNewAnnouncement = id !== viewedId;
|
||||||
|
|
||||||
localStorage.setItem(STORAGE_ID_KEY, id);
|
localStorage.setItem(STORAGE_ID_KEY, id);
|
||||||
|
|
|
@ -166,7 +166,7 @@ const ThemeConfigSchema = Joi.object({
|
||||||
colorMode: ColorModeSchema,
|
colorMode: ColorModeSchema,
|
||||||
image: Joi.string(),
|
image: Joi.string(),
|
||||||
announcementBar: Joi.object({
|
announcementBar: Joi.object({
|
||||||
id: Joi.string(),
|
id: Joi.string().default('announcement-bar'),
|
||||||
content: Joi.string(),
|
content: Joi.string(),
|
||||||
backgroundColor: Joi.string().default('#fff'),
|
backgroundColor: Joi.string().default('#fff'),
|
||||||
textColor: Joi.string().default('#000'),
|
textColor: Joi.string().default('#000'),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue