this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve sort & filter of language options in search (#5709)

authored by

Paul Frazee and committed by
GitHub
5ebb630c 9a769b9a

+20 -3
+20 -3
src/view/screens/Search/Search.tsx
··· 22 22 import AsyncStorage from '@react-native-async-storage/async-storage' 23 23 import {useFocusEffect, useNavigation} from '@react-navigation/native' 24 24 25 - import {LANGUAGES} from '#/lib/../locale/languages' 25 + import {APP_LANGUAGES, LANGUAGES} from '#/lib/../locale/languages' 26 26 import {createHitslop} from '#/lib/constants' 27 27 import {HITSLOP_10} from '#/lib/constants' 28 28 import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' ··· 349 349 key: '*', 350 350 }, 351 351 ].concat( 352 - LANGUAGES.filter(l => Boolean(l.code2)) 352 + LANGUAGES.filter( 353 + (lang, index, self) => 354 + Boolean(lang.code2) && // reduce to the code2 varieties 355 + index === self.findIndex(t => t.code2 === lang.code2), // remove dupes (which will happen) 356 + ) 353 357 .map(l => ({ 354 358 label: l.name, 355 359 inputLabel: l.name, 356 360 value: l.code2, 357 361 key: l.code2 + l.code3, 358 362 })) 359 - .sort(a => (contentLanguages.includes(a.value) ? -1 : 1)), 363 + .sort((a, b) => { 364 + // prioritize user's languages 365 + const aIsUser = contentLanguages.includes(a.value) 366 + const bIsUser = contentLanguages.includes(b.value) 367 + if (aIsUser && !bIsUser) return -1 368 + if (bIsUser && !aIsUser) return 1 369 + // prioritize "common" langs in the network 370 + const aIsCommon = !!APP_LANGUAGES.find(al => al.code2 === a.value) 371 + const bIsCommon = !!APP_LANGUAGES.find(al => al.code2 === b.value) 372 + if (aIsCommon && !bIsCommon) return -1 373 + if (bIsCommon && !aIsCommon) return 1 374 + // fall back to alphabetical 375 + return a.label.localeCompare(b.label) 376 + }), 360 377 ) 361 378 }, [_, contentLanguages]) 362 379