Skip to content

Commit 7f21f53

Browse files
committed
fix search query
1 parent ade693d commit 7f21f53

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/components/SearchPage.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ const SearchPage: React.FC<SearchPageProps> = memo(({ query, sort: initialSort,
5555
const fetchPosts = useCallback(() => {
5656
if (!hasMore || !userQuery) return;
5757

58-
const isAlreadyEncoded = userQuery.match(/%[0-9A-F]{2}/i);
59-
const encodedQuery = isAlreadyEncoded ? encodeURIComponent(userQuery) : userQuery;
60-
6158
const searchUrl = subreddit
62-
? `https://www.reddit.com/r/${subreddit}/search.json?q=${encodedQuery}&after=${after}&sort=${sort}&t=${time}&restrict_sr=on`
63-
: `https://www.reddit.com/search.json?q=${encodedQuery}&after=${after}&sort=${sort}&t=${time}`;
59+
? `https://www.reddit.com/r/${subreddit}/search.json?q=${userQuery}&after=${after}&sort=${sort}&t=${time}&restrict_sr=on`
60+
: `https://www.reddit.com/search.json?q=${userQuery}&after=${after}&sort=${sort}&t=${time}`;
6461

6562
RedditApiClient.fetch(searchUrl)
6663
.then((response) => response.json())
@@ -74,8 +71,7 @@ const SearchPage: React.FC<SearchPageProps> = memo(({ query, sort: initialSort,
7471

7572
const fetchSubredditSuggestions = useCallback(() => {
7673
if (userQuery.trim() !== "") {
77-
const encodedQuery = encodeURIComponent(userQuery);
78-
const searchUrl = `https://www.reddit.com/search.json?q=${encodedQuery}&sort=${sort}&type=sr&sr_detail=true`;
74+
const searchUrl = `https://www.reddit.com/search.json?q=${userQuery}&sort=${sort}&type=sr&sr_detail=true`;
7975

8076
RedditApiClient.fetch(searchUrl)
8177
.then((response) => response.json())

0 commit comments

Comments
 (0)