Skip to content

Commit

Permalink
feat: profile/Tabs - addToNavigationHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
weiwei2694 committed Oct 21, 2023
1 parent f27eb17 commit e36cbd0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/profile/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";
import { cn } from "@/lib/utils";
import { usePrevious } from "@/hooks/usePrevious";
import { cn, getCurrentPath } from "@/lib/utils";
import Link from "next/link";
import { usePathname } from "next/navigation";
import React from "react";
import { useTransition } from "react";

interface TabsProps {
username: string;
Expand All @@ -16,10 +17,20 @@ interface TabProps {

const Tab = ({ title, href, path }: TabProps) => {
const isSamePath = path === href;
const { addToNavigationHistory } = usePrevious();
const [isPending, startTransition] = useTransition();

return (
<Link
href={href}
onClick={e => {
if (isPending) return;

e.stopPropagation();
startTransition(() => {
addToNavigationHistory(getCurrentPath());
})
}}
className="flex-1 flex justify-center cursor-pointer hover:bg-gray-300 transition"
>
<p
Expand Down

0 comments on commit e36cbd0

Please sign in to comment.