Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysSullivan committed Oct 19, 2024
2 parents 17e8a3f + 2195653 commit 45aa9fb
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/(category-sidebar)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from "@/components/ui/link";
import { db } from "@/db";
import Link from "next/link";

export default async function Layout({
children,
Expand Down
2 changes: 1 addition & 1 deletion src/app/(category-sidebar)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Link from "next/link";
import { Link } from "@/components/ui/link";
import { db } from "@/db";
import Image from "next/image";

Expand Down
2 changes: 1 addition & 1 deletion src/app/(category-sidebar)/products/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@/db/schema";
import { count, eq } from "drizzle-orm";
import Image from "next/image";
import Link from "next/link";
import { Link } from "@/components/ui/link";
import { notFound } from "next/navigation";

export default async function Page(props: {
Expand Down
1 change: 1 addition & 0 deletions src/app/auth.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LoginForm, SignInSignUp, SignOut } from "./auth.client";

export async function AuthServer() {
const user = await getUser();
// TODO: Could dynamic load the sign-in/sign-up and sign-out components as they're not used on initial render
if (!user) {
return <SignInSignUp />;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Metadata, Viewport } from "next";
import localFont from "next/font/local";
import "./globals.css";
import Link from "next/link";
import { SearchDropdownComponent } from "@/components/search-dropdown";
import { MenuIcon } from "lucide-react";
import { Suspense } from "react";
import { Cart } from "@/components/cart";
import { AuthServer } from "./auth.server";
import { Link } from "@/components/ui/link";

const helvetica = localFont({
src: "./fonts/HelveticaNeueLTPro-Md.woff",
Expand Down
2 changes: 1 addition & 1 deletion src/app/order/dynamic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cache } from "react";
import { detailedCart } from "@/lib/cart";
import Link from "next/link";
import { Link } from "@/components/ui/link";
import Image from "next/image";
import { removeFromCart } from "@/lib/actions";
import { X } from "lucide-react";
Expand Down
2 changes: 1 addition & 1 deletion src/components/search-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Image from "next/image";
import { cn } from "@/lib/utils";
import { Product } from "../db/schema";
import { searchProducts } from "../lib/actions";
import Link from "next/link";
import { Link } from "@/components/ui/link";
import { useParams, useRouter } from "next/navigation";

type SearchResult = Product & { href: string };
Expand Down
29 changes: 29 additions & 0 deletions src/components/ui/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import NextLink from "next/link";
import { useRouter } from "next/navigation";

export const Link: typeof NextLink = (({ children, ...props }) => {
const router = useRouter();
return (
<NextLink
onMouseDown={(e) => {
const url = new URL(String(props.href), window.location.href);
if (
url.origin === window.location.origin &&
e.button === 0 &&
!e.altKey &&
!e.ctrlKey &&
!e.metaKey &&
!e.shiftKey
) {
e.preventDefault();
router.push(String(props.href));
}
}}
{...props}
>
{children}
</NextLink>
);
}) as typeof NextLink;
2 changes: 1 addition & 1 deletion src/components/ui/product-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Link from "next/link";
import { Link } from "@/components/ui/link";
import Image from "next/image";
import { Product } from "@/db/schema";
export function ProductLink(props: {
Expand Down

0 comments on commit 45aa9fb

Please sign in to comment.