Skip to content

Commit

Permalink
Refactor Link imports to use custom Link component and integrate view…
Browse files Browse the repository at this point in the history
… transitions
  • Loading branch information
IgorKowalczyk committed Jan 2, 2025
1 parent f480195 commit 48c9b27
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { allBlogs } from "contentlayer/generated";
import "styles/blog.css";
import { Metadata } from "next";
import Image from "next/image";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Header1 } from "@/components/Headers";
import Link from "@/components/Link";
import { MDXComponent } from "@/components/MDXComponents";
import { meta } from "@/config";
import { cn } from "@/lib/utils";
Expand Down
2 changes: 1 addition & 1 deletion app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { allBlogs } from "contentlayer/generated";
import { pick } from "contentlayer2/client";
import Link from "next/link";
import { Icons } from "../../components/Icons";
import { Description, Header1, Header2 } from "@/components/Headers";
import Link from "@/components/Link";
import { parseISO } from "@/lib/utils";

export const metadata = {
Expand Down
3 changes: 2 additions & 1 deletion app/contact/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function Page() {
<div className="mt-4 flex flex-wrap gap-4">
{contact.links.map((element) => (
<Button variant="tertiary" href={element.href} key={`contact-link-${element.href}`} className="gap-2">
{element.icon} {element.title}
<element.icon className="size-5" />
{element.title}
</Button>
))}
</div>
Expand Down
45 changes: 24 additions & 21 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Analytics } from "@vercel/analytics/react";
import { GeistMono } from "geist/font/mono";
import Script from "next/script";
import { ThemeProvider } from "next-themes";
import { ViewTransitions } from "next-view-transitions";
import { Nav } from "@/components/client/Nav";
import { Providers } from "@/components/client/Providers";
import { Footer } from "@/components/Footer";
Expand Down Expand Up @@ -55,11 +56,12 @@ export const viewport = {

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
{process.env.HOTJAR_ID && (
<Script strategy="afterInteractive" id="hotjar">
{`
<ViewTransitions>
<html lang="en" suppressHydrationWarning>
<head>
{process.env.HOTJAR_ID && (
<Script strategy="afterInteractive" id="hotjar">
{`
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:${process.env.HOTJAR_ID},hjsv:6};
Expand All @@ -69,21 +71,22 @@ export default function RootLayout({ children }: { children: React.ReactNode })
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
`}
</Script>
)}
</head>
<body className={cn("antialiase relative scroll-smooth px-6 font-mono", GeistMono.variable)}>
<ThemeProvider attribute="class" disableTransitionOnChange>
<Providers>
<Nav />
<main className="mx-auto min-h-screen w-full max-w-screen-md">{children}</main>
<div className="noise pointer-events-none absolute inset-0" />
<div className="color-rays" />
<Footer />
<Analytics />
</Providers>
</ThemeProvider>
</body>
</html>
</Script>
)}
</head>
<body className={cn("antialiase relative scroll-smooth px-6 font-mono", GeistMono.variable)}>
<ThemeProvider attribute="class" disableTransitionOnChange>
<Providers>
<Nav />
<main className="mx-auto min-h-screen w-full max-w-screen-md">{children}</main>
<div className="noise pointer-events-none absolute inset-0" />
<div className="color-rays" />
<Footer />
<Analytics />
</Providers>
</ThemeProvider>
</body>
</html>
</ViewTransitions>
);
}
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Image from "next/image";
import Link from "next/link";
import { Button } from "../components/Button";
import { Icons } from "../components/Icons";
import { ContactForm } from "@/components/client/ContactForm";
import { Description, Header2 } from "@/components/Headers";
import Link from "@/components/Link";
import { ProjectCard } from "@/components/ProjectCard";
import { projects } from "@/config";
import { header, contact, meta, technologies } from "@/config";
Expand Down
2 changes: 1 addition & 1 deletion app/photography/components/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import { Masonry } from "react-plock";
import Link from "@/components/Link";
import type { Photo } from "@/lib/getPhotography";

export const Grid = ({ photos }: { photos: Photo[] }) => {
Expand Down
2 changes: 1 addition & 1 deletion app/uses/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { allOtherPages } from "contentlayer/generated";
import Image from "next/image";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Header1 } from "@/components/Headers";
import Link from "@/components/Link";
import { MDXComponent } from "@/components/MDXComponents";
import setup from "@/public/assets/setup.jpg";

Expand Down
2 changes: 1 addition & 1 deletion components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cva, VariantProps } from "class-variance-authority";
import Link from "next/link";
import React from "react";
import { Icons } from "@/components/Icons";
import Link from "@/components/Link";
import { cn } from "@/lib/utils";

export const buttonVariants = cva("group flex w-fit items-center rounded-md px-4 py-2 font-medium duration-200 disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none", {
Expand Down
2 changes: 1 addition & 1 deletion components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Link from "next/link";
import Link from "@/components/Link";
import { footer } from "@/config";

export function Footer() {
Expand Down
2 changes: 1 addition & 1 deletion components/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cn } from "@/lib/utils";
import type { LucideIcon } from "lucide-react";
import * as LucideIcons from "lucide-react";
import { cn } from "@/lib/utils";

export type Icon = LucideIcon;

Expand Down
17 changes: 17 additions & 0 deletions components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import NextLink, { LinkProps as NextLinkProps } from "next/link";
import { Link as TransitionLink } from "next-view-transitions";
import { forwardRef } from "react";

type LinkProps = NextLinkProps & React.AnchorHTMLAttributes<HTMLAnchorElement>;

const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(props, ref) {
const { href, ...rest } = props;

if (typeof href === "string" && href.startsWith("#")) {
return <NextLink {...rest} href={href} ref={ref} />;
}

return <TransitionLink {...rest} href={href} ref={ref} />;
});

export default Link;
4 changes: 2 additions & 2 deletions components/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Image from "next/image";
import Link from "next/link";
import { Icons } from "./Icons";
import { Button } from "@/components/Button";
import { type Project } from "@/config";
import Link from "@/components/Link";
import type { Project } from "@/lib/types";
import { parseISO } from "@/lib/utils";

export interface ProjectCardProps extends React.HTMLAttributes<HTMLDivElement> {
Expand Down
2 changes: 1 addition & 1 deletion components/client/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import MobileNav from "@/components/client/MobileNav";
import Popover from "@/components/client/NavPopover";
import Settings from "@/components/client/Settings";
import Link from "@/components/Link";
import { nav } from "@/config";
import { cn } from "@/lib/utils";

Expand Down
2 changes: 1 addition & 1 deletion components/client/NavPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { Transition, Popover, PopoverButton, PopoverPanel, PopoverProps } from "@headlessui/react";
import Link from "next/link";
import { Icons } from "../Icons";
import Link from "@/components/Link";
import { meta } from "@/config";

export default function NavPopover(props: PopoverProps) {
Expand Down
2 changes: 1 addition & 1 deletion components/client/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";

import { Dialog, DialogPanel, DialogTitle, DialogBackdrop, Description } from "@headlessui/react";
import Link from "next/link";
import { useTheme } from "next-themes";
import { useState } from "react";
import { useEffect } from "react";
import { Icons } from "../Icons";
import { Button } from "@/components/Button";
import Select from "@/components/client/Select";
import Switch from "@/components/client/Switch";
import Link from "@/components/Link";
import { meta } from "@/config";
import { cn } from "@/lib/utils";

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"next-contentlayer2": "0.5.3",
"next-nprogress-bar": "2.4.3",
"next-themes": "0.4.4",
"next-view-transitions": "0.3.4",
"nprogress": "0.2.0",
"react": "19.0.0",
"react-dom": "19.0.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48c9b27

Please sign in to comment.