Skip to content

Commit

Permalink
Store feed page in url
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanv committed Aug 26, 2024
1 parent ef7b82c commit 0ecb946
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions frontend/src/components/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import PageWithHeader from "./PageWithHeader";
const Home: React.FC = () => {
usePageTitle("My Feed");
const [urlParams, setUrlParams] = useSearchParams();
const [page, setPage] = useState(1);
const [searchParams, setSearchParams] = useState<
Omit<SearchParams, "searchText">
>({
Expand All @@ -21,6 +20,10 @@ const Home: React.FC = () => {
});
const searchText = urlParams.get("s") || "";
const tagId = urlParams.get("t") || undefined;
const page = parseInt(urlParams.get("p") || "1");
const setPage = (p: number) => {
setUrlParams({ ...urlParams, p: p.toString() });
};

const {
loading: feedLoading,
Expand All @@ -36,14 +39,14 @@ const Home: React.FC = () => {

const handleSearchParamsChange = (newSearchParams: SearchParams) => {
setSearchParams(newSearchParams);
const newParams: {[key: string]: string} = {
const newParams: { [key: string]: string } = {
s: newSearchParams.searchText,
}
p: "1",
};
if (newSearchParams.tagId) {
newParams['t'] = newSearchParams.tagId;
newParams["t"] = newSearchParams.tagId;
}
setUrlParams(newParams);
setPage(1);
};

const renderContent = () => {
Expand Down

0 comments on commit 0ecb946

Please sign in to comment.