Fix fast refresh by abstracting project/link types into types.ts

This commit is contained in:
Xevion
2022-12-30 16:59:12 -06:00
parent 57e5ead20d
commit 130e6a0020
3 changed files with 29 additions and 28 deletions

View File

@@ -5,8 +5,8 @@ import DependentImage from "./DependentImage";
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
import Link from "next/link"; import Link from "next/link";
import {LinkIcon, LinkIcons} from "../pages";
import {useRouter} from "next/router"; import {useRouter} from "next/router";
import {type LinkIcon, LinkIcons} from "../utils/types";
type ItemCardProps = { type ItemCardProps = {
banner: string; banner: string;
@@ -70,7 +70,7 @@ const ItemCard = ({banner, bannerBlur, title, description, links, location}: Ite
{links!.map(({icon, location, newTab}) => {links!.map(({icon, location, newTab}) =>
<Link key={location} href={location} target={(newTab ?? true) ? "_blank" : "_self"} <Link key={location} href={location} target={(newTab ?? true) ? "_blank" : "_self"}
onClick={e => e.stopPropagation()}> onClick={e => e.stopPropagation()}>
{LinkIcons[icon]!({})} {LinkIcons[icon]?.({})}
</Link>)} </Link>)}
</div> </div>
</div> : null} </div> : null}

View File

@@ -1,33 +1,10 @@
import {GetStaticPropsContext, type NextPage} from "next"; import {type NextPage} from "next";
import Head from "next/head"; import Head from "next/head";
import React, {useEffect} from "react"; import React, {useEffect} from "react";
import ItemCard from "../components/ItemCard"; import ItemCard from "../components/ItemCard";
import {getPlaiceholder} from "plaiceholder"; import {getPlaiceholder} from "plaiceholder";
import {useBreakpointValue} from "../utils/helpers"; import {useBreakpointValue} from "../utils/helpers";
import {IconType} from "react-icons"; import type {Project} from "../utils/types";
import {AiFillGithub, AiOutlineLink} from "react-icons/ai";
import {RxOpenInNewWindow} from "react-icons/rx";
export type Project = {
title: string;
banner: string;
longDescription: string;
shortDescription: string;
links?: LinkIcon[];
location: string;
}
export const LinkIcons: Record<string, IconType> = {
github: AiFillGithub,
external: RxOpenInNewWindow,
link: AiOutlineLink
}
export type LinkIcon = {
icon: keyof typeof LinkIcons;
location: string;
newTab?: boolean;
}
type ProjectWithBlur = Project & { bannerBlur: string }; type ProjectWithBlur = Project & { bannerBlur: string };
@@ -36,7 +13,7 @@ type HomeStaticProps = {
projects: ProjectWithBlur[]; projects: ProjectWithBlur[];
} }
export async function getStaticProps(context: GetStaticPropsContext) { export async function getStaticProps() {
const projects: Project[] = [ const projects: Project[] = [
{ {
title: "Phototag", title: "Phototag",

24
src/utils/types.ts Normal file
View File

@@ -0,0 +1,24 @@
import {IconType} from "react-icons";
import {AiFillGithub, AiOutlineLink} from "react-icons/ai";
import {RxOpenInNewWindow} from "react-icons/rx";
export type Project = {
title: string;
banner: string;
longDescription: string;
shortDescription: string;
links?: LinkIcon[];
location: string;
}
export const LinkIcons: Record<string, IconType> = {
github: AiFillGithub,
external: RxOpenInNewWindow,
link: AiOutlineLink
}
export type LinkIcon = {
icon: keyof typeof LinkIcons;
location: string;
newTab?: boolean;
}