Skip to content

Commit 7e41373

Browse files
committed
feat(minapps): remove locale filtering from view and state
1 parent 4c3c322 commit 7e41373

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

src/renderer/src/hooks/useMinapps.ts

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@ import type { RootState } from '@renderer/store'
33
import { useAppDispatch, useAppSelector } from '@renderer/store'
44
import { setDisabledMinApps, setMinApps, setPinnedMinApps } from '@renderer/store/minapps'
55
import { type DetectedRegion, setDetectedRegion } from '@renderer/store/runtime'
6-
import type { LanguageVarious, MinAppType } from '@renderer/types'
6+
import type { MinAppType } from '@renderer/types'
77
import { useCallback, useEffect, useMemo, useRef } from 'react'
88

99
/**
1010
* Data Flow Design:
1111
*
12-
* PRINCIPLE: Locale/Region filtering is a VIEW concern, not a DATA concern.
12+
* PRINCIPLE: Region filtering is a VIEW concern, not a DATA concern.
1313
*
14-
* - Redux stores ALL apps (including locale/region-restricted ones) to preserve user preferences
15-
* - allMinApps is the template data source containing locale/region definitions
16-
* - This hook applies locale/region filtering only when READING for UI display
14+
* - Redux stores ALL apps (including region-restricted ones) to preserve user preferences
15+
* - allMinApps is the template data source containing region definitions
16+
* - This hook applies region filtering only when READING for UI display
1717
* - When WRITING, hidden apps are merged back to prevent data loss
1818
*/
1919

20-
// Check if app should be visible for the given locale
21-
const isVisibleForLocale = (app: MinAppType, language: LanguageVarious): boolean => {
22-
if (!app.locales) return true
23-
return app.locales.includes(language)
24-
}
25-
2620
/**
2721
* Check if app should be visible for the given region.
2822
*
@@ -43,22 +37,11 @@ const isVisibleForRegion = (app: MinAppType, region: DetectedRegion): boolean =>
4337
return app.supportedRegions.includes('Global')
4438
}
4539

46-
// Filter apps by locale - only show apps that match current language
47-
const filterByLocale = (apps: MinAppType[], language: LanguageVarious): MinAppType[] => {
48-
return apps.filter((app) => isVisibleForLocale(app, language))
49-
}
50-
5140
// Filter apps by region
5241
const filterByRegion = (apps: MinAppType[], region: DetectedRegion): MinAppType[] => {
5342
return apps.filter((app) => isVisibleForRegion(app, region))
5443
}
5544

56-
// Get locale-hidden apps from allMinApps for the current language
57-
// This uses allMinApps as source of truth for locale definitions
58-
const getLocaleHiddenApps = (language: LanguageVarious): MinAppType[] => {
59-
return allMinApps.filter((app) => !isVisibleForLocale(app, language))
60-
}
61-
6245
// Get region-hidden apps from allMinApps for the current region
6346
const getRegionHiddenApps = (region: DetectedRegion): MinAppType[] => {
6447
return allMinApps.filter((app) => !isVisibleForRegion(app, region))
@@ -89,7 +72,6 @@ const detectUserRegion = async (): Promise<DetectedRegion> => {
8972

9073
export const useMinapps = () => {
9174
const { enabled, disabled, pinned } = useAppSelector((state: RootState) => state.minapps)
92-
const language = useAppSelector((state: RootState) => state.settings.language)
9375
const minAppRegionSetting = useAppSelector((state: RootState) => state.settings.minAppRegion)
9476
const detectedRegion = useAppSelector((state: RootState) => state.runtime.detectedRegion)
9577
const dispatch = useAppDispatch()
@@ -132,29 +114,26 @@ export const useMinapps = () => {
132114
[mapApps]
133115
)
134116

135-
// READ: Get apps filtered by locale and region for UI display
117+
// READ: Get apps filtered by region for UI display
136118
const minapps = useMemo(() => {
137119
const allApps = getAllApps(enabled, disabled)
138120
const disabledIds = new Set(disabled.map((app) => app.id))
139121
const withoutDisabled = allApps.filter((app) => !disabledIds.has(app.id))
140-
// Apply region filter first, then locale filter
141-
const byRegion = filterByRegion(withoutDisabled, effectiveRegion)
142-
return filterByLocale(byRegion, language)
143-
}, [enabled, disabled, language, effectiveRegion, getAllApps])
122+
return filterByRegion(withoutDisabled, effectiveRegion)
123+
}, [enabled, disabled, effectiveRegion, getAllApps])
144124

145125
const disabledApps = useMemo(
146-
() => filterByLocale(filterByRegion(mapApps(disabled), effectiveRegion), language),
147-
[disabled, language, effectiveRegion, mapApps]
126+
() => filterByRegion(mapApps(disabled), effectiveRegion),
127+
[disabled, effectiveRegion, mapApps]
148128
)
149129
// Pinned apps are always visible regardless of region/language
150130
// User explicitly pinned apps should not be hidden
151131
const pinnedApps = useMemo(() => mapApps(pinned), [pinned, mapApps])
152132

153133
// Get hidden apps for preserving user preferences when writing
154-
const getHiddenApps = useCallback((language: LanguageVarious, region: DetectedRegion) => {
155-
const localeHidden = getLocaleHiddenApps(language)
134+
const getHiddenApps = useCallback((region: DetectedRegion) => {
156135
const regionHidden = getRegionHiddenApps(region)
157-
const hiddenIds = new Set([...localeHidden, ...regionHidden].map((app) => app.id))
136+
const hiddenIds = new Set(regionHidden.map((app) => app.id))
158137
return hiddenIds
159138
}, [])
160139

@@ -163,7 +142,7 @@ export const useMinapps = () => {
163142
const disabledIds = new Set(disabled.map((app) => app.id))
164143
const withoutDisabled = visibleApps.filter((app) => !disabledIds.has(app.id))
165144

166-
const hiddenIds = getHiddenApps(language, effectiveRegion)
145+
const hiddenIds = getHiddenApps(effectiveRegion)
167146
const preservedHidden = enabled.filter((app) => hiddenIds.has(app.id) && !disabledIds.has(app.id))
168147

169148
const visibleIds = new Set(withoutDisabled.map((app) => app.id))
@@ -175,35 +154,35 @@ export const useMinapps = () => {
175154

176155
dispatch(setMinApps([...merged, ...missingApps]))
177156
},
178-
[dispatch, enabled, disabled, language, effectiveRegion, getHiddenApps]
157+
[dispatch, enabled, disabled, effectiveRegion, getHiddenApps]
179158
)
180159

181160
// WRITE: Update disabled apps, preserving hidden disabled apps
182161
const updateDisabledMinapps = useCallback(
183162
(visibleDisabledApps: MinAppType[]) => {
184-
const hiddenIds = getHiddenApps(language, effectiveRegion)
163+
const hiddenIds = getHiddenApps(effectiveRegion)
185164
const preservedHidden = disabled.filter((app) => hiddenIds.has(app.id))
186165

187166
const visibleIds = new Set(visibleDisabledApps.map((app) => app.id))
188167
const toAppend = preservedHidden.filter((app) => !visibleIds.has(app.id))
189168

190169
dispatch(setDisabledMinApps([...visibleDisabledApps, ...toAppend]))
191170
},
192-
[dispatch, disabled, language, effectiveRegion, getHiddenApps]
171+
[dispatch, disabled, effectiveRegion, getHiddenApps]
193172
)
194173

195174
// WRITE: Update pinned apps, preserving hidden pinned apps
196175
const updatePinnedMinapps = useCallback(
197176
(visiblePinnedApps: MinAppType[]) => {
198-
const hiddenIds = getHiddenApps(language, effectiveRegion)
177+
const hiddenIds = getHiddenApps(effectiveRegion)
199178
const preservedHidden = pinned.filter((app) => hiddenIds.has(app.id))
200179

201180
const visibleIds = new Set(visiblePinnedApps.map((app) => app.id))
202181
const toAppend = preservedHidden.filter((app) => !visibleIds.has(app.id))
203182

204183
dispatch(setPinnedMinApps([...visiblePinnedApps, ...toAppend]))
205184
},
206-
[dispatch, pinned, language, effectiveRegion, getHiddenApps]
185+
[dispatch, pinned, effectiveRegion, getHiddenApps]
207186
)
208187

209188
return {

0 commit comments

Comments
 (0)