π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Navigation
vishnukvmd0f78f288ae7e
diff --git a/web/apps/locker/src/components/ItemList.tsx b/web/apps/locker/src/components/ItemList.tsxindex d0d82b3814..12ddab2c75 100644--- a/web/apps/locker/src/components/ItemList.tsx+++ b/web/apps/locker/src/components/ItemList.tsx@@ -1,4 +1,5 @@import AddOutlinedIcon from "@mui/icons-material/AddOutlined";+import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";import CheckCircleRoundedIcon from "@mui/icons-material/CheckCircleRounded";import ClearRoundedIcon from "@mui/icons-material/ClearRounded";import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";@@ -85,6 +86,7 @@ interface ItemListProps {onCreateCollection?: (name: string) => Promise<number>;onShareCollection?: (collection: LockerCollection) => void;searchTerm: string;+ onNavigateBack?: () => void;}const contentMaxWidth = 560;@@ -108,6 +110,7 @@ export const ItemList: React.FC<ItemListProps> = ({onCreateCollection,onShareCollection,searchTerm,+ onNavigateBack,}) => {const currentUserID = ensureLocalUser().id;const [selectedItem, setSelectedItem] = useState<LockerItem | null>(null);@@ -784,6 +787,7 @@ export const ItemList: React.FC<ItemListProps> = ({countLabel={t("lockerCollectionsCount", {count: displayCollections.length,})}+ onBack={onNavigateBack}action={onCreateCollection ? (<Tooltip@@ -933,6 +937,7 @@ export const ItemList: React.FC<ItemListProps> = ({countLabel={t("lockerItemsCount", {count: sortedItems.length,})}+ onBack={onNavigateBack}action={<Stackdirection="row"@@ -1441,7 +1446,8 @@ const SectionHeader: React.FC<{title: string;countLabel: string;action?: React.ReactNode;-}> = ({ title, countLabel, action }) => (+ onBack?: () => void;+}> = ({ title, countLabel, action, onBack }) => (<Stackdirection="row"sx={{@@ -1451,17 +1457,45 @@ const SectionHeader: React.FC<{maxWidth: contentMaxWidth,mx: "auto",mt: 3,- mb: 1.5,+ mb: 2.25,}}>- <Box>- <Typography variant="h3" sx={{ fontWeight: "bold" }}>- {title}- </Typography>- <Typography variant="small" sx={{ color: "text.muted" }}>- {countLabel}- </Typography>- </Box>+ <Stack+ direction="row"+ sx={{ minWidth: 0, gap: 1.5, alignItems: "center" }}+ >+ {onBack && (+ <IconButton+ aria-label="Back"+ onClick={onBack}+ sx={{+ alignSelf: "center",+ width: 44,+ height: 44,+ flexShrink: 0,+ color: "text.secondary",+ border: "1px solid rgba(255, 255, 255, 0.10)",+ backgroundColor: "rgba(255, 255, 255, 0.03)",+ "&:hover": {+ backgroundColor: "rgba(255, 255, 255, 0.08)",+ },+ }}+ >+ <ArrowBackRoundedIcon sx={{ fontSize: 20 }} />+ </IconButton>+ )}+ <Box sx={{ minWidth: 0 }}>+ <Typography+ variant="h3"+ sx={{ fontWeight: "bold", minWidth: 0 }}+ >+ {title}+ </Typography>+ <Typography variant="small" sx={{ color: "text.muted", mt: 1 }}>+ {countLabel}+ </Typography>+ </Box>+ </Stack>{action}</Stack>);diff --git a/web/apps/locker/src/pages/collection/[id].tsx b/web/apps/locker/src/pages/collection/[id].tsxnew file mode 100644index 0000000000..f58e6f75b5--- /dev/null+++ b/web/apps/locker/src/pages/collection/[id].tsx@@ -0,0 +1 @@+export { LockerPage as default } from "../locker";diff --git a/web/apps/locker/src/pages/collections.tsx b/web/apps/locker/src/pages/collections.tsxnew file mode 100644index 0000000000..85c6cff69f--- /dev/null+++ b/web/apps/locker/src/pages/collections.tsx@@ -0,0 +1 @@+export { LockerPage as default } from "./locker";diff --git a/web/apps/locker/src/pages/index.tsx b/web/apps/locker/src/pages/index.tsxindex 6c5ad19133..85c6cff69f 100644--- a/web/apps/locker/src/pages/index.tsx+++ b/web/apps/locker/src/pages/index.tsx@@ -1,11 +1 @@-import { LoadingIndicator } from "ente-base/components/loaders";-import { useRouter } from "next/router";-import React, { useEffect } from "react";--const Page: React.FC = () => {- const router = useRouter();- useEffect(() => void router.replace("/login"), [router]);- return <LoadingIndicator />;-};--export default Page;+export { LockerPage as default } from "./locker";diff --git a/web/apps/locker/src/pages/locker.tsx b/web/apps/locker/src/pages/locker.tsxindex acfabf2805..0808ad06b5 100644--- a/web/apps/locker/src/pages/locker.tsx+++ b/web/apps/locker/src/pages/locker.tsx@@ -101,7 +101,13 @@ const hasPaidLockerAccess = (json: {return hasActivePaidSubscription || isPartOfFamily || hasPaidAddon;};-const Page: React.FC = () => {+const isLockerAppPath = (path: string) =>+ path === "/" ||+ path === "/collections" ||+ path === "/trash" ||+ path.startsWith("/collection/");++export const LockerPage: React.FC = () => {const { logout, showMiniDialog } = useBaseContext();const router = useRouter();const isLockerI18nReady = useSetupLockerI18n();@@ -121,13 +127,6 @@ const Page: React.FC = () => {// View mode stateconst [trashItems, setTrashItems] = useState<LockerItem[]>([]);const [trashLastUpdatedAt, setTrashLastUpdatedAt] = useState(0);- const [isTrashView, setIsTrashView] = useState(false);- const [isCollectionsView, setIsCollectionsView] = useState(false);-- // Collection filter state- const [selectedCollectionID, setSelectedCollectionID] = useState<- number | null- >(null);const [searchTerm, setSearchTerm] = useState("");// Create/Edit dialog state@@ -149,6 +148,19 @@ const Page: React.FC = () => {);const [isDragActive, setIsDragActive] = useState(false);const dragDepthRef = useRef(0);+ const lockerRouteStackRef = useRef<string[]>([]);+ const isNavigatingBackRef = useRef(false);+ const routeCollectionID =+ router.pathname === "/collection/[id]" &&+ typeof router.query.id === "string"+ ? Number.parseInt(router.query.id, 10)+ : null;+ const selectedCollectionID =+ routeCollectionID !== null && Number.isFinite(routeCollectionID)+ ? routeCollectionID+ : null;+ const isTrashView = router.pathname === "/trash";+ const isCollectionsView = router.pathname === "/collections";const loadUserDetails = useCallback(async () => {try {@@ -203,11 +215,19 @@ const Page: React.FC = () => {[loadUserDetails, masterKey, logout, showMiniDialog],);+ useEffect(() => {+ if (router.pathname !== "/locker") {+ return;+ }++ void router.replace("/", undefined, { shallow: true });+ }, [router]);+useEffect(() => {const load = async () => {const mk = await masterKeyFromSession();if (!mk) {- stashRedirect("/locker");+ stashRedirect(router.asPath || "/");void router.push("/login");return;}@@ -239,26 +259,73 @@ const Page: React.FC = () => {void load();}, [loadUserDetails, router, logout, showMiniDialog]);- const handleSelectCollection = useCallback((id: number | null) => {- setSelectedCollectionID(id);- setIsTrashView(false);- setIsCollectionsView(false);+ useEffect(() => {+ if (!router.isReady || !isLockerAppPath(router.asPath)) {+ return;+ }++ const routeStack = lockerRouteStackRef.current;+ const currentPath = router.asPath;+ const lastPath = routeStack[routeStack.length - 1];++ if (isNavigatingBackRef.current) {+ isNavigatingBackRef.current = false;+ if (lastPath !== currentPath) {+ routeStack.push(currentPath);+ }+ return;+ }++ if (lastPath !== currentPath) {+ routeStack.push(currentPath);+ }+ }, [router.asPath, router.isReady]);++ const navigateHome = useCallback(() => {+ void router.push("/", undefined, { shallow: true });+ }, [router]);++ const handleNavigateBack = useCallback(() => {setSidebarOpen(false);- }, []);++ const routeStack = lockerRouteStackRef.current;+ if (routeStack.length > 1) {+ routeStack.pop();+ isNavigatingBackRef.current = true;+ router.back();+ return;+ }++ if (router.asPath !== "/") {+ lockerRouteStackRef.current = ["/"];+ isNavigatingBackRef.current = true;+ void router.push("/", undefined, { shallow: true });+ }+ }, [router]);++ const handleSelectCollection = useCallback(+ (id: number | null) => {+ if (id === null) {+ navigateHome();+ } else {+ void router.push(`/collection/${id}`, undefined, {+ shallow: true,+ });+ }+ setSidebarOpen(false);+ },+ [navigateHome, router],+ );const handleSelectCollections = useCallback(() => {- setIsCollectionsView(true);- setIsTrashView(false);- setSelectedCollectionID(null);+ void router.push("/collections", undefined, { shallow: true });setSidebarOpen(false);- }, []);+ }, [router]);const handleSelectTrash = useCallback(() => {- setIsTrashView(true);- setIsCollectionsView(false);- setSelectedCollectionID(null);+ void router.push("/trash", undefined, { shallow: true });setSidebarOpen(false);- }, []);+ }, [router]);const isHomeView =!isTrashView && !isCollectionsView && selectedCollectionID === null;@@ -534,6 +601,7 @@ const Page: React.FC = () => {if (droppedItems.length > 0 &&(droppedItems.length !== 1 ||+ droppedItem === undefined ||droppedItem.kind !== "file" ||droppedItem.webkitGetAsEntry()?.isDirectory)) {@@ -573,14 +641,14 @@ const Page: React.FC = () => {color: "critical",action: async () => {await deleteCollectionAPI(collectionID);- setSelectedCollectionID(null);+ navigateHome();await refreshData();setToast(t("collectionDeletedSuccessfully"));},},});},- [collections, showMiniDialog, refreshData],+ [collections, navigateHome, refreshData, showMiniDialog],);const handleOpenShareCollection = useCallback(@@ -615,8 +683,13 @@ const Page: React.FC = () => {: (collections.find((collection) => collection.id === shareCollectionID,) ?? null);+ const isCollectionRoutePending =+ router.pathname === "/collection/[id]" &&+ (!router.isReady || typeof router.query.id !== "string");+ const isViewLoading =+ !hasFetched || !isLockerI18nReady || isCollectionRoutePending;- if (!hasFetched || !isLockerI18nReady) {+ if (isViewLoading) {return <LoadingIndicator />;}if (initialLoadError && collections.length === 0) {@@ -706,6 +779,7 @@ const Page: React.FC = () => {onCreateCollection={handleCreateCollection}onShareCollection={handleOpenShareCollection}searchTerm={searchTerm}+ onNavigateBack={handleNavigateBack}/></Box><LockerSidebar@@ -844,4 +918,4 @@ const Page: React.FC = () => {);};-export default Page;+export default LockerPage;diff --git a/web/apps/locker/src/pages/trash.tsx b/web/apps/locker/src/pages/trash.tsxnew file mode 100644index 0000000000..85c6cff69f--- /dev/null+++ b/web/apps/locker/src/pages/trash.tsx@@ -0,0 +1 @@+export { LockerPage as default } from "./locker";