mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
ab3b2c2055
Introduces a collapsable sidebar in the Vault view to enhance user experience and optimize screen real estate. The sidebar's collapsed or expanded state is now persisted across sessions using local storage. Tooltips are added to navigation items, providing clear labels when the sidebar is in its collapsed state. Additionally, improves tooltip activation behavior in the SFTP modal, delaying their appearance slightly to prevent flickering on modal open.
25 lines
822 B
TypeScript
25 lines
822 B
TypeScript
import { useEffect, useState } from "react";
|
|
import { localStorageAdapter } from "../../infrastructure/persistence/localStorageAdapter";
|
|
|
|
/**
|
|
* Hook for persisting a boolean value to localStorage.
|
|
* @param storageKey - The key to use for localStorage
|
|
* @param fallback - The default value if no stored value exists (defaults to false)
|
|
* @returns A tuple of [value, setValue] similar to useState
|
|
*/
|
|
export const useStoredBoolean = (
|
|
storageKey: string,
|
|
fallback: boolean = false,
|
|
) => {
|
|
const [value, setValue] = useState<boolean>(() => {
|
|
const stored = localStorageAdapter.readBoolean(storageKey);
|
|
return stored ?? fallback;
|
|
});
|
|
|
|
useEffect(() => {
|
|
localStorageAdapter.writeBoolean(storageKey, value);
|
|
}, [storageKey, value]);
|
|
|
|
return [value, setValue] as const;
|
|
};
|