|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback, useState } from "react";
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
import { serializeLibraryAsJSON } from "../data/json";
|
|
|
import { t } from "../i18n";
|
|
|
import {
|
|
@@ -15,6 +15,7 @@ import { duplicateElements } from "../element/newElement";
|
|
|
import { LibraryMenuControlButtons } from "./LibraryMenuControlButtons";
|
|
|
import { LibraryDropdownMenu } from "./LibraryMenuHeaderContent";
|
|
|
import LibraryMenuSection from "./LibraryMenuSection";
|
|
|
+import { useScrollPosition } from "../hooks/useScrollPosition";
|
|
|
import { useLibraryCache } from "../hooks/useLibraryItemSvg";
|
|
|
|
|
|
import "./LibraryMenuItems.scss";
|
|
@@ -39,6 +40,15 @@ export default function LibraryMenuItems({
|
|
|
id: string;
|
|
|
}) {
|
|
|
const [selectedItems, setSelectedItems] = useState<LibraryItem["id"][]>([]);
|
|
|
+ const libraryContainerRef = useRef<HTMLDivElement>(null);
|
|
|
+ const scrollPosition = useScrollPosition<HTMLDivElement>(libraryContainerRef);
|
|
|
+
|
|
|
+ // This effect has to be called only on first render, therefore `scrollPosition` isn't in the dependency array
|
|
|
+ useEffect(() => {
|
|
|
+ if (scrollPosition > 0) {
|
|
|
+ libraryContainerRef.current?.scrollTo(0, scrollPosition);
|
|
|
+ }
|
|
|
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
const { svgCache } = useLibraryCache();
|
|
|
|
|
|
const unpublishedItems = libraryItems.filter(
|
|
@@ -183,6 +193,7 @@ export default function LibraryMenuItems({
|
|
|
flex: publishedItems.length > 0 ? 1 : "0 1 auto",
|
|
|
marginBottom: 0,
|
|
|
}}
|
|
|
+ ref={libraryContainerRef}
|
|
|
>
|
|
|
<>
|
|
|
{!isLibraryEmpty && (
|