|
|
@@ -68,28 +68,28 @@ export const useIsMobile = (): SWRResponse<boolean, Error> => {
|
|
|
return useStaticSWR<boolean, Error>(key, undefined, configuration);
|
|
|
};
|
|
|
|
|
|
-const updateBodyClassesByEditorMode = (newEditorMode: EditorMode) => {
|
|
|
+const updateBodyClassesByEditorMode = (newEditorMode: EditorMode, isSidebar = false) => {
|
|
|
switch (newEditorMode) {
|
|
|
case EditorMode.View:
|
|
|
$('body').removeClass('on-edit');
|
|
|
$('body').removeClass('builtin-editor');
|
|
|
$('body').removeClass('hackmd');
|
|
|
- $('body').removeClass('pathname-sidebar');
|
|
|
+ $('body').removeClass('editing-sidebar');
|
|
|
break;
|
|
|
case EditorMode.Editor:
|
|
|
$('body').addClass('on-edit');
|
|
|
$('body').addClass('builtin-editor');
|
|
|
$('body').removeClass('hackmd');
|
|
|
// editing /Sidebar
|
|
|
- if (window.location.pathname === '/Sidebar') {
|
|
|
- $('body').addClass('pathname-sidebar');
|
|
|
+ if (isSidebar) {
|
|
|
+ $('body').addClass('editing-sidebar');
|
|
|
}
|
|
|
break;
|
|
|
case EditorMode.HackMD:
|
|
|
$('body').addClass('on-edit');
|
|
|
$('body').addClass('hackmd');
|
|
|
$('body').removeClass('builtin-editor');
|
|
|
- $('body').removeClass('pathname-sidebar');
|
|
|
+ $('body').removeClass('editing-sidebar');
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
@@ -133,6 +133,9 @@ export const useEditorMode = (): SWRResponse<EditorMode, Error> => {
|
|
|
const isEditable = !isLoading && _isEditable;
|
|
|
const initialData = isEditable ? editorModeByHash : EditorMode.View;
|
|
|
|
|
|
+ const { data: currentPagePath } = useCurrentPagePath();
|
|
|
+ const isSidebar = currentPagePath === '/Sidebar';
|
|
|
+
|
|
|
const swrResponse = useSWRImmutable(
|
|
|
isLoading ? null : ['editorMode', isEditable],
|
|
|
null,
|
|
|
@@ -142,7 +145,7 @@ export const useEditorMode = (): SWRResponse<EditorMode, Error> => {
|
|
|
// initial updating
|
|
|
if (!isEditorModeLoaded && !isLoading && swrResponse.data != null) {
|
|
|
if (isEditable) {
|
|
|
- updateBodyClassesByEditorMode(swrResponse.data);
|
|
|
+ updateBodyClassesByEditorMode(swrResponse.data, isSidebar);
|
|
|
}
|
|
|
isEditorModeLoaded = true;
|
|
|
}
|
|
|
@@ -155,7 +158,7 @@ export const useEditorMode = (): SWRResponse<EditorMode, Error> => {
|
|
|
if (!isEditable) {
|
|
|
return Promise.resolve(EditorMode.View); // fixed if not editable
|
|
|
}
|
|
|
- updateBodyClassesByEditorMode(editorMode);
|
|
|
+ updateBodyClassesByEditorMode(editorMode, isSidebar);
|
|
|
updateHashByEditorMode(editorMode);
|
|
|
return swrResponse.mutate(editorMode, shouldRevalidate);
|
|
|
},
|