Fix more types

This commit is contained in:
Max Leiter 2022-12-17 17:38:45 -08:00
parent 82aadd94f2
commit 0631ae3897
6 changed files with 12 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import { Popover } from "@components/popover" import { Popover } from "@components/popover"
import { codeFileExtensions } from "@lib/constants" import { codeFileExtensions } from "@lib/constants"
import clsx from "clsx" 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 styles from "./dropdown.module.css"
import buttonStyles from "@components/button/button.module.css" import buttonStyles from "@components/button/button.module.css"
import { ChevronDown, Code, File as FileIcon } from "react-feather" import { ChevronDown, Code, File as FileIcon } from "react-feather"
@ -15,7 +15,7 @@ const FileDropdown = ({
files, files,
loading loading
}: { }: {
files: File[] files: Pick<PostWithFiles, "files">["files"]
loading?: boolean loading?: boolean
}) => { }) => {
if (loading) { if (loading) {

View file

@ -5,8 +5,8 @@ import ButtonGroup from "@components/button-group"
import FileDropdown from "app/(posts)/components/file-dropdown" import FileDropdown from "app/(posts)/components/file-dropdown"
import { Edit, ArrowUpCircle, Archive } from "react-feather" import { Edit, ArrowUpCircle, Archive } from "react-feather"
import styles from "./post-buttons.module.css" import styles from "./post-buttons.module.css"
import { File } from "@prisma/client"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { PostWithFiles } from "@lib/server/prisma"
export const PostButtons = ({ export const PostButtons = ({
title, title,
@ -16,7 +16,7 @@ export const PostButtons = ({
parentId parentId
}: { }: {
title: string title: string
files?: File[] files?: Pick<PostWithFiles, "files">["files"]
loading?: boolean loading?: boolean
postId?: string postId?: string
parentId?: string parentId?: string

View file

@ -7,3 +7,7 @@
.table thead th { .table thead th {
font-weight: bold; font-weight: bold;
} }
.table .id {
width: 10ch;
}

View file

@ -20,7 +20,7 @@ export function UserTable({
<tbody> <tbody>
{users?.map((user) => ( {users?.map((user) => (
<tr key={user.id}> <tr key={user.id}>
<td>{user.name ? user.name : "no name"}</td> <td>{user.displayName ? user.displayName : "no name"}</td>
<td>{user.email}</td> <td>{user.email}</td>
<td>{user.role}</td> <td>{user.role}</td>
<td className={styles.id}>{user.id}</td> <td className={styles.id}>{user.id}</td>
@ -62,7 +62,7 @@ export function PostTable({
{post.title} {post.title}
</a> </a>
</td> </td>
<td>{"author" in post ? post.author.name : "no author"}</td> <td>{"author" in post ? post.author?.name : "no author"}</td>
<td>{post.createdAt.toLocaleDateString()}</td> <td>{post.createdAt.toLocaleDateString()}</td>
<td>{post.visibility}</td> <td>{post.visibility}</td>
<td>{post.id}</td> <td>{post.id}</td>
@ -89,7 +89,7 @@ export default async function AdminPage() {
const [users, posts] = await Promise.all([usersPromise, postsPromise]) const [users, posts] = await Promise.all([usersPromise, postsPromise])
return ( return (
<div className={styles.wrapper}> <div>
<h1>Admin</h1> <h1>Admin</h1>
<h2>Users</h2> <h2>Users</h2>
<UserTable users={users} /> <UserTable users={users} />

View file

@ -6,7 +6,6 @@ import { useRouter } from "next/navigation"
import styles from "./list-item.module.css" import styles from "./list-item.module.css"
import Link from "@components/link" import Link from "@components/link"
import type { PostWithFiles } from "@lib/server/prisma" import type { PostWithFiles } from "@lib/server/prisma"
import type { File } from "@lib/server/prisma"
import Tooltip from "@components/tooltip" import Tooltip from "@components/tooltip"
import Badge from "@components/badges/badge" import Badge from "@components/badges/badge"
import Card from "@components/card" import Card from "@components/card"
@ -94,7 +93,7 @@ const ListItem = ({
</> </>
<hr /> <hr />
<> <>
{post?.files?.map((file: File) => { {post?.files?.map((file: Pick<PostWithFiles, "files">["files"][0]) => {
return ( return (
<div key={file.id}> <div key={file.id}>
<Link colored href={`/post/${post.id}#${file.title}`}> <Link colored href={`/post/${post.id}#${file.title}`}>

View file

@ -189,8 +189,6 @@ export const getPostById = async (
if (post) { if (post) {
if ("files" in 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 // @ts-expect-error TODO: fix types so files can exist
post.files = post.files.map((file) => ({ post.files = post.files.map((file) => ({
...file, ...file,