🚸 Save sidebar locked state in local storage (#1956)

Closes #1933

---------

Co-authored-by: Baptiste Arnaud <contact@baptiste-arnaud.fr>
Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
This commit is contained in:
Anonymus2000 2025-01-30 00:48:23 +05:30 committed by GitHub
parent 5ceaa961a1
commit d4d922dbf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -25,7 +25,7 @@ import { isDefined } from "@typebot.io/lib/utils";
import type React from "react";
import { useState } from "react";
import { useDebouncedCallback } from "use-debounce";
import { headerHeight } from "../constants";
import { headerHeight, leftSidebarLockedStorageKey } from "../constants";
import { BlockCard } from "./BlockCard";
import { BlockCardOverlay } from "./BlockCardOverlay";
import {
@ -49,8 +49,12 @@ export const BlocksSideBar = () => {
x: 0,
y: 0,
});
const [isLocked, setIsLocked] = useState(true);
const [isExtended, setIsExtended] = useState(true);
const [isLocked, setIsLocked] = useState(
localStorage.getItem(leftSidebarLockedStorageKey) === "true",
);
const [isExtended, setIsExtended] = useState(
localStorage.getItem(leftSidebarLockedStorageKey) === "true",
);
const [searchInput, setSearchInput] = useState("");
const closeSideBar = useDebouncedCallback(() => setIsExtended(false), 200);
@ -86,7 +90,14 @@ export const BlocksSideBar = () => {
};
useEventListener("mouseup", handleMouseUp);
const handleLockClick = () => setIsLocked(!isLocked);
const handleLockClick = () => {
try {
localStorage.setItem(leftSidebarLockedStorageKey, String(!isLocked));
} catch (error) {
console.error(error);
}
setIsLocked(!isLocked);
};
const handleDockBarEnter = () => {
closeSideBar.flush();

View File

@ -1 +1,3 @@
export const headerHeight = 56;
export const leftSidebarLockedStorageKey = "isLeftSidebarLocked";