From b58946579cf35834bbebf988fa05940eb11f34d9 Mon Sep 17 00:00:00 2001 From: Sai K K Date: Mon, 4 Nov 2024 21:20:58 +0530 Subject: [PATCH] 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 fb59150be..802ca35ad 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 (