Skip to content

Commit

Permalink
feat: introduce custom Link component with hover-only prefetching
Browse files Browse the repository at this point in the history
  • Loading branch information
simonknittel committed Jan 6, 2025
1 parent 193d012 commit 0abeba6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/app/app/spynet/citizen/_components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Actions } from "@/common/components/Actions";
import { Link } from "@/common/components/Link";
import { type Entity, type Role } from "@prisma/client";
import Link from "next/link";
import { Suspense } from "react";
import { FaExternalLinkAlt, FaSortDown, FaSortUp } from "react-icons/fa";
import { HistoryModal } from "../../entity/[id]/_components/generic-log-type/HistoryModal";
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/app/spynet/notes/_components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Actions } from "@/common/components/Actions";
import { Link } from "@/common/components/Link";
import {
type ClassificationLevel,
type Entity,
Expand All @@ -7,7 +8,6 @@ import {
type NoteType,
type User,
} from "@prisma/client";
import Link from "next/link";
import { FaSortDown, FaSortUp } from "react-icons/fa";
import { type EntityLogConfirmationState } from "../../../../../types";
import ConfirmationState from "./ConfirmationState";
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/app/spynet/other/_components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Actions } from "@/common/components/Actions";
import { Link } from "@/common/components/Link";
import { entityLogTypeTranslations } from "@/common/utils/entityLogTypeTranslations";
import type { EntityLogConfirmationState } from "@/types";
import {
Expand All @@ -7,7 +8,6 @@ import {
type EntityLogAttribute,
type User,
} from "@prisma/client";
import Link from "next/link";
import { FaSortDown, FaSortUp } from "react-icons/fa";
import ConfirmationState from "./ConfirmationState";
import DeleteLog from "./DeleteLog";
Expand Down
25 changes: 25 additions & 0 deletions app/src/common/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

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

type Props = ComponentProps<typeof NextLink>;

export const Link = (props: Props) => {
const { prefetch, href, onMouseEnter, ...rest } = props;
const router = useRouter();

return (
<NextLink
href={href}
prefetch={prefetch === undefined ? false : prefetch}
onMouseEnter={
prefetch === undefined && onMouseEnter === undefined
? () => router.prefetch(typeof href === "string" ? href : href.href)
: onMouseEnter
}
{...rest}
/>
);
};
2 changes: 1 addition & 1 deletion app/src/events/components/ParticipantsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RolesCell } from "@/app/app/spynet/citizen/_components/RolesCell";
import { requireAuthentication } from "@/auth/server";
import { Link } from "@/common/components/Link";
import { type getEvent } from "@/discord/utils/getEvent";
import type { memberSchema, userSchema } from "@/discord/utils/schemas";
import type { Entity } from "@prisma/client";
import clsx from "clsx";
import Image from "next/image";
import Link from "next/link";
import { Suspense } from "react";
import type { z } from "zod";
import { getParticipants } from "../utils/getParticipants";
Expand Down

0 comments on commit 0abeba6

Please sign in to comment.