From 0631ae3897b934f431e914b75d1d18156121d8ba Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Sat, 17 Dec 2022 17:38:45 -0800 Subject: [PATCH] Fix more types --- src/app/(posts)/components/file-dropdown/index.tsx | 4 ++-- .../post/[id]/components/header/post-buttons/index.tsx | 4 ++-- src/app/admin/admin.module.css | 4 ++++ src/app/admin/page.tsx | 6 +++--- src/app/components/post-list/list-item.tsx | 3 +-- src/lib/server/prisma.ts | 2 -- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/app/(posts)/components/file-dropdown/index.tsx b/src/app/(posts)/components/file-dropdown/index.tsx index add16498..f4b9680c 100644 --- a/src/app/(posts)/components/file-dropdown/index.tsx +++ b/src/app/(posts)/components/file-dropdown/index.tsx @@ -1,7 +1,7 @@ import { Popover } from "@components/popover" import { codeFileExtensions } from "@lib/constants" import clsx from "clsx" -import type { File } from "lib/server/prisma" +import type { File, PostWithFiles } from "lib/server/prisma" import styles from "./dropdown.module.css" import buttonStyles from "@components/button/button.module.css" import { ChevronDown, Code, File as FileIcon } from "react-feather" @@ -15,7 +15,7 @@ const FileDropdown = ({ files, loading }: { - files: File[] + files: Pick["files"] loading?: boolean }) => { if (loading) { diff --git a/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx b/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx index bdf80fcf..cc64095d 100644 --- a/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx +++ b/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx @@ -5,8 +5,8 @@ import ButtonGroup from "@components/button-group" import FileDropdown from "app/(posts)/components/file-dropdown" import { Edit, ArrowUpCircle, Archive } from "react-feather" import styles from "./post-buttons.module.css" -import { File } from "@prisma/client" import { useRouter } from "next/navigation" +import { PostWithFiles } from "@lib/server/prisma" export const PostButtons = ({ title, @@ -16,7 +16,7 @@ export const PostButtons = ({ parentId }: { title: string - files?: File[] + files?: Pick["files"] loading?: boolean postId?: string parentId?: string diff --git a/src/app/admin/admin.module.css b/src/app/admin/admin.module.css index 4182821a..92e1ebc8 100644 --- a/src/app/admin/admin.module.css +++ b/src/app/admin/admin.module.css @@ -7,3 +7,7 @@ .table thead th { font-weight: bold; } + +.table .id { + width: 10ch; +} diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index 2e3af7b3..a89a1412 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -20,7 +20,7 @@ export function UserTable({ {users?.map((user) => ( - {user.name ? user.name : "no name"} + {user.displayName ? user.displayName : "no name"} {user.email} {user.role} {user.id} @@ -62,7 +62,7 @@ export function PostTable({ {post.title} - {"author" in post ? post.author.name : "no author"} + {"author" in post ? post.author?.name : "no author"} {post.createdAt.toLocaleDateString()} {post.visibility} {post.id} @@ -89,7 +89,7 @@ export default async function AdminPage() { const [users, posts] = await Promise.all([usersPromise, postsPromise]) return ( -
+

Admin

Users

diff --git a/src/app/components/post-list/list-item.tsx b/src/app/components/post-list/list-item.tsx index d5458c68..3f124503 100644 --- a/src/app/components/post-list/list-item.tsx +++ b/src/app/components/post-list/list-item.tsx @@ -6,7 +6,6 @@ import { useRouter } from "next/navigation" import styles from "./list-item.module.css" import Link from "@components/link" import type { PostWithFiles } from "@lib/server/prisma" -import type { File } from "@lib/server/prisma" import Tooltip from "@components/tooltip" import Badge from "@components/badges/badge" import Card from "@components/card" @@ -94,7 +93,7 @@ const ListItem = ({
<> - {post?.files?.map((file: File) => { + {post?.files?.map((file: Pick["files"][0]) => { return (
diff --git a/src/lib/server/prisma.ts b/src/lib/server/prisma.ts index 99c688a9..99108b8f 100644 --- a/src/lib/server/prisma.ts +++ b/src/lib/server/prisma.ts @@ -189,8 +189,6 @@ export const getPostById = async ( if (post) { if ("files" in post) { - // @ts-expect-error TODO: fix types so files can exist - console.log(post.files) // @ts-expect-error TODO: fix types so files can exist post.files = post.files.map((file) => ({ ...file,