MCPcopy Create free account
hub / github.com/dailydotdev/apps / useForYouSort

Function useForYouSort

packages/shared/src/components/feeds/ForYouSort.tsx:34–57  ·  view source on GitHub ↗
(onChange?: () => void)

Source from the content-addressed store, hash-verified

32
33/** The feed's sort, held where the sort dropdown has always kept it. */
34export 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. */
60export const getForYouMenuAriaLabel = ({

Callers 2

FeedNavFunction · 0.90
HomeFeedTabsFunction · 0.90

Calls 3

useSettingsContextFunction · 0.90
usePersistentContextFunction · 0.85
onChangeFunction · 0.50

Tested by

no test coverage detected