Skip to content

Commit

Permalink
refactor: Nit on hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Apr 18, 2024
1 parent 6027d1b commit 2e5c81f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/content-tags-drawer/ContentTagsDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ContentTagsDrawer = ({ id, onClose }) => {
toEditMode,
toastMessage,
closeToast,
setCollapsibleToInitalState,
} = context;

let onCloseDrawer = onClose;
Expand Down Expand Up @@ -81,6 +82,11 @@ const ContentTagsDrawer = ({ id, onClose }) => {
}
}, [commitGlobalStagedTagsStatus]);

// First call of the initial collapsible states
React.useEffect(() => {
setCollapsibleToInitalState();
}, [isTaxonomyListLoaded, isContentTaxonomyTagsLoaded]);

return (
<ContentTagsDrawerContext.Provider value={context}>
<div id="content-tags-drawer" className="mt-1 tags-drawer d-flex flex-column justify-content-between min-vh-100">
Expand Down
7 changes: 2 additions & 5 deletions src/content-tags-drawer/ContentTagsDrawerHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import messages from './messages';
* toastMessage: string | undefined,
* showToastAfterSave: () => void,
* closeToast: () => void,
* setCollapsibleToInitalState: () => void,
* }}
*/
const useContentTagsDrawerContext = (contentId) => {
Expand Down Expand Up @@ -335,11 +336,6 @@ const useContentTagsDrawerContext = (contentId) => {
updateTags.mutate({ tagsData });
}, [tagsByTaxonomy]);

// First call of the initial collapsible states
React.useEffect(() => {
setCollapsibleToInitalState();
}, [isTaxonomyListLoaded, isContentTaxonomyTagsLoaded]);

return {
stagedContentTags,
addStagedContentTag,
Expand Down Expand Up @@ -367,6 +363,7 @@ const useContentTagsDrawerContext = (contentId) => {
toastMessage,
showToastAfterSave,
closeToast,
setCollapsibleToInitalState,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/content-tags-drawer/common/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export const ContentTagsDrawerContext = React.createContext({
toastMessage: /** @type{string|undefined} */ (undefined),
showToastAfterSave: /** @type{() => void} */ (() => {}),
closeToast: /** @type{() => void} */ (() => {}),
setCollapsibleToInitalState: /** @type{() => void} */ (() => {}),
});

0 comments on commit 2e5c81f

Please sign in to comment.