partially implement del function
This commit is contained in:
parent
7b68a7451e
commit
525f716f16
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
Binary file not shown.
|
@ -1,4 +0,0 @@
|
|||
"use server"
|
||||
export async function createStory(formData: FormData) {
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
"use server"
|
||||
import prisma from "./db"
|
||||
export async function createStory(data) {
|
||||
console.log("CREATESTORY CALLED")
|
||||
const id = await prisma.story.create({
|
||||
data: {
|
||||
title: "test",
|
||||
word_count: 500
|
||||
}
|
||||
})
|
||||
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
"use server"
|
||||
import { revalidatePath } from "next/cache";
|
||||
import prisma from "./db";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function deleteStory(id) {
|
||||
console.log(`id: ${id}`)
|
||||
export async function deleteStory(id: number) {
|
||||
const res = await prisma.story.delete({
|
||||
where: { id }
|
||||
})
|
||||
console.log(res)
|
||||
console.log(`deleted: ${res}`)
|
||||
revalidatePath("/story")
|
||||
redirect("/story")
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ import { Button } from "@/components/ui/button"
|
|||
import { Badge } from "@/components/ui/badge"
|
||||
import { CircleX } from "lucide-react"
|
||||
import { deleteStory } from "app/lib/del"
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
|
||||
const columnHelper = createColumnHelper<StoryWithGenres>()
|
||||
|
||||
|
||||
|
||||
export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||
{
|
||||
accessorKey: "title",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { getGenres } from "app/lib/get";
|
||||
import StoryForm from "app/ui/forms/story";
|
||||
import prisma from "app/lib/db";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
export default async function Page() {
|
||||
const genres = await getGenres()
|
||||
async function createStory(data) {
|
||||
|
@ -20,6 +22,8 @@ export default async function Page() {
|
|||
}
|
||||
})
|
||||
console.log(genresRes)
|
||||
revalidatePath("/story")
|
||||
redirect("/story")
|
||||
}
|
||||
return <StoryForm genres={genres} createStory={createStory} />
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ export function DataTable<TData, TValue>({
|
|||
columns,
|
||||
data,
|
||||
}: DataTableProps<TData, TValue>) {
|
||||
console.log(data)
|
||||
//STATE
|
||||
const [sorting, setSorting] = useState<SortingState>([])
|
||||
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>(
|
||||
|
@ -69,7 +68,6 @@ export function DataTable<TData, TValue>({
|
|||
})
|
||||
|
||||
const [filterBy, setFilterBy] = useState(table.getAllColumns()[0])
|
||||
console.log(filterBy.id)
|
||||
return (<>
|
||||
<div className="flex justify-between py-4">
|
||||
<div className="flex gap-2">
|
||||
|
|
|
@ -3,9 +3,13 @@ import { DataTable } from "./data-table";
|
|||
import { columns } from "./columns";
|
||||
import { getStoriesWithGenres } from "app/lib/get";
|
||||
import { Genre } from "@prisma/client";
|
||||
export type StoryWithGenres = Story & { genres: Array<Genre> }
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
export const revalidate = 1
|
||||
|
||||
export type StoryWithGenres = Story & { genres: Array<Genre> }
|
||||
const stories: Array<StoryWithGenres> = await getStoriesWithGenres()
|
||||
|
||||
export default async function Page() {
|
||||
return (
|
||||
<div className="container mx-auto py-10">
|
||||
|
|
Loading…
Reference in New Issue