Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into persist-share-as-im…
Browse files Browse the repository at this point in the history
…age-choices
  • Loading branch information
sharunkumar committed Aug 11, 2024
2 parents 29d1410 + b8f305c commit 6f423e3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.{js,ts,jsx,tsx,yaml,json}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
11 changes: 11 additions & 0 deletions src/features/feed/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { ListingType } from "lemmy-js-client";
import { getFeedUrlName } from "../community/mod/ModActions";

type InternalFeedType =
| "PostsSearch"
| "CommentsSearch"
| "CommunitiesSearch"
| "CommunitiesExplore";

export type AnyFeed =
| {
remoteCommunityHandle: string;
}
| {
listingType: ListingType;
}
| {
internal: InternalFeedType;
};

export function serializeFeedName(feed: AnyFeed): string {
Expand All @@ -15,6 +24,8 @@ export function serializeFeedName(feed: AnyFeed): string {
return feed.remoteCommunityHandle; // always contains @ - will never overlap with getFeedUrlName
case "listingType" in feed:
return getFeedUrlName(feed.listingType);
case "internal" in feed:
return `@@voyager_${feed.internal}`;
default:
return feed;
}
Expand Down
15 changes: 3 additions & 12 deletions src/features/post/appearance/appearanceSlice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PayloadAction, createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { ListingType } from "lemmy-js-client";
import { PostAppearanceType, db } from "../../../services/db";
import { serializeFeedName } from "../../feed/helpers";
import { AnyFeed, serializeFeedName } from "../../feed/helpers";

interface PostAppearanceState {
/**
Expand All @@ -21,7 +20,7 @@ export const postAppearanceSlice = createSlice({
setPostAppeartance: (
state,
action: PayloadAction<{
feed: FeedSortFeed;
feed: AnyFeed;
postAppearance: PostAppearanceType;
}>,
) => {
Expand All @@ -47,17 +46,9 @@ export const { setPostAppeartance } = postAppearanceSlice.actions;

export default postAppearanceSlice.reducer;

export type FeedSortFeed =
| {
remoteCommunityHandle: string;
}
| {
listingType: ListingType;
};

export const getPostAppearance = createAsyncThunk(
"postAppearance/getPostAppearance",
async (feed: FeedSortFeed) => {
async (feed: AnyFeed) => {
const feedName = serializeFeedName(feed);
const postAppearance =
(await db.getSetting("post_appearance_type", {
Expand Down
6 changes: 5 additions & 1 deletion src/routes/pages/search/CommunitiesResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export default function CommunitiesResultsPage({
}: CommunitiesResultsPageProps) {
const buildGeneralBrowseLink = useBuildGeneralBrowseLink();
const client = useClient();
const [sort, setSort] = useFeedSort("posts", undefined, "TopAll");
const [sort, setSort] = useFeedSort(
"posts",
{ internal: search ? "CommunitiesSearch" : "CommunitiesExplore" },
"TopAll",
);
const [listingType, setListingType] = useState<ListingType>("All");

const fetchFn: FetchFn<CommunityView> = useCallback(
Expand Down
4 changes: 3 additions & 1 deletion src/routes/pages/search/results/SearchFeedResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default function SearchFeedResultsPage({
}>();
const buildGeneralBrowseLink = useBuildGeneralBrowseLink();
const client = useClient();
const [sort, setSort] = useFeedSort("posts");
const [sort, setSort] = useFeedSort("posts", {
internal: `${type}Search`,
});

const search = decodeURIComponent(_encodedSearch);

Expand Down

0 comments on commit 6f423e3

Please sign in to comment.