feat(sidebar): implement home visibility toggle with hide/unhide functionality
This commit is contained in:
@@ -18,6 +18,7 @@ export type InCinnySpacesContent = {
|
||||
shortcut?: string[];
|
||||
sidebar?: SidebarItems;
|
||||
hidden?: string[];
|
||||
hideHome?: boolean;
|
||||
};
|
||||
|
||||
export const parseSidebar = (
|
||||
@@ -238,3 +239,67 @@ export const makeUnhideSpaceContent = (
|
||||
hidden: currentHidden.filter((id) => id !== spaceId),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Create content for hiding home
|
||||
*/
|
||||
export const makeHideHomeContent = (mx: MatrixClient): InCinnySpacesContent => {
|
||||
const currentContent =
|
||||
getAccountData(mx, AccountDataEvent.CinnySpaces)?.getContent<InCinnySpacesContent>() ?? {};
|
||||
|
||||
return {
|
||||
...currentContent,
|
||||
hideHome: true,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Create content for unhiding home
|
||||
*/
|
||||
export const makeUnhideHomeContent = (mx: MatrixClient): InCinnySpacesContent => {
|
||||
const currentContent =
|
||||
getAccountData(mx, AccountDataEvent.CinnySpaces)?.getContent<InCinnySpacesContent>() ?? {};
|
||||
|
||||
return {
|
||||
...currentContent,
|
||||
hideHome: false,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook to get and manage home hidden state
|
||||
*/
|
||||
export const useHomeHidden = (): [boolean, Dispatch<SetStateAction<boolean>>] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const [homeHidden, setHomeHidden] = useState(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
return content?.hideHome ?? false;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const content = getAccountData(
|
||||
mx,
|
||||
AccountDataEvent.CinnySpaces
|
||||
)?.getContent<InCinnySpacesContent>();
|
||||
setHomeHidden(content?.hideHome ?? false);
|
||||
}, [mx]);
|
||||
|
||||
useAccountDataCallback(
|
||||
mx,
|
||||
useCallback(
|
||||
(mEvent) => {
|
||||
if (mEvent.getType() === AccountDataEvent.CinnySpaces) {
|
||||
const newContent = mEvent.getContent<InCinnySpacesContent>();
|
||||
setHomeHidden(newContent?.hideHome ?? false);
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
);
|
||||
|
||||
return [homeHidden, setHomeHidden];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user