From 146ea54d7173b56d380e0aa8d2a7a465f16eca98 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Tue, 19 Dec 2023 19:21:45 +0100 Subject: [PATCH] refactor: some renaming and corrections --- README.md | 8 +- app/api/mailing/route.ts | 15 +- app/api/news/route.ts | 9 +- app/confirmation/page.tsx | 4 +- app/page.tsx | 4 +- app/privacy/page.tsx | 7 +- app/unsubscribe/page.tsx | 4 +- components/custom/background/tile/tile.tsx | 6 +- .../custom/background/tile/tileContent.tsx | 4 +- components/custom/background/tile/tiles.tsx | 8 +- components/custom/card.tsx | 22 +- components/custom/link.tsx | 3 +- components/emails/components/footer.tsx | 11 +- package-lock.json | 7401 ----------------- prisma/schema.prisma | 4 +- tailwind.config.ts | 6 +- utils/schemas.ts | 8 + yarn.lock | 190 +- 18 files changed, 169 insertions(+), 7545 deletions(-) delete mode 100644 package-lock.json diff --git a/README.md b/README.md index 72706e5..942b259 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Custom url shortener for links in the newsletter - Cron every 10 minutes: people are more likely to open the newsletter if delivered around the time when they subscribed (if cron becomes not enough, then the cost of sending all the emails might be a bigger issue) -## Vercel basics +## Commands Install vercel cli @@ -43,3 +43,9 @@ Reset Prisma database ```bash yarn db:reset ``` + +Run on Docker + +```bash +docker-compose up --build +``` diff --git a/app/api/mailing/route.ts b/app/api/mailing/route.ts index ffcaf21..dfb8d2c 100644 --- a/app/api/mailing/route.ts +++ b/app/api/mailing/route.ts @@ -19,9 +19,16 @@ export async function GET(request: Request) { where: { confirmed: true, deleted: false, - lastMail: { - lt: new Date(Date.now() - 1000 * 60 * 60 * 24 + 1000 * 10 * 60) // 24h - 10m - } + OR: [ + { + lastMail: { + lt: new Date(Date.now() - 1000 * 60 * 60 * 24 + 1000 * 10 * 60) // 24h - 10m + } + }, + { + lastMail: null + } + ] }, select: { id: true, @@ -38,7 +45,7 @@ export async function GET(request: Request) { const news = await prisma.news.findMany({ where: { createdAt: { - gt: new Date(Date.now() - 1000 * 60 * 60) + gt: new Date(Date.now() - 1000 * 60 * 60 * 24) } } }); diff --git a/app/api/news/route.ts b/app/api/news/route.ts index 03a8e0d..f269f91 100644 --- a/app/api/news/route.ts +++ b/app/api/news/route.ts @@ -6,10 +6,15 @@ export async function GET() { orderBy: { createdAt: 'desc' }, - take: 100 + take: 50, + select: { + id: true, + title: true, + by: true + } }); - if (news && news.length === 100) { + if (news) { return ApiResponse(200, JSON.stringify(news)); } diff --git a/app/confirmation/page.tsx b/app/confirmation/page.tsx index 68309b4..1221161 100644 --- a/app/confirmation/page.tsx +++ b/app/confirmation/page.tsx @@ -2,7 +2,7 @@ import { useRouter, useSearchParams } from 'next/navigation'; import { useEffect, useState } from 'react'; import { z } from 'zod'; -import { CustomCard } from '../../components/custom/card'; +import { Card } from '../../components/custom/card'; import { ResponseSchema } from '../../utils/schemas'; export default function Confirmation() { @@ -55,7 +55,7 @@ export default function Confirmation() { } return ( -

Interpretation and Definitions

-

Interpretation

The words of which the initial letter is capitalized have meanings @@ -116,9 +115,7 @@ export default function Privacy() {

Collecting and Using Your Personal Data

-

Types of Data Collected

-

Personal Data

While using Our Service, We may ask You to provide Us with certain @@ -432,7 +429,7 @@ export default function Privacy() { ); return ( - ; - newsB?: z.infer; + newsA?: z.infer; + newsB?: z.infer; }; export function Tile({ newsA, newsB }: CardProps) { diff --git a/components/custom/background/tile/tileContent.tsx b/components/custom/background/tile/tileContent.tsx index 7df8f31..b45aa5f 100644 --- a/components/custom/background/tile/tileContent.tsx +++ b/components/custom/background/tile/tileContent.tsx @@ -1,10 +1,10 @@ import { useState } from 'react'; import { z } from 'zod'; import { getRandomColor } from '../../../../utils/getRandomColor'; -import { NewsSchema } from '../../../../utils/schemas'; +import { NewsTileSchema } from '../../../../utils/schemas'; type CardContentProps = { - story: z.infer; + story: z.infer; side: boolean; }; diff --git a/components/custom/background/tile/tiles.tsx b/components/custom/background/tile/tiles.tsx index 6f0872f..995c8cb 100644 --- a/components/custom/background/tile/tiles.tsx +++ b/components/custom/background/tile/tiles.tsx @@ -3,7 +3,7 @@ import { usePathname } from 'next/navigation'; import { useEffect, useState } from 'react'; import { z } from 'zod'; -import { NewsSchema } from '../../../../utils/schemas'; +import { NewsTile, NewsTileSchema } from '../../../../utils/schemas'; import { Tile } from './tile'; type TilesProps = { @@ -19,11 +19,11 @@ export const Tiles = ({ children }: TilesProps) => { width: 0, height: 0 }); - const [news, setNews] = useState[]>(); + const [news, setNews] = useState[]>(); useEffect(() => { async function getNews() { - const news = await fetch('/api/news').then(res => res.json()); + const news: NewsTile[] = await fetch('/api/news').then(res => res.json()); if (news) { setNews(news); @@ -83,7 +83,7 @@ export const Tiles = ({ children }: TilesProps) => { return (

-
+
{Array.from({ length: rows }).map((_, index) => renderRow(columns, index) )} diff --git a/components/custom/card.tsx b/components/custom/card.tsx index dbe79b0..fa6aa96 100644 --- a/components/custom/card.tsx +++ b/components/custom/card.tsx @@ -1,16 +1,16 @@ import { ReactNode, useEffect, useState } from 'react'; import { useMediaQuery } from 'react-responsive'; import { - Card, CardContent, CardDescription, CardFooter, CardHeader, - CardTitle + CardTitle, + Card as CardUI } from '../../components/ui/card'; import Footer from './footer'; -type CustomCardProps = { +type CardProps = { title: string; description?: string; content: ReactNode; @@ -18,13 +18,13 @@ type CustomCardProps = { footer?: boolean; }; -export const CustomCard = ({ +export const Card = ({ title, description, content, style, footer = true -}: CustomCardProps) => { +}: CardProps) => { const [isLoaded, setIsLoaded] = useState(false); const isMobile = useMediaQuery({ query: '(max-width: 767px)' }); @@ -39,7 +39,7 @@ export const CustomCard = ({ if (isMobile) { console.log(isMobile); return ( - + {title} {description} @@ -52,12 +52,16 @@ export const CustomCard = ({