From 50bca71a3fead1e61ddd4957928af56aedd90994 Mon Sep 17 00:00:00 2001 From: alex 3 Date: Sun, 5 Nov 2023 23:53:51 -0500 Subject: [PATCH] Add social links page --- prisma/schema.prisma | 96 ++++++++++++++++++--------------- src/components/ProjectsCard.tsx | 5 +- src/components/SocialCard.tsx | 16 ++++++ src/pages/links.tsx | 40 ++++++++++++++ src/pages/reviews/create.tsx | 36 +++++++++++-- src/pages/reviews/index.tsx | 34 +++++++----- src/server/api/root.ts | 2 + src/server/api/routers/links.ts | 41 ++++++++++++++ src/server/api/routers/post.ts | 12 +++++ 9 files changed, 219 insertions(+), 63 deletions(-) create mode 100644 src/components/SocialCard.tsx create mode 100644 src/pages/links.tsx create mode 100644 src/server/api/routers/links.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d11a66b..74a7d7c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,69 +1,77 @@ generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" } datasource db { - provider = "mongodb" - url = env("DATABASE_URL") + provider = "mongodb" + url = env("DATABASE_URL") } model Post { - id String @id @map("_id") @default(uuid()) - type String - name String - reviewContents String - image String - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(uuid()) @map("_id") + type String + name String + reviewContents String + image String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt - createdBy User @relation(fields: [createdById], references: [id]) - createdById String + createdBy User @relation(fields: [createdById], references: [id]) + createdById String - @@index([name]) + @@index([name]) +} + +model SocialLink { + id String @id @default(uuid()) @map("_id") + name String + url String + + @@index([name]) } // Necessary for Next auth model Account { - id String @id @map("_id") @default(cuid()) - userId String - type String - provider String - providerAccountId String - refresh_token String? // @db.Text - access_token String? // @db.Text - expires_at Int? - token_type String? - scope String? - id_token String? // @db.Text - session_state String? - user User @relation(fields: [userId], references: [id], onDelete: Cascade) + id String @id @default(cuid()) @map("_id") + userId String + type String + provider String + providerAccountId String + refresh_token String? // @db.Text + access_token String? // @db.Text + expires_at Int? + token_type String? + scope String? + id_token String? // @db.Text + session_state String? + user User @relation(fields: [userId], references: [id], onDelete: Cascade) - @@unique([provider, providerAccountId]) + @@unique([provider, providerAccountId]) } model Session { - id String @id @map("_id") @default(cuid()) - sessionToken String @unique - userId String - expires DateTime - user User @relation(fields: [userId], references: [id], onDelete: Cascade) + id String @id @default(cuid()) @map("_id") + sessionToken String @unique + userId String + expires DateTime + user User @relation(fields: [userId], references: [id], onDelete: Cascade) } model User { - id String @id @map("_id") @default(cuid()) - name String? - email String? @unique - emailVerified DateTime? - image String? - accounts Account[] - sessions Session[] - posts Post[] + id String @id @default(cuid()) @map("_id") + name String? + email String? @unique + emailVerified DateTime? + image String? + accounts Account[] + sessions Session[] + posts Post[] } model VerificationToken { - identifier String @id @map("_id") - token String @unique - expires DateTime + identifier String @id @map("_id") + token String @unique + expires DateTime - @@unique([identifier, token]) + @@unique([identifier, token]) } diff --git a/src/components/ProjectsCard.tsx b/src/components/ProjectsCard.tsx index e5adc4d..13f60cc 100644 --- a/src/components/ProjectsCard.tsx +++ b/src/components/ProjectsCard.tsx @@ -3,7 +3,6 @@ import Link from "next/link" type ProjectCardProps = { name: string, subHeading?: string, - key: string, description: string, urlTo: string } @@ -11,8 +10,8 @@ type ProjectCardProps = { export default function ProjectCard(props: ProjectCardProps) { return ( -
-
+
+

{props.name}

{props.subHeading}

diff --git a/src/components/SocialCard.tsx b/src/components/SocialCard.tsx new file mode 100644 index 0000000..acbd252 --- /dev/null +++ b/src/components/SocialCard.tsx @@ -0,0 +1,16 @@ +import Link from "next/link" + +type SocialCardProps = { + name: string, + url: string +} + +export default function SocialMediaCard(props: SocialCardProps) { + return ( +
+ + {props.name} + +
+ ) +} \ No newline at end of file diff --git a/src/pages/links.tsx b/src/pages/links.tsx new file mode 100644 index 0000000..a829a69 --- /dev/null +++ b/src/pages/links.tsx @@ -0,0 +1,40 @@ +import Header from "@/components/header"; +import Footer from "@/components/footer"; +import SocialCard from '@/components/SocialCard' +import Dropdown from "@/components/Dropdown"; +import { api } from "@/utils/api"; +import React, {useEffect, useState} from 'react'; + +export default function Links() { + const {data: linkData} = api.links.getAll.useQuery() + const [formatted, setFormatted] = useState(null) + + useEffect(() => { + if (linkData) { + setFormatted( + linkData.map((v) => { + return + }) + ) + } + }, [linkData]) + + return ( +
+
+
+ + {formatted} + + {/* { + formatted ? + + : +

There's nothing here :(

+ } */} + +
+
+
+ ) +} \ No newline at end of file diff --git a/src/pages/reviews/create.tsx b/src/pages/reviews/create.tsx index 27a543c..7c545ca 100644 --- a/src/pages/reviews/create.tsx +++ b/src/pages/reviews/create.tsx @@ -8,7 +8,8 @@ import { api } from "@/utils/api"; export default function Page() { const { data: session, status } = useSession() - const mutation = api.post.create.useMutation() + const postMutation = api.post.create.useMutation() + const linksMutation = api.links.create.useMutation() const [loading, setLoading] = useState(true) useEffect(() => { @@ -26,7 +27,7 @@ export default function Page() { return title.replaceAll(" ", "-").toLowerCase() } - function onSubmit(event: FormEvent) { + function onPostSubmit(event: FormEvent) { event.preventDefault() const form = event.target as HTMLFormElement @@ -42,7 +43,22 @@ export default function Page() { type: typeElement.value } - mutation.mutate(object) + postMutation.mutate(object) + } + + function onLinkSubmit(event: FormEvent) { + event.preventDefault() + const form = event.target as HTMLFormElement + + const titleElement = form.elements.namedItem('title') as HTMLInputElement; + const urlElement = form.elements.namedItem('url') as HTMLInputElement; + + const object = { + name: sanitizeTitleForLink(titleElement.value), + url: urlElement.value + } + + linksMutation.mutate(object) } if (!loading) { @@ -50,7 +66,7 @@ export default function Page() {
-
+


@@ -67,6 +83,18 @@ export default function Page() {
+ +
+
+
+
+ +
+
+ + +
+
diff --git a/src/pages/reviews/index.tsx b/src/pages/reviews/index.tsx index 99391d5..6bd9df2 100644 --- a/src/pages/reviews/index.tsx +++ b/src/pages/reviews/index.tsx @@ -43,17 +43,21 @@ export default function Reviews() { if (itemData) { const filteredArray = itemData.filter(v => v.type == type.toLowerCase()) - setList( - filteredArray.map((v: GenericItemType, k) => { - return - }) - ) + if (filteredArray.length <= 0) { + setList(null) + } else { + setList( + filteredArray.map((v: GenericItemType, k) => { + return + }) + ) + } } }, [itemData, type]) @@ -77,7 +81,13 @@ export default function Reviews() {

- {list} + { + list ? list + :
+

Nothing here!

+

Try again later :(

+
+ }