Skip to content

Commit 7f5e8d5

Browse files
committed
Remember clicks in environments sidebar
1 parent be166c8 commit 7f5e8d5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/components/molecules/sidebar/content/Environment.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
88
import { toast } from 'react-toastify';
99
import Tippy from '@tippyjs/react';
1010
import 'tippy.js/dist/tippy.css';
11+
import useCollectionStore from 'stores/CollectionStore';
1112

1213
const Environment = ({ collectionId, collection }) => {
13-
const [isExpanded, setIsExpanded] = useState(false);
14+
//const [isExpanded, setIsExpanded] = useState(false);
15+
const clickEnvironments = useCollectionStore((state) => state.clickEnvironments);
1416
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
1517
const [envToDelete, setEnvToDelete] = useState('');
1618

@@ -26,7 +28,8 @@ const Environment = ({ collectionId, collection }) => {
2628
const clickFromElementDataSet = event.target.dataset;
2729
const clickFrom = clickFromElementDataSet?.clickFrom;
2830
if (!clickFrom || clickFrom !== 'env-options-menu') {
29-
return setIsExpanded((prev) => !prev);
31+
//return setIsExpanded((prev) => !prev);
32+
clickEnvironments(collectionId);
3033
}
3134
}}
3235
>
@@ -42,7 +45,7 @@ const Environment = ({ collectionId, collection }) => {
4245
pathName={collection.pathname}
4346
/>
4447
</div>
45-
{isExpanded && (
48+
{collection.envCollapsed === false && (
4649
<>
4750
{collection.environments?.map((environment, index) => (
4851
<ul

src/stores/CollectionStore.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const useCollectionStore = create((set, get) => ({
2525
nodes: nodes,
2626
items: [],
2727
environments: [],
28+
envCollapsed: true,
2829
};
2930
if (!get().collections.find((c) => c.pathname === pathname)) {
3031
set((state) => ({ collections: [...state.collections, collectionObj] }));
@@ -328,6 +329,16 @@ const useCollectionStore = create((set, get) => ({
328329
}),
329330
);
330331
},
332+
clickEnvironments: (collectionId) => {
333+
set(
334+
produce((state) => {
335+
const collection = state.collections.find((c) => c.id === collectionId);
336+
if (collection) {
337+
collection.envCollapsed = !collection.envCollapsed;
338+
}
339+
}),
340+
);
341+
},
331342
}));
332343

333344
export default useCollectionStore;

0 commit comments

Comments
 (0)