1- import { useMemo , useRef } from 'react'
1+ import { useCallback , useMemo , useRef } from 'react'
22
33import {
44 getFeedQueryKey ,
@@ -24,6 +24,7 @@ import { TrackLineup } from 'components/lineup/TrackLineup'
2424import { LineupVariant } from 'components/lineup/types'
2525import Page from 'components/page/Page'
2626import EmptyFeed from 'pages/feed-page/components/EmptyFeed'
27+ import { FeedFilters } from 'pages/feed-page/components/FeedFilters'
2728import { FeedTabs } from 'pages/feed-page/components/FeedTabs'
2829
2930const messages = {
@@ -32,17 +33,12 @@ const messages = {
3233 feedDescription : 'Listen to what people you follow are sharing'
3334}
3435
35- const { getFeedTab } = feedPageSelectors
36+ const { getFeedTab, getFeedFilter } = feedPageSelectors
3637
3738type FeedPageContentProps = {
3839 containerRef ?: React . RefObject < HTMLDivElement >
3940}
4041
41- const tabToFilter : Record < Exclude < FeedTab , FeedTab . FOR_YOU > , FeedFilter > = {
42- [ FeedTab . FOLLOWING ] : FeedFilter . ALL ,
43- [ FeedTab . UPLOADS_ONLY ] : FeedFilter . ORIGINAL
44- }
45-
4642// Note: the feed API returns both tracks and collections (playlist reposts).
4743// The new TrackLineup renders tracks only, so collections are filtered out by
4844// `trackIds` on the hook side. This is a known limitation introduced by the
@@ -51,28 +47,30 @@ const tabToFilter: Record<Exclude<FeedTab, FeedTab.FOR_YOU>, FeedFilter> = {
5147const FeedPageContent = ( { containerRef } : FeedPageContentProps ) => {
5248 const dispatch = useDispatch ( )
5349 const titleRowRef = useRef < HTMLDivElement > ( null )
54- const feedTab = useSelector ( getFeedTab )
50+ const persistedTab = useSelector ( getFeedTab )
51+ const feedFilter = useSelector ( getFeedFilter )
5552 const { data : currentUserId } = useCurrentUserId ( )
5653
5754 // Desktop viewports + fast trackpad / wheel scroll need bigger pages than
5855 // the shared default (mobile-tuned) so successive load-mores keep up with a
5956 // user scrolling deep into the lineup.
6057 const desktopLoadMorePageSize = 10
6158
59+ // Coerce legacy persisted FeedTab values (FOLLOWING / UPLOADS_ONLY) to
60+ // CHRONOLOGICAL after the For You / Chronological refactor.
61+ const feedTab =
62+ persistedTab === FeedTab . FOR_YOU ? FeedTab . FOR_YOU : FeedTab . CHRONOLOGICAL
6263 const isForYou = feedTab === FeedTab . FOR_YOU
63- const followingFilter = isForYou
64- ? FeedFilter . ALL
65- : tabToFilter [ feedTab as Exclude < FeedTab , FeedTab . FOR_YOU > ]
6664
67- // Following / Uploads-Only lineup. Disabled while For You is active.
65+ // Chronological lineup. Disabled while For You is active.
6866 const feedArgs = useMemo (
6967 ( ) => ( {
7068 userId : currentUserId ,
71- filter : followingFilter ,
69+ filter : feedFilter ,
7270 initialPageSize : FEED_INITIAL_PAGE_SIZE ,
7371 loadMorePageSize : desktopLoadMorePageSize
7472 } ) ,
75- [ followingFilter , currentUserId ]
73+ [ feedFilter , currentUserId ]
7674 )
7775 const followFeed = useFeed ( feedArgs , { enabled : ! isForYou } )
7876
@@ -91,13 +89,24 @@ const FeedPageContent = ({ containerRef }: FeedPageContentProps) => {
9189 )
9290
9391 const record = useRecord ( )
94- const onSelectTab = ( tab : FeedTab ) => {
95- if ( containerRef ?. current ?. scrollTo ) {
96- containerRef . current . scrollTo ( 0 , 0 )
97- }
98- dispatch ( discoverPageAction . setFeedTab ( tab ) )
99- record ( make ( Name . FEED_CHANGE_VIEW , { view : tab } ) )
100- }
92+ const onSelectTab = useCallback (
93+ ( tab : FeedTab ) => {
94+ if ( containerRef ?. current ?. scrollTo ) {
95+ containerRef . current . scrollTo ( 0 , 0 )
96+ }
97+ dispatch ( discoverPageAction . setFeedTab ( tab ) )
98+ record ( make ( Name . FEED_CHANGE_VIEW , { view : tab } ) )
99+ } ,
100+ [ containerRef , dispatch , record ]
101+ )
102+
103+ const onSelectFilter = useCallback (
104+ ( filter : FeedFilter ) => {
105+ dispatch ( discoverPageAction . setFeedFilter ( filter ) )
106+ record ( make ( Name . FEED_CHANGE_VIEW , { view : filter } ) )
107+ } ,
108+ [ dispatch , record ]
109+ )
101110
102111 const header = (
103112 < Header
@@ -107,6 +116,14 @@ const FeedPageContent = ({ containerRef }: FeedPageContentProps) => {
107116 rightDecorator = {
108117 < FeedTabs currentTab = { feedTab } onSelectTab = { onSelectTab } />
109118 }
119+ bottomBar = {
120+ isForYou ? null : (
121+ < FeedFilters
122+ currentFilter = { feedFilter }
123+ onSelectFilter = { onSelectFilter }
124+ />
125+ )
126+ }
110127 />
111128 )
112129
0 commit comments