(onChange?: () => void)
| 32 | |
| 33 | /** The feed's sort, held where the sort dropdown has always kept it. */ |
| 34 | export const useForYouSort = (onChange?: () => void): ForYouSort => { |
| 35 | const { sortingEnabled } = useSettingsContext(); |
| 36 | const [selectedAlgo, setSelectedAlgo] = usePersistentContext( |
| 37 | DEFAULT_ALGORITHM_KEY, |
| 38 | DEFAULT_ALGORITHM_INDEX, |
| 39 | [0, 1], |
| 40 | DEFAULT_ALGORITHM_INDEX, |
| 41 | ); |
| 42 | const onSelect = useCallback( |
| 43 | (index: number) => { |
| 44 | if (index !== selectedAlgo) { |
| 45 | setSelectedAlgo(index).catch(() => undefined); |
| 46 | onChange?.(); |
| 47 | } |
| 48 | }, |
| 49 | [onChange, selectedAlgo, setSelectedAlgo], |
| 50 | ); |
| 51 | |
| 52 | return { |
| 53 | canSort: !!sortingEnabled, |
| 54 | selected: sortingEnabled ? selectedAlgo : DEFAULT_ALGORITHM_INDEX, |
| 55 | onSelect, |
| 56 | }; |
| 57 | }; |
| 58 | |
| 59 | /** The phone's For you tab, a button for the For you sheet. */ |
| 60 | export const getForYouMenuAriaLabel = ({ |
no test coverage detected