Add search param state management
cgen-57d716cbe2fd40efa27ad09f8429bde8
This commit is contained in:
parent
787ab10e31
commit
c1f011e450
1 changed files with 43 additions and 18 deletions
|
|
@ -88,6 +88,8 @@ export default function Dashboard() {
|
||||||
const [userPosts, setUserPosts] = useState<any[]>([]);
|
const [userPosts, setUserPosts] = useState<any[]>([]);
|
||||||
const [applications, setApplications] = useState<any[]>([]);
|
const [applications, setApplications] = useState<any[]>([]);
|
||||||
const [connectionAction, setConnectionAction] = useState<string | null>(null);
|
const [connectionAction, setConnectionAction] = useState<string | null>(null);
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
const [activeTab, setActiveTab] = useState(() => searchParams.get("tab") ?? "profile");
|
||||||
|
|
||||||
const linkedProviderMap = useMemo(() => {
|
const linkedProviderMap = useMemo(() => {
|
||||||
const map: Record<string, (typeof linkedProviders)[number]> = {};
|
const map: Record<string, (typeof linkedProviders)[number]> = {};
|
||||||
|
|
@ -97,24 +99,47 @@ export default function Dashboard() {
|
||||||
return map;
|
return map;
|
||||||
}, [linkedProviders]);
|
}, [linkedProviders]);
|
||||||
|
|
||||||
const oauthConnections = useMemo(
|
useEffect(() => {
|
||||||
() =>
|
const paramTab = searchParams.get("tab") ?? "profile";
|
||||||
[
|
if (paramTab !== activeTab) {
|
||||||
{
|
setActiveTab(paramTab);
|
||||||
provider: "google" as ProviderKey,
|
}
|
||||||
name: "Google",
|
}, [searchParams, activeTab]);
|
||||||
description: "Link your Google account for one-click access.",
|
|
||||||
Icon: Globe,
|
const handleTabChange = (value: string) => {
|
||||||
gradient: "from-red-500 to-yellow-500",
|
setActiveTab(value);
|
||||||
},
|
const next = new URLSearchParams(searchParams);
|
||||||
{
|
if (value === "profile") {
|
||||||
provider: "github" as ProviderKey,
|
if (next.has("tab")) {
|
||||||
name: "GitHub",
|
next.delete("tab");
|
||||||
description: "Connect your GitHub account to sync contributions.",
|
setSearchParams(next, { replace: true });
|
||||||
Icon: Github,
|
}
|
||||||
gradient: "from-gray-600 to-gray-900",
|
return;
|
||||||
},
|
}
|
||||||
] as const,
|
|
||||||
|
if (next.get("tab") !== value) {
|
||||||
|
next.set("tab", value);
|
||||||
|
setSearchParams(next, { replace: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const oauthConnections = useMemo<readonly ProviderDescriptor[]>(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
provider: "google",
|
||||||
|
name: "Google",
|
||||||
|
description: "Link your Google account for one-click access.",
|
||||||
|
Icon: Globe,
|
||||||
|
gradient: "from-red-500 to-yellow-500",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provider: "github",
|
||||||
|
name: "GitHub",
|
||||||
|
description: "Connect your GitHub account to sync contributions.",
|
||||||
|
Icon: Github,
|
||||||
|
gradient: "from-gray-600 to-gray-900",
|
||||||
|
},
|
||||||
|
],
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue