Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Standardize mobile detection in TripLayout using screen size breakpoint

anandbaburajan670eb91964c9
diff --git a/web/apps/photos/src/components/TripLayout/MobileNavBar.tsx b/web/apps/photos/src/components/TripLayout/MobileNavBar.tsx
index 330bee81ba..a92840aa4b 100644
--- a/web/apps/photos/src/components/TripLayout/MobileNavBar.tsx
+++ b/web/apps/photos/src/components/TripLayout/MobileNavBar.tsx
@@ -4,7 +4,6 @@ import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import ShareIcon from "@mui/icons-material/Share";
import { Box, Button, IconButton, styled } from "@mui/material";
import { EnteLogo } from "ente-base/components/EnteLogo";
-import { useIsTouchscreen } from "ente-base/components/utils/hooks";
import { Notification } from "ente-new/photos/components/Notification";
import { t } from "i18next";
import { useState } from "react";
@@ -23,7 +22,6 @@ export const MobileNavBar: React.FC<MobileNavBarProps> = ({
collectionTitle,
}) => {
const [showCopiedMessage, setShowCopiedMessage] = useState(false);
- const isTouchscreen = useIsTouchscreen();
const handleShare = async () => {
if (typeof window !== "undefined") {
@@ -81,7 +79,7 @@ export const MobileNavBar: React.FC<MobileNavBarProps> = ({
)}
<MobileSignUpButton onClick={handleSignUp}>
- {isTouchscreen ? t("install") : t("sign_up")}
+ {t("install")}
</MobileSignUpButton>
</ButtonGroup>
</MobileNavContainer>
diff --git a/web/apps/photos/src/components/TripLayout/TopNavButtons.tsx b/web/apps/photos/src/components/TripLayout/TopNavButtons.tsx
index 0e520ebe69..fd290ce41a 100644
--- a/web/apps/photos/src/components/TripLayout/TopNavButtons.tsx
+++ b/web/apps/photos/src/components/TripLayout/TopNavButtons.tsx
@@ -3,7 +3,6 @@ import CheckIcon from "@mui/icons-material/Check";
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import ShareIcon from "@mui/icons-material/Share";
import { Box, Button, IconButton, styled } from "@mui/material";
-import { useIsTouchscreen } from "ente-base/components/utils/hooks";
import { Notification } from "ente-new/photos/components/Notification";
import { t } from "i18next";
import { useState } from "react";
@@ -20,7 +19,6 @@ export const TopNavButtons: React.FC<TopNavButtonsProps> = ({
enableDownload,
}) => {
const [showCopiedMessage, setShowCopiedMessage] = useState(false);
- const isTouchscreen = useIsTouchscreen();
const handleShare = () => {
if (typeof window !== "undefined") {
@@ -58,7 +56,7 @@ export const TopNavButtons: React.FC<TopNavButtonsProps> = ({
)}
<SignUpButton onClick={handleSignUp}>
- {isTouchscreen ? t("install") : t("sign_up")}
+ {t("sign_up")}
</SignUpButton>
</ButtonContainer>
diff --git a/web/apps/photos/src/components/TripLayout/TripMap.tsx b/web/apps/photos/src/components/TripLayout/TripMap.tsx
index e36673a97c..c627b53d2e 100644
--- a/web/apps/photos/src/components/TripLayout/TripMap.tsx
+++ b/web/apps/photos/src/components/TripLayout/TripMap.tsx
@@ -1,5 +1,4 @@
-import { Box, styled } from "@mui/material";
-import { useIsTouchscreen } from "ente-base/components/utils/hooks";
+import { Box, styled, useMediaQuery, useTheme } from "@mui/material";
import dynamic from "next/dynamic";
import { MapEvents } from "./MapEvents";
@@ -69,12 +68,13 @@ export const TripMap: React.FC<TripMapProps> = ({
setTargetZoom,
onMarkerClick,
}) => {
- const isTouchDevice = useIsTouchscreen();
+ const theme = useTheme();
+ const isMobileOrTablet = useMediaQuery(theme.breakpoints.down("md")); // 960px breakpoint for mobile and tablet
// Calculate current active location index based on scroll progress (same logic as in scrollUtils)
let currentActiveLocationIndex = -1;
if (photoClusters.length > 0) {
- if (isTouchDevice) {
+ if (isMobileOrTablet) {
// Mobile: Slower progression - stay on each location longer
currentActiveLocationIndex = Math.floor(
scrollProgress * (photoClusters.length - 0.5),
@@ -107,13 +107,13 @@ export const TripMap: React.FC<TripMapProps> = ({
superClusterInfo,
)}
zoom={
- isTouchDevice
+ isMobileOrTablet
? Math.max(1, optimalZoom - 2)
: optimalZoom
}
scrollWheelZoom={true}
zoomControl={false}
- attributionControl={!isTouchDevice}
+ attributionControl={!isMobileOrTablet}
>
<MapEvents
setMapRef={setMapRef}
@@ -123,14 +123,14 @@ export const TripMap: React.FC<TripMapProps> = ({
{/* Stadia Alidade Satellite - includes both imagery and labels */}
<TileLayer
attribution={
- isTouchDevice
+ isMobileOrTablet
? ""
: '&copy; <a href="https://stadiamaps.com/">Stadia Maps</a>, &copy; <a href="https://openmaptiles.org/">OpenMapTiles</a> &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}
url="https://tiles.stadiamaps.com/tiles/alidade_satellite/{z}/{x}/{y}{r}.jpg"
maxZoom={20}
- updateWhenZooming={isTouchDevice ? true : false}
- keepBuffer={isTouchDevice ? 3 : 1}
+ updateWhenZooming={isMobileOrTablet ? true : false}
+ keepBuffer={isMobileOrTablet ? 3 : 1}
/>
{/* Draw super-clusters (clickable for zoom and gallery) */}
@@ -143,7 +143,7 @@ export const TripMap: React.FC<TripMapProps> = ({
const icon = createSuperClusterIcon(
superCluster.image, // Use representative photo (first photo of first cluster)
superCluster.clusterCount,
- isTouchDevice ? 40 : 55,
+ isMobileOrTablet ? 40 : 55,
isActive,
);
@@ -206,7 +206,7 @@ export const TripMap: React.FC<TripMapProps> = ({
const icon = createIcon(
firstPhoto.image,
- isTouchDevice ? 40 : 55,
+ isMobileOrTablet ? 40 : 55,
"#ffffff",
cluster.length,
isActive,
diff --git a/web/apps/photos/src/components/TripLayout/hooks/useScrollHandling.ts b/web/apps/photos/src/components/TripLayout/hooks/useScrollHandling.ts
index 6bc0eba7fd..7803c8d8af 100644
--- a/web/apps/photos/src/components/TripLayout/hooks/useScrollHandling.ts
+++ b/web/apps/photos/src/components/TripLayout/hooks/useScrollHandling.ts
@@ -1,4 +1,3 @@
-import { useIsTouchscreen } from "ente-base/components/utils/hooks";
import { useCallback, useEffect, useMemo } from "react";
import type { JourneyPoint } from "../types";
@@ -39,6 +38,7 @@ export interface UseScrollHandlingParams {
clusterToSuperClusterMap: Map<number, number>;
};
scrollProgress: number;
+ isMobileOrTablet: boolean;
}
export const useScrollHandling = ({
@@ -57,8 +57,8 @@ export const useScrollHandling = ({
previousSuperClusterStateRef,
superClusterInfo,
scrollProgress,
+ isMobileOrTablet,
}: UseScrollHandlingParams) => {
- const isTouchDevice = useIsTouchscreen();
// Update location positions callback
const updatePositions = useCallback(() => {
updateLocationPositions({
@@ -78,7 +78,7 @@ export const useScrollHandling = ({
setHasUserScrolled,
setScrollProgress,
previousActiveLocationRef,
- isTouchDevice,
+ isMobileOrTablet,
setTargetZoom,
previousSuperClusterStateRef,
superClusterInfo,
@@ -92,7 +92,7 @@ export const useScrollHandling = ({
setHasUserScrolled,
setScrollProgress,
previousActiveLocationRef,
- isTouchDevice,
+ isMobileOrTablet,
setTargetZoom,
previousSuperClusterStateRef,
superClusterInfo,
@@ -112,9 +112,10 @@ export const useScrollHandling = ({
locationIndex,
photoClusters,
locationPositions,
+ isMobileOrTablet,
});
},
- [timelineRef, photoClusters, locationPositions],
+ [timelineRef, photoClusters, locationPositions, isMobileOrTablet],
);
// Marker click handler
@@ -131,7 +132,7 @@ export const useScrollHandling = ({
setScrollProgress,
setHasUserScrolled,
scrollTimelineToLocation: scrollToLocation,
- isTouchDevice,
+ isMobileOrTablet,
superClusterInfo,
scrollProgress,
setTargetZoom,
@@ -147,7 +148,7 @@ export const useScrollHandling = ({
setScrollProgress,
setHasUserScrolled,
scrollToLocation,
- isTouchDevice,
+ isMobileOrTablet,
superClusterInfo,
scrollProgress,
setTargetZoom,
diff --git a/web/apps/photos/src/components/TripLayout/index.tsx b/web/apps/photos/src/components/TripLayout/index.tsx
index 947f7a0fff..f2044c9aa4 100644
--- a/web/apps/photos/src/components/TripLayout/index.tsx
+++ b/web/apps/photos/src/components/TripLayout/index.tsx
@@ -56,7 +56,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
// Use media query for mobile/tablet detection (up to 960px)
const theme = useTheme();
- const isTouchDevice = useMediaQuery(theme.breakpoints.down("md")); // 960px breakpoint for mobile and tablet
+ const isMobileOrTablet = useMediaQuery(theme.breakpoints.down("md")); // 960px breakpoint for mobile and tablet
// Save groups hook for download progress tracking
const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
@@ -223,7 +223,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
const firstLocationInSuperCluster =
clusterToSuperClusterMap.has(0);
const initialZoom = firstLocationInSuperCluster
- ? isTouchDevice
+ ? isMobileOrTablet
? 15
: 14 // Super cluster zoom level
: optimalZoomLevel;
@@ -237,7 +237,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
);
}
}
- }, [isClient, journeyData, isTouchDevice]);
+ }, [isClient, journeyData, isMobileOrTablet]);
// Update currentZoom when optimalZoom changes and there's no mapRef yet
useEffect(() => {
@@ -292,10 +292,11 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
clusterClickTimeoutRef,
previousActiveLocationRef,
setLocationPositions,
+ isMobileOrTablet,
setHasUserScrolled: (scrolled: boolean) => {
setHasUserScrolled(scrolled);
if (
- isTouchDevice &&
+ isMobileOrTablet &&
tripStartedRef.current &&
timelineRef.current
) {
@@ -333,7 +334,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
return (
<TripLayoutContainer>
{!openFileViewer &&
- (isTouchDevice ? (
+ (isMobileOrTablet ? (
<MobileNavBar
onAddPhotos={onAddPhotos}
downloadAllFiles={downloadAllFiles}
@@ -348,7 +349,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
/>
))}
{/* Mobile Layout */}
- {isTouchDevice ? (
+ {isMobileOrTablet ? (
<MobileContainer>
{/* Map takes 60% of height */}
<MobileMapContainer>
diff --git a/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts b/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts
index b82a83b3e2..739aa87d62 100644
--- a/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts
+++ b/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts
@@ -45,7 +45,7 @@ export interface HandleTimelineScrollParams {
setHasUserScrolled: (scrolled: boolean) => void;
setScrollProgress: (progress: number) => void;
previousActiveLocationRef: React.RefObject<number>;
- isTouchDevice: boolean;
+ isMobileOrTablet: boolean;
setTargetZoom: (zoom: number | null) => void;
previousSuperClusterStateRef: React.RefObject<{
isInSuperCluster: boolean;
@@ -72,7 +72,7 @@ export const handleTimelineScroll = ({
setHasUserScrolled,
setScrollProgress,
previousActiveLocationRef,
- isTouchDevice,
+ isMobileOrTablet,
setTargetZoom,
previousSuperClusterStateRef,
superClusterInfo,
@@ -116,7 +116,7 @@ export const handleTimelineScroll = ({
// Calculate current active location index based on scroll progress
let currentActiveLocationIndex = -1; // Start with no location selected
if (photoClusters.length > 0) {
- if (isTouchDevice) {
+ if (isMobileOrTablet) {
// Mobile: Slower progression - stay on each location longer
currentActiveLocationIndex = Math.floor(
clampedProgress * (photoClusters.length - 0.5),
@@ -176,7 +176,7 @@ export const handleTimelineScroll = ({
}
}
- const targetZoom = isTouchDevice ? 8 : 10; // Touch device-aware zoom level
+ const targetZoom = isMobileOrTablet ? 8 : 10; // Touch device-aware zoom level
// Get super cluster info for both source and destination
const currentSuperClusterIndex =
@@ -208,7 +208,7 @@ export const handleTimelineScroll = ({
// Handle super cluster zoom logic - check distant locations first!
if (isInSuperCluster && !wasInSuperCluster && isFirstLocationEver) {
// First location ever and it's in a super cluster - directly zoom to super cluster level
- const superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters
+ const superClusterZoom = isMobileOrTablet ? 15 : 14; // Higher zoom on mobile to break apart clusters
const [zoomAwareLat, zoomAwareLng] = getLocationPositionAtZoom(
targetCluster.lat,
targetCluster.lng,
@@ -222,8 +222,8 @@ export const handleTimelineScroll = ({
isDistantLocation
) {
// Entering super cluster from distant location - full zoom out β†’ pan β†’ zoom in
- const superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters
- const intermediateZoom = isTouchDevice ? 2 : 4; // Extreme zoom out for distant locations
+ const superClusterZoom = isMobileOrTablet ? 15 : 14; // Higher zoom on mobile to break apart clusters
+ const intermediateZoom = isMobileOrTablet ? 2 : 4; // Extreme zoom out for distant locations
const [zoomAwareLat, zoomAwareLng] = getLocationPositionAtZoom(
targetCluster.lat,
targetCluster.lng,
@@ -248,7 +248,7 @@ export const handleTimelineScroll = ({
}, 1600);
} else if (isInSuperCluster && !wasInSuperCluster) {
// Entering super cluster from nearby location - direct zoom in
- const superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters
+ const superClusterZoom = isMobileOrTablet ? 15 : 14; // Higher zoom on mobile to break apart clusters
const [zoomAwareLat, zoomAwareLng] = getLocationPositionAtZoom(
targetCluster.lat,
targetCluster.lng,
@@ -264,7 +264,7 @@ export const handleTimelineScroll = ({
// Leaving super cluster - check if distant location
if (isDistantLocation) {
// Distant location: full zoom out β†’ pan β†’ zoom in
- const intermediateZoom = isTouchDevice ? 2 : 4;
+ const intermediateZoom = isMobileOrTablet ? 2 : 4;
mapRef.flyTo(
[positionedLat, positionedLng],
intermediateZoom,
@@ -315,8 +315,8 @@ export const handleTimelineScroll = ({
if (isDistantLocation) {
// Distant location from super cluster: full zoom out β†’ pan β†’ zoom in
// Since we're in the isInSuperCluster block, destination is always a super cluster
- const finalZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters
- const intermediateZoom = isTouchDevice ? 2 : 4; // Extreme zoom out for distant locations
+ const finalZoom = isMobileOrTablet ? 15 : 14; // Higher zoom on mobile to break apart clusters
+ const intermediateZoom = isMobileOrTablet ? 2 : 4; // Extreme zoom out for distant locations
const [zoomAwareLat, zoomAwareLng] =
getLocationPositionAtZoom(
targetCluster.lat,
@@ -342,8 +342,8 @@ export const handleTimelineScroll = ({
}, 1600);
} else if (isDifferentSuperCluster) {
// Different super cluster (not distant): moderate zoom out β†’ pan β†’ zoom in
- const superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters
- const intermediateZoom = isTouchDevice ? 8 : 10; // Moderate zoom out for nearby super clusters
+ const superClusterZoom = isMobileOrTablet ? 15 : 14; // Higher zoom on mobile to break apart clusters
+ const intermediateZoom = isMobileOrTablet ? 8 : 10; // Moderate zoom out for nearby super clusters
const [zoomAwareLat, zoomAwareLng] =
getLocationPositionAtZoom(
targetCluster.lat,
@@ -388,7 +388,7 @@ export const handleTimelineScroll = ({
}
} else if (isDistantLocation) {
// For distant locations not in super cluster: zoom out β†’ pan β†’ zoom in
- const intermediateZoom = isTouchDevice ? 2 : 4;
+ const intermediateZoom = isMobileOrTablet ? 2 : 4;
mapRef.flyTo([positionedLat, positionedLng], intermediateZoom, {
animate: true,
duration: 1.5,
@@ -436,6 +436,7 @@ export interface ScrollTimelineToLocationParams {
locationIndex: number;
photoClusters: JourneyPoint[][];
locationPositions: PositionInfo[];
+ isMobileOrTablet: boolean;
}
export const scrollTimelineToLocation = ({
@@ -443,6 +444,7 @@ export const scrollTimelineToLocation = ({
locationIndex,
photoClusters,
locationPositions,
+ isMobileOrTablet,
}: ScrollTimelineToLocationParams) => {
if (
!timelineRef.current ||
@@ -457,14 +459,9 @@ export const scrollTimelineToLocation = ({
const clientHeight = timelineContainer.clientHeight;
const maxScrollableDistance = scrollHeight - clientHeight;
- // Check if we're on a touch device
- const isTouchDevice =
- typeof window !== "undefined" &&
- ("ontouchstart" in window || navigator.maxTouchPoints > 0);
-
// Calculate target progress using the same formula as scroll progress calculation
let targetProgress;
- if (isTouchDevice) {
+ if (isMobileOrTablet) {
// Mobile: Use inverse of the slower progression formula
// If active index = Math.floor(progress * (length - 0.5))
// Then progress = (index + 0.5) / (length - 0.5) for accurate inverse
@@ -496,7 +493,7 @@ export interface HandleMarkerClickParams {
setScrollProgress: (progress: number) => void;
setHasUserScrolled: (scrolled: boolean) => void;
scrollTimelineToLocation: (locationIndex: number) => void;
- isTouchDevice: boolean;
+ isMobileOrTablet: boolean;
superClusterInfo?: {
superClusters: {
lat: number;
@@ -527,7 +524,7 @@ export const handleMarkerClick = ({
setScrollProgress,
setHasUserScrolled,
scrollTimelineToLocation,
- isTouchDevice,
+ isMobileOrTablet,
superClusterInfo,
scrollProgress,
setTargetZoom,
@@ -550,7 +547,7 @@ export const handleMarkerClick = ({
// Calculate current active location index
let currentActiveLocationIndex = -1;
if (photoClusters.length > 0) {
- if (isTouchDevice) {
+ if (isMobileOrTablet) {
currentActiveLocationIndex = Math.floor(
scrollProgress * (photoClusters.length - 0.5),
);
@@ -613,7 +610,7 @@ export const handleMarkerClick = ({
if (isInSuperCluster) {
// Zoom to super cluster level to break it apart
- const superClusterZoom = isTouchDevice ? 15 : 14;
+ const superClusterZoom = isMobileOrTablet ? 15 : 14;
const [zoomAwareLat, zoomAwareLng] =
getLocationPositionAtZoom(
clusterLat,
@@ -644,7 +641,7 @@ export const handleMarkerClick = ({
clusterLat,
clusterLng,
);
- const targetZoomLevel = isTouchDevice ? 8 : 10;
+ const targetZoomLevel = isMobileOrTablet ? 8 : 10;
// Set target zoom before animation
setTargetZoom(targetZoomLevel);
mapRef.flyTo(