Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): announcement bar bad spelling + minor refactors #3343

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down