diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx index f868cd5ce9..b5e2b7e936 100644 --- a/web/apps/photos/src/components/Sidebar.tsx +++ b/web/apps/photos/src/components/Sidebar.tsx @@ -129,6 +129,12 @@ import { testUpload } from "../../tests/upload.test"; import { SubscriptionCard } from "./SubscriptionCard"; type SidebarProps = ModalVisibilityProps & { + /** + * The latest UI collections. + * + * These are used to obtain data about the uncategorized, hidden and other + * items shown in the shortcut section within the sidebar. + */ collectionSummaries: CollectionSummaries; }; @@ -138,15 +144,15 @@ export const Sidebar: React.FC = ({ collectionSummaries, }) => ( - - + + - - + + @@ -160,31 +166,29 @@ const RootSidebarDrawer = styled(SidebarDrawer)(({ theme }) => ({ }, })); -interface HeaderSectionProps { - closeSidebar: () => void; +interface SectionProps { + onCloseSidebar: SidebarProps["onClose"]; } -const HeaderSection: React.FC = ({ closeSidebar }) => { - return ( - - - - - - - ); -}; +const HeaderSection: React.FC = ({ onCloseSidebar }) => ( + + + + + + +); interface UserDetailsSectionProps { - sidebarView: boolean; + sidebarOpen: boolean; } const UserDetailsSection: React.FC = ({ - sidebarView, + sidebarOpen, }) => { const galleryContext = useContext(GalleryContext); const userDetails = useUserDetailsSnapshot(); @@ -197,8 +201,8 @@ const UserDetailsSection: React.FC = ({ setMemberSubscriptionManageView(false); useEffect(() => { - if (sidebarView) void syncUserDetails(); - }, [sidebarView]); + if (sidebarOpen) void syncUserDetails(); + }, [sidebarOpen]); const isNonAdminFamilyMember = useMemo( () => @@ -417,13 +421,12 @@ function MemberSubscriptionManage({ open, userDetails, onClose }) { ); } -interface ShortcutSectionProps { - closeSidebar: () => void; - collectionSummaries: CollectionSummaries; -} +type ShortcutSectionProps = SectionProps & { + collectionSummaries: SidebarProps["collectionSummaries"]; +}; const ShortcutSection: React.FC = ({ - closeSidebar, + onCloseSidebar, collectionSummaries, }) => { const galleryContext = useContext(GalleryContext); @@ -431,35 +434,31 @@ const ShortcutSection: React.FC = ({ useState(); useEffect(() => { - const main = async () => { - const unCategorizedCollection = await getUncategorizedCollection(); - if (unCategorizedCollection) { - setUncategorizedCollectionID(unCategorizedCollection.id); - } else { - setUncategorizedCollectionID(DUMMY_UNCATEGORIZED_COLLECTION); - } - }; - main(); + void getUncategorizedCollection().then((uncat) => + setUncategorizedCollectionID( + uncat?.id ?? DUMMY_UNCATEGORIZED_COLLECTION, + ), + ); }, []); const openUncategorizedSection = () => { galleryContext.setActiveCollectionID(uncategorizedCollectionId); - closeSidebar(); + onCloseSidebar(); }; const openTrashSection = () => { galleryContext.setActiveCollectionID(TRASH_SECTION); - closeSidebar(); + onCloseSidebar(); }; const openArchiveSection = () => { galleryContext.setActiveCollectionID(ARCHIVE_SECTION); - closeSidebar(); + onCloseSidebar(); }; const openHiddenSection = () => { galleryContext.openHiddenSection(() => { - closeSidebar(); + onCloseSidebar(); }); }; @@ -506,12 +505,11 @@ const ShortcutSection: React.FC = ({ ); }; -const UtilitySection: React.FC> = ({ - closeSidebar, -}) => { - const router = useRouter(); +const UtilitySection: React.FC = ({ onCloseSidebar }) => { const { watchFolderView, setWatchFolderView } = usePhotosAppContext(); + const router = useRouter(); + const { show: showAccount, props: accountVisibilityProps } = useModalVisibility(); const { show: showPreferences, props: preferencesVisibilityProps } = @@ -552,18 +550,16 @@ const UtilitySection: React.FC> = ({ onClose={handleCloseWatchFolder} /> )} - + ); }; -const HelpSection: React.FC> = ({ - closeSidebar, -}) => { +const HelpSection: React.FC = ({ onCloseSidebar }) => { const { showMiniDialog } = useBaseContext(); const { openExportModal } = useContext(GalleryContext); @@ -591,7 +587,7 @@ const HelpSection: React.FC> = ({ } onClick={handleExport} /> - + ); }; diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 2f691ddef7..7d82d4c04f 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -208,11 +208,6 @@ const Page: React.FC = () => { const [uploadTypeSelectorIntent, setUploadTypeSelectorIntent] = useState("upload"); - const [sidebarView, setSidebarView] = useState(false); - - const closeSidebar = () => setSidebarView(false); - const openSidebar = () => setSidebarView(true); - const [authenticateUserModalView, setAuthenticateUserModalView] = useState(false); @@ -249,6 +244,8 @@ const Page: React.FC = () => { const [collectionSelectorAttributes, setCollectionSelectorAttributes] = useState(); + const { show: showSidebar, props: sidebarVisibilityProps } = + useModalVisibility(); const { show: showPlanSelector, props: planSelectorVisibilityProps } = useModalVisibility(); const { show: showWhatsNew, props: whatsNewVisibilityProps } = @@ -447,10 +444,10 @@ const Page: React.FC = () => { } // if any of the modals are open, don't select all if ( - sidebarView || uploadTypeSelectorView || openCollectionSelector || collectionNamerView || + sidebarVisibilityProps.open || planSelectorVisibilityProps.open || fixCreationTimeVisibilityProps.open || exportVisibilityProps.open || @@ -927,21 +924,19 @@ const Page: React.FC = () => { /> ) : ( - dispatch({ type: "enterSearchMode" }), - onSelectSearchOption: handleSelectSearchOption, - onSelectPeople: () => - dispatch({ type: "showPeople" }), - onSelectPerson: (personID) => - dispatch({ - type: "showPerson", - personID, - }), - }} + {...{ isInSearchMode }} + onSidebar={showSidebar} + onUpload={openUploader} + onShowSearchInput={() => + dispatch({ type: "enterSearchMode" }) + } + onSelectSearchOption={handleSelectSearchOption} + onSelectPeople={() => + dispatch({ type: "showPeople" }) + } + onSelectPerson={(personID) => + dispatch({ type: "showPerson", personID }) + } /> )} @@ -1002,9 +997,8 @@ const Page: React.FC = () => { }} /> {!isInSearchMode && @@ -1099,19 +1093,25 @@ const preloadImage = (imgBasePath: string) => { }; type NormalNavbarContentsProps = SearchBarProps & { - openSidebar: () => void; - openUploader: () => void; + /** + * Called when the user activates the sidebar icon. + */ + onSidebar: () => void; + /** + * Called when the user activates the upload button. + */ + onUpload: () => void; }; const NormalNavbarContents: React.FC = ({ - openSidebar, - openUploader, + onSidebar, + onUpload, ...props }) => ( <> - {!props.isInSearchMode && } + {!props.isInSearchMode && } - {!props.isInSearchMode && } + {!props.isInSearchMode && } );