From 44a95cbf1cc95c8e052437bc9d267a5bb91ef855 Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Tue, 27 Jun 2023 14:01:32 +0200 Subject: [PATCH] fix: eslint errors --- lib/content/training.ts | 36 ++++++++++++++++++++--------------- lib/currency/formatter.ts | 2 +- src/components/Button.tsx | 9 +++------ src/components/Sidebar.tsx | 9 +++------ src/pages/training/[slug].tsx | 21 +++++++++++++++----- src/pages/trainings.tsx | 19 +++++++++++++++--- 6 files changed, 60 insertions(+), 36 deletions(-) diff --git a/lib/content/training.ts b/lib/content/training.ts index a462640..dbea4e9 100644 --- a/lib/content/training.ts +++ b/lib/content/training.ts @@ -24,11 +24,11 @@ export type { Training }; const root = process.cwd(); -export async function getTrainingFiles() { +export function getTrainingFiles() { return fs.readdirSync(path.join(root, 'content', 'training'), 'utf-8'); } -export async function getTrainingBySlug(slug: string, fields: string[] = []) { +export function getTrainingBySlug(slug: string) { const source = fs.readFileSync(path.join(root, 'content', 'training', `${slug}.md`), 'utf8'); const { data, content } = matter(source); @@ -39,21 +39,27 @@ export async function getTrainingBySlug(slug: string, fields: string[] = []) { }; } -export async function getAllTrainingsWithMetadata(): Promise { +export function getAllTrainingsWithMetadata(): Training[] { const files = fs.readdirSync(path.join(root, 'content', 'training')) - // @ts-ignore - return files.reduce((allTrainings, fileName) => { - const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8'); - const { data, content } = matter(source); + const trainings = [] as Training[]; - return [ - { - metadata: data, - content: content, - }, - ...allTrainings, - ] - }, []) + for (const fileName of files) { + const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8'); + const { data: metadata, content: content } = matter(source); + trainings.push({metadata, content} as Training); + } + + return trainings; + + // return files.reduce((allTrainings, fileName) => { + // const source = fs.readFileSync(path.join(root, 'content', 'training', fileName), 'utf8'); + // const training = matter(source); + + // return [ + // training, + // ...allTrainings, + // ] + // }, []) } diff --git a/lib/currency/formatter.ts b/lib/currency/formatter.ts index 867f841..effb2b7 100644 --- a/lib/currency/formatter.ts +++ b/lib/currency/formatter.ts @@ -1,4 +1,4 @@ -export function formatCurrency(price: number | bigint, locale: string = 'en-US', currency: string = 'CZK'): string { +export function formatCurrency(price: number | bigint, locale ='en-US', currency = 'CZK'): string { const currencyFormatter = new Intl.NumberFormat(locale, { style: 'currency', currency: currency, diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 422fc7c..2f91a82 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,9 +1,6 @@ +import clsx from "clsx"; import Link from "next/link"; -import { ReactNode } from "react"; - -function classNames(...classes: any) { - return classes.filter(Boolean).join(' ') -} +import { type ReactNode } from "react"; const baseStyles = { solid: @@ -58,7 +55,7 @@ export function Button({ throw new Error("Outline buttons cannot be amber"); } - className = classNames( + className = clsx( baseStyles[variant], variantStyles[variant][color], sizeStyles[size], diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index af4ec84..b5de84d 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,3 +1,4 @@ +import clsx from "clsx"; import Link from 'next/link'; import { useRouter } from 'next/router'; import { Fragment, useState } from 'react'; @@ -15,10 +16,6 @@ const navigation = [ { name: 'Trainings', href: '/trainings', icon: AcademicCapIcon }, ] -function classNames(...classes: any) { - return classes.filter(Boolean).join(' ') -} - export function Sidebar() { const [sidebarOpen, setSidebarOpen] = useState(false) const router = useRouter(); @@ -79,7 +76,7 @@ export function Sidebar() {
  • { const session = await getServerAuthSession(ctx); @@ -23,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { training: training, session } }; } -function Detail({ training }: { training: any }) { +function Detail({ training }: { training: Training }) { return (
    @@ -88,7 +100,6 @@ export default function Training({ training }: { training: Training }) { Training | MaresHQ backoffice - {/* { JSON.stringify(trainings) } */} diff --git a/src/pages/trainings.tsx b/src/pages/trainings.tsx index c323ee0..eddc7b7 100644 --- a/src/pages/trainings.tsx +++ b/src/pages/trainings.tsx @@ -1,4 +1,4 @@ -import { GetServerSideProps } from "next"; +import { type GetServerSideProps } from "next"; import Head from "next/head"; import Link from "next/link"; @@ -10,6 +10,18 @@ import { Training } from "lib/content/training"; import { Layout } from "~/components/Layout"; import { Button } from "~/components/Button"; +type Trainings = [ + { + id: string; + name: string; + slug: string; + days: number; + draft: boolean; + priceOpen: number; + priceCorporate: number; + } +]; + export const getServerSideProps: GetServerSideProps = async (ctx) => { const session = await getServerAuthSession(ctx); @@ -26,10 +38,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { priceCorporate: true, } }); + return { props: { trainings: trainings, session } }; } -function Table({trainings}: { trainings: Training[] }) { +function Table({trainings}: { trainings: Trainings }) { return (
    @@ -105,7 +118,7 @@ function Table({trainings}: { trainings: Training[] }) { ) } -export default function Training({ trainings }: { trainings: Training[] }) { +export default function Training({ trainings }: { trainings: Trainings }) { return ( <>