Skip to content

Commit

Permalink
Merge pull request #182 from ulu-telegram/tg-244-Maintain-open-state-…
Browse files Browse the repository at this point in the history
…between-refreshes

Update UluControlledTreeEnvironment.tsx
  • Loading branch information
ulugmer authored Dec 4, 2023
2 parents 6bbcd39 + b83e67e commit 17da58e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ const UluControlledTreeEnvironment = forwardRef<TreeEnvironmentRef, OwnProps>(({
setExpandedItems(newExpandedItems);
}, [totalFolders, items, currentWorkspaceId]);

// Чтение сохраненного состояния при монтировании
useEffect(() => {
const savedExpandedItems = localStorage.getItem(`expandedItems-${id}`);
if (savedExpandedItems) {
setExpandedItems(JSON.parse(savedExpandedItems));
}
}, [id]);

// Сохранение состояния при его изменении
useEffect(() => {
localStorage.setItem(`expandedItems-${id}`, JSON.stringify(expandedItems));
}, [expandedItems, id]);

return (
<ControlledTreeEnvironment
items={items}
Expand Down

0 comments on commit 17da58e

Please sign in to comment.