Skip to content

Commit 9f321c7

Browse files
committed
chore: logic of fetchRecentlyVisitedParsedApps modified
1 parent 694299f commit 9f321c7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Shared/Hooks/useUserPreferences/useUserPrefrences.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
UseUserPreferencesProps,
88
ViewIsPipelineRBACConfiguredRadioTabs,
99
} from './types'
10-
import { getUserPreferences } from './service'
10+
import { getUserPreferences, updateUserPreferences } from './service'
1111

1212
export const useUserPreferences = ({ migrateUserPreferences }: UseUserPreferencesProps) => {
1313
const [userPreferences, setUserPreferences] = useState<UserPreferencesType>(null)
@@ -25,11 +25,12 @@ export const useUserPreferences = ({ migrateUserPreferences }: UseUserPreference
2525
// Ensure all items have valid `appId` and `appName`
2626
const validApps = _recentApps.filter((app) => app?.appId && app?.appName)
2727

28-
// Combine current app with previous list
29-
const combinedList = [{ appId, appName }, ...validApps]
28+
// Convert to a Map for uniqueness while maintaining stacking order
29+
const uniqueApps = [
30+
{ appId, appName }, // Ensure new app is on top
31+
...validApps.filter((app) => app.appId !== appId), // Keep previous order, remove duplicate
32+
].slice(0, 6) // Limit to 6 items
3033

31-
// Filter out invalid app and limit to 6 && Ensure unique entries using a Set
32-
const uniqueApps = Array.from(new Map(combinedList.map((app) => [app.appId, app])).values()).slice(0, 6)
3334
const uniqueFilteredApps = isInvalidAppId ? uniqueApps.filter((app) => app.appId !== Number(appId)) : uniqueApps
3435
setUserPreferences((prev) => ({
3536
...prev,
@@ -41,6 +42,7 @@ export const useUserPreferences = ({ migrateUserPreferences }: UseUserPreference
4142
},
4243
},
4344
}))
45+
await updateUserPreferences(null, uniqueFilteredApps)
4446
}
4547

4648
const handleInitializeUserPreferencesFromResponse = (userPreferencesResponse: UserPreferencesType) => {

0 commit comments

Comments
 (0)