-
+ {}}>
받은 떡국 재료
내가 응원한 떡국
diff --git a/src/pages/MyActivityPage.tsx b/src/pages/MyActivityPage.tsx
index 9b6e48e..954b963 100644
--- a/src/pages/MyActivityPage.tsx
+++ b/src/pages/MyActivityPage.tsx
@@ -1,5 +1,6 @@
-import { Fragment, useRef, useState } from "react";
+import { Fragment, useEffect, useRef, useState } from "react";
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
+import { useSearchParams } from "react-router-dom";
import classNames from "classnames";
import { useAtomValue } from "jotai";
@@ -15,7 +16,12 @@ import Loading from "@/components/common/Loading";
import MySupportedTteokgukCardList from "@/components/MyActivity/MySupportedTteokgukCardList";
const MyActivityPage = () => {
- const [tabIndex, setTabIndex] = useState(0);
+ const tabParams = ["ingredient", "support"];
+
+ const [searchParams, setSearchParams] = useSearchParams();
+ const tabParam = searchParams.get("tab") ?? "";
+ const tabIndexByParam = tabParams.indexOf(tabParam);
+ const [tabIndex, setTabIndex] = useState(tabIndexByParam === -1 ? 0 : tabIndexByParam);
const isSelectedTab = (index: number) => index === tabIndex;
const {
mySupportedTteokguks,
@@ -36,6 +42,11 @@ const MyActivityPage = () => {
const isFetchingNextPage =
isReceivedTteokgukFetchingNextPage || isMySupportedTteokgukFetchingNextPage;
+ const handleSelectTab = (index: number) => {
+ setSearchParams({ tab: tabParams[index] });
+ setTabIndex(index);
+ };
+
useIntersectionObserver({
target: fetchMoreRef,
handleIntersect:
@@ -44,11 +55,15 @@ const MyActivityPage = () => {
: () => handleSupportedTtoekguksIntersect({ enabled: isSelectedTab(1) }),
});
+ useEffect(() => {
+ setTabIndex(tabIndexByParam === -1 ? 0 : tabIndexByParam);
+ }, [tabIndexByParam, setTabIndex]);
+
return (
활동 내역
- setTabIndex(index)}>
+
받은 떡국 재료