QueryParams,
relTags,
restoreScrollPosition,
- routeDataTypeToEnum,
- routeListingTypeToEnum,
- routeSortTypeToEnum,
saveCommentRes,
saveScrollPosition,
setIsoData,
page: number;
}
-const getDataTypeFromQuery = (type?: string) =>
- routeDataTypeToEnum(type ?? "", DataType.Post);
+function getDataTypeFromQuery(type?: string): DataType {
+ return type ? DataType[type] : DataType.Post;
+}
-function getListingTypeFromQuery(type?: string) {
- const mui = UserService.Instance.myUserInfo;
+function getListingTypeFromQuery(type?: string): ListingType {
+ const myListingType =
+ UserService.Instance.myUserInfo?.local_user_view?.local_user
+ ?.default_listing_type;
- return routeListingTypeToEnum(
- type ?? "",
- mui
- ? Object.values(ListingType)[
- mui.local_user_view.local_user.default_listing_type
- ]
- : ListingType.Local
- );
+ return type ? (type as ListingType) : myListingType ?? "Local";
}
-function getSortTypeFromQuery(type?: string) {
- const mui = UserService.Instance.myUserInfo;
+function getSortTypeFromQuery(type?: string): SortType {
+ const mySortType =
+ UserService.Instance.myUserInfo?.local_user_view?.local_user
+ ?.default_sort_type;
- return routeSortTypeToEnum(
- type ?? "",
- mui
- ? Object.values(SortType)[
- mui.local_user_view.local_user.default_listing_type
- ]
- : SortType.Active
- );
+ return type ? (type as SortType) : mySortType ?? "Active";
}
const getHomeQueryParams = () =>
function fetchTrendingCommunities() {
const listCommunitiesForm: ListCommunities = {
- type_: ListingType.Local,
- sort: SortType.Hot,
+ type_: "Local",
+ sort: "Hot",
limit: trendingFetchLimit,
auth: myAuth(false),
};
let rss: string | undefined = undefined;
switch (listingType) {
- case ListingType.All: {
+ case "All": {
rss = `/feeds/all.xml?sort=${sort}`;
break;
}
- case ListingType.Local: {
+ case "Local": {
rss = `/feeds/local.xml?sort=${sort}`;
break;
}
- case ListingType.Subscribed: {
+ case "Subscribed": {
rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
break;
}
}
const trendingCommunitiesForm: ListCommunities = {
- type_: ListingType.Local,
- sort: SortType.Hot,
+ type_: "Local",
+ sort: "Hot",
limit: trendingFetchLimit,
auth,
};
let shouldAddPost: boolean;
switch (listingType) {
- case ListingType.Subscribed: {
+ case "Subscribed": {
// If you're on subscribed, only push it if you're subscribed.
shouldAddPost = !!mui?.follows.some(
({ community: { id } }) => id === post_view.community.id
);
break;
}
- case ListingType.Local: {
+ case "Local": {
// If you're on the local view, only push it if its local
shouldAddPost = post_view.post.local;
break;
// If you're on subscribed, only push it if you're subscribed.
const shouldAddComment =
- listingType === ListingType.Subscribed
+ listingType === "Subscribed"
? UserService.Instance.myUserInfo?.follows.some(
({ community: { id } }) => id === comment_view.community.id
)