From fc2931855e1a67742f3ad0ec62900dfae3f5b2ed Mon Sep 17 00:00:00 2001 From: Sai K K Date: Mon, 4 Nov 2024 21:08:31 +0530 Subject: [PATCH 1/2] feat: adds save preferences on collections --- .../bruno-app/src/components/Sidebar/Collections/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/index.js b/packages/bruno-app/src/components/Sidebar/Collections/index.js index 91018594f0..fb59150be2 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 { useDispatch, useSelector } from 'react-redux'; +import { savePreferences } from 'providers/ReduxStore/slices/app'; import { IconSearch, IconFolders, @@ -22,6 +23,8 @@ const CollectionsBadge = () => { const dispatch = useDispatch(); const { collections } = useSelector((state) => state.collections); const { collectionSortOrder } = useSelector((state) => state.collections); + const preferences = useSelector((state) => state.app.preferences); + const sortCollectionOrder = () => { let order; switch (collectionSortOrder) { @@ -36,6 +39,10 @@ const CollectionsBadge = () => { break; } dispatch(sortCollections({ order })); + dispatch(savePreferences({ + ...preferences, + collectionSortOrder: order + })); }; return (
From b58946579cf35834bbebf988fa05940eb11f34d9 Mon Sep 17 00:00:00 2001 From: Sai K K Date: Mon, 4 Nov 2024 21:20:58 +0530 Subject: [PATCH 2/2] refactor: set collection order on mounted --- .../components/Sidebar/Collections/index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/index.js b/packages/bruno-app/src/components/Sidebar/Collections/index.js index fb59150be2..802ca35ada 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/index.js @@ -1,4 +1,4 @@ -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 { @@ -25,7 +25,7 @@ const CollectionsBadge = () => { const { collectionSortOrder } = useSelector((state) => state.collections); const preferences = useSelector((state) => state.app.preferences); - const sortCollectionOrder = () => { + const resolveOrderValue = () => { let order; switch (collectionSortOrder) { case 'default': @@ -38,12 +38,24 @@ const CollectionsBadge = () => { order = 'default'; break; } + + return order; + }; + + const sortCollectionOrder = () => { + const order = resolveOrderValue(); + dispatch(sortCollections({ order })); dispatch(savePreferences({ ...preferences, collectionSortOrder: order })); - }; + } + + useEffect(() => { + dispatch(sortCollections({ order: preferences.collectionSortOrder })); + }, []); + return (