Skip to content

armgit / ente

Public Imported from GitHub
0

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

wip: checkpoint

Manav Rathi19273927d1a5
diff --git a/web/apps/photos/src/components/Collections/CollectionListBar.tsx b/web/apps/photos/src/components/Collections/CollectionListBar.tsx
index 0c2e6ade8d..339df9c2b3 100644
--- a/web/apps/photos/src/components/Collections/CollectionListBar.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionListBar.tsx
@@ -102,56 +102,65 @@ export const CollectionListBar: React.FC<CollectionListBarProps> = ({
// const windowSize = useWindowSize();
const isMobile = useIsMobileWidth();
- const listContainerCallbackRef = useCallback((node) => {
- listContainerRef.current = node;
- }, []);
- const listContainerRef = useRef<HTMLDivElement>(null);
- const listRef = useRef(null);
-
const [canScrollLeft, setCanScrollLeft] = useState(false);
const [canScrollRight, setCanScrollRight] = useState(false);
const updateScrollState = useCallback(() => {
- console.log("updateScrollState 1");
- if (!listContainerRef.current) return;
+ console.log(
+ "updateScrollState called, ref is",
+ listContainerRef.current,
+ );
+ // if (!listContainerRef.current) return;
const { scrollLeft, scrollWidth, clientWidth } =
listContainerRef.current;
- console.log("updateScrollState 2", {
- scrollLeft,
- scrollWidth,
- clientWidth,
- });
+ // console.log("updateScrollState 2", {
+ // scrollLeft,
+ // scrollWidth,
+ // clientWidth,
+ // });
setCanScrollLeft(scrollLeft > 0);
setCanScrollRight(scrollLeft + clientWidth < scrollWidth);
}, []);
- useEffect(() => {
- const listContainer = listContainerRef.current;
- if (!listContainer) return;
-
- // Add event listener.
- listContainer.addEventListener("scroll", updateScrollState);
- const observer = new ResizeObserver((es) => {
- console.log(es);
+ const listContainerCallbackRef = useCallback(
+ (ref) => {
+ console.log("callback ref was called with node", ref);
+ listContainerRef.current = ref;
+ if (!ref) return;
+
+ // Add event listener.
+ ref.addEventListener("scroll", updateScrollState);
+ const observer = new ResizeObserver((es) => {
+ console.log(es);
+ updateScrollState();
+ });
+ observer.observe(ref);
+ // listContainer.addEventListener("resize", updateScrollState);
+
+ // Call handler right away so that state gets updated with initial
+ // window size.
updateScrollState();
- });
- observer.observe(listContainer);
- // listContainer.addEventListener("resize", updateScrollState);
- // Call handler right away so that state gets updated with initial
- // window size.
- updateScrollState();
+ // Remove event listener on cleanup.
+ return () => {
+ ref.removeEventListener("scroll", updateScrollState);
+ // listContainer.removeEventListener("resize", updateScrollState);
+ observer.unobserve(ref);
+ };
+ },
+ [updateScrollState],
+ );
+
+ const listContainerRef = useRef<HTMLDivElement>(null);
+ const listRef = useRef(null);
- // Remove event listener on cleanup.
- return () => {
- listContainer.removeEventListener("scroll", updateScrollState);
- // listContainer.removeEventListener("resize", updateScrollState);
- observer.unobserve(listContainer);
- };
- }, [updateScrollState]);
+ // useEffect(() => {
+ // const listContainer = listContainerRef.current;
+ // if (!listContainer) return;
+ // }, [updateScrollState]);
useEffect(() => {
updateScrollState();