@@ -52,9 +52,9 @@ interface Sorts {
5252 communities : CommunitySortType ;
5353}
5454
55- export default function useFeedSort <
56- Context extends "posts" | "comments" | "search" | "communities" ,
57- > (
55+ export type FeedSortContext = "posts" | "comments" | "search" | "communities" ;
56+
57+ export default function useFeedSort < Context extends FeedSortContext > (
5858 context : Context ,
5959 feed ?: AnyFeed | undefined ,
6060 overrideSort ?: VgerSorts [ Context ] ,
@@ -72,7 +72,9 @@ export default function useFeedSort<
7272 mode ? state . settings . general [ context ] . sort [ mode ] : undefined ,
7373 ) as Sort | undefined ;
7474 const rememberCommunitySort = useAppSelector (
75- ( state ) => state . settings . general [ context ] . rememberCommunitySort ,
75+ ( state ) =>
76+ state . settings . general [ findFeedContext ( feed ) ?? context ]
77+ . rememberCommunitySort ,
7678 ) ;
7779
7880 const [ sort , _setSort ] = useState < Sort | undefined > (
@@ -127,9 +129,29 @@ export default function useFeedSort<
127129 return [ sort , setSort ] as const ;
128130}
129131
130- export function useFeedSortParams <
131- Context extends "posts" | "comments" | "search" | "communities" ,
132- > (
132+ function findFeedContext (
133+ feed : AnyFeed | undefined ,
134+ ) : FeedSortContext | undefined {
135+ if ( ! feed ) return ;
136+ if ( ! ( "internal" in feed ) ) return ;
137+
138+ switch ( feed . internal ) {
139+ case "CommentsSearch" :
140+ return "comments" ;
141+ case "PostsSearch" :
142+ return "posts" ;
143+ case "CommunitiesSearch" :
144+ return "communities" ;
145+ case "CommunitiesExplore" :
146+ return "communities" ;
147+ case "ProfilePosts" :
148+ return "posts" ;
149+ case "ProfileComments" :
150+ return "comments" ;
151+ }
152+ }
153+
154+ export function useFeedSortParams < Context extends FeedSortContext > (
133155 context : Context ,
134156 sort : VgerSorts [ Context ] | undefined ,
135157) : Sorts [ Context ] | undefined {
@@ -140,9 +162,11 @@ export function useFeedSortParams<
140162 return convertSortToLemmyParams ( context , sort , mode ) ;
141163}
142164
143- function convertSortToLemmyParams <
144- Context extends "posts" | "comments" | "search" | "communities" ,
145- > ( context : Context , sort : VgerSorts [ Context ] , mode : ThreadiverseMode ) {
165+ function convertSortToLemmyParams < Context extends FeedSortContext > (
166+ context : Context ,
167+ sort : VgerSorts [ Context ] ,
168+ mode : ThreadiverseMode ,
169+ ) {
146170 switch ( context ) {
147171 case "posts" :
148172 return convertPostSortToParams ( sort as VgerSorts [ "posts" ] , mode ) ;
0 commit comments