Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CL-28: Don't add to recent apps if app is in a fixed list #38

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/slices/appStateHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PayloadAction } from '@reduxjs/toolkit'
import { call, put, select, takeLatest } from 'redux-saga/effects'
import { AppDetails } from '../models/app-details'
import { FavoriteApp } from '../models/favorite-app'
import { PinnedApp } from '../models/pinned-app'
import { RenderedIn } from '../models/rendered-in'
import { launchApp } from '../utils/apps-module'
import { dismissKeyboard } from '../utils/keyboard'
Expand All @@ -21,8 +23,11 @@ import {
sortTemporaryPinnedApps,
toogleAllApps,
} from './appState'
import { selectFavoriteAppsMemoized } from './favoriteApps'
import { selectPinnedAppsMemoized } from './pinnedApps'
import { addRecentApp } from './recentApps'

// We should only add a launched app if it was clicked (rendered) in one of the following places;
const ADD_TO_RECENT_APPS_RENDERED_IN_VALUES = [RenderedIn.ALL_APPS, RenderedIn.FILTERED_APPS]

function* toggleAllAppsHandler() {
Expand All @@ -38,9 +43,27 @@ function* appLaunchHandler(action: PayloadAction<{ renderedIn: RenderedIn; appDe
yield put(setDisplaySettings(false))
yield put(setDisplaySortableFavoriteApps(false))

if (ADD_TO_RECENT_APPS_RENDERED_IN_VALUES.includes(action.payload.renderedIn)) {
yield put(addRecentApp(action.payload.appDetails))
const { appDetails, renderedIn } = action.payload

if (!ADD_TO_RECENT_APPS_RENDERED_IN_VALUES.includes(renderedIn)) {
return
}

// Skip adding to recent apps if permanently pinned/favourited but launched from different lists/views
const pinnedApps: PinnedApp[] = yield select(selectPinnedAppsMemoized)
const favoriteApps: FavoriteApp[] = yield select(selectFavoriteAppsMemoized)
// TODO: Include the temporarily pinned apps but only when they're rendered/displayed.

const pinnedAppsPackages: string[] = pinnedApps.map(({ packageName }: PinnedApp) => packageName)
const favoriteAppsPackages: string[] = favoriteApps.map(({ packageName }: FavoriteApp) => packageName)
const allApps = new Set([...pinnedAppsPackages, ...favoriteAppsPackages])

if (allApps.has(appDetails.packageName)) {
return
}

// Otherwise add to recent apps
yield put(addRecentApp(appDetails))
}

function* sortFavoriteAppsHandler() {
Expand Down
Loading