diff --git a/packages/bruno-app/src/components/Sidebar/Collections/index.js b/packages/bruno-app/src/components/Sidebar/Collections/index.js index 91018594f0..802ca35ada 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/index.js @@ -1,5 +1,6 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; +import { savePreferences } from 'providers/ReduxStore/slices/app'; import { IconSearch, IconFolders, @@ -22,7 +23,9 @@ const CollectionsBadge = () => { const dispatch = useDispatch(); const { collections } = useSelector((state) => state.collections); const { collectionSortOrder } = useSelector((state) => state.collections); - const sortCollectionOrder = () => { + const preferences = useSelector((state) => state.app.preferences); + + const resolveOrderValue = () => { let order; switch (collectionSortOrder) { case 'default': @@ -35,8 +38,24 @@ const CollectionsBadge = () => { order = 'default'; break; } - dispatch(sortCollections({ order })); + + return order; }; + + const sortCollectionOrder = () => { + const order = resolveOrderValue(); + + dispatch(sortCollections({ order })); + dispatch(savePreferences({ + ...preferences, + collectionSortOrder: order + })); + } + + useEffect(() => { + dispatch(sortCollections({ order: preferences.collectionSortOrder })); + }, []); + return (