From 7b68a7451e80df5ec19097973c8cd74f3dbe3ef0 Mon Sep 17 00:00:00 2001 From: andrzej Date: Wed, 19 Jun 2024 18:01:42 +0200 Subject: [PATCH] add deleteStory function, fix schema to allow it --- prisma/dev.db | Bin 69632 -> 69632 bytes prisma/dev.db-journal | Bin 0 -> 12824 bytes .../20240619155421_init/migration.sql | 19 +++++++ .../20240619155628_init/migration.sql | 19 +++++++ .../20240619155716_init/migration.sql | 20 ++++++++ prisma/schema.prisma | 16 +++--- src/app/lib/del.ts | 10 ++++ src/app/story/columns.tsx | 32 ++++++------ src/app/story/data-table.tsx | 3 +- src/app/tailwind.css | 47 ++++++++++++++++++ src/app/ui/forms/genresTrigger.tsx | 2 +- 11 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 prisma/dev.db-journal create mode 100644 prisma/migrations/20240619155421_init/migration.sql create mode 100644 prisma/migrations/20240619155628_init/migration.sql create mode 100644 prisma/migrations/20240619155716_init/migration.sql create mode 100644 src/app/lib/del.ts diff --git a/prisma/dev.db b/prisma/dev.db index 98f3dbff9cea76cbd00f7b1f796067d5d4420142..d5bdc3b15d6ac6ee08883ce0ee734ecb5699a072 100644 GIT binary patch delta 1554 zcmbVM+iw(A7@xBj5hFX(F?+oXo`QXX|Oyb z_wU@cEm|+E>PfM~WG|lTlKZv`v*6E!`q07q)H@cb>5_|H0cUfMFhSqIG^0wo>ivbfp&7NOOJ6Fn4H^Us>x+G;hHuVsuC3?MS_PRzu-&HJZ_zJ>-p}2uzDYmEUj)gSO@`xR(mhZSIK&}&LzHQl> zj#P`d7SEYCqUMuBIAuA@$?NT|iJKbr&N|)f}R_u5Sm(3=CIwb;_X{ zF7lA!sHW=@$MiMZAb}nPW@uAE=;9j>38J~&6NE0-;+gitTw6g}$G`&o0Unh;gs)21 zq}QZ5h@^G!blfS+()22JCwP?aSxA77QfDCnK1%+40*pUiyAd>}|397JWq1yrgpIg! z!+sbw*1yGn1~0(x;WZdj)4R|}_KXOU6N0uQmoKobfOb-*$g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8sg=j2FpQ{(NJ*WlQ?H#uG_E8hNWe|3$0-~fWsZrlALe zw*AiyEOabjZS>7xeE!G}M^1IOJGuVF`V(tc4*z!e9X{Q*W}q2p2AY9ppc!Zent{i{ z!1U1C;kTyUKo17XqoNRWNrG%or)lwT7O*OJ4%4Do^COZ>R0VFKwqK*X+r8LrGtTuXdggM$0 zyp*VTTD$+*BRp358IRrnc-oETJTcdhWUivR$~=m!2#8UnD2w+=R%#LClA$dZUOYEq%H&{AYd5sS8v9hV9nMlMV! zPU$ebwsL>%tA{)QlKtXC9=`D9v^zBC3Ep{`5k%4+1%d(gW2?~GK+GxzZ!$`9syb=2 z1Br!vb+#Crk}ARKT0Hf`_?4;pVmL1xDvpk=*(xfQdG0azgZ%V78r6*Fo<2S8R^~iX zaYQsl!DT4yM;Vc*Dq%w{ptDOcl9LWlmPni^rAz>XUL+WswG5CcLeN!mXc57?6d1EA z4w`Yrdas%1&fe#99==(a@!Z*)a+K#hIeE+Xk)m=m1PezIEuzSr8ijqURA&M~U^OYI z%n8b>a8fal2PD>)oB|8UYKvYO%0XMlP2#0831tRko?F*nne#{hH{-c=Jxsf$IgiWH zJ0$M(1tEQzf| z<1BEF9S}z;a(j3#j8#D1=Bl(J?)rkHqE;0vDO5`G+5_Afskpws_I~_i&Vv$X>knUe z|NB3WFYs5|ayR~Iuspu8F#dJ?_4xMq{`kiD#$)kS*C3mLW}q2p2AY9ppc!Zent^7Z z8E6KYf&a3B@%^=K@z`*iE}c7dAuSzRTYPeO=0aLnA1yvTJWadjceZz_8?7%M9iG|S znOt5R|1lU1`=O&{K6jF~C$!9hR!97)$>sX{@&|mh)c+q~X*?Z_zZ>t5KjodaH3Q8+ zGtdk)1I<7)&{v17y4QsX76b+^R+eSBkaW$@B7!`0We zF4FGCn;R#0($*&b!tW1X-lN^Uw~sHZ44!{>xcbJFLA( literal 0 HcmV?d00001 diff --git a/prisma/migrations/20240619155421_init/migration.sql b/prisma/migrations/20240619155421_init/migration.sql new file mode 100644 index 0000000..9dfdfe5 --- /dev/null +++ b/prisma/migrations/20240619155421_init/migration.sql @@ -0,0 +1,19 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Sub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "storyId" INTEGER, + "pubId" INTEGER, + "submitted" TEXT NOT NULL, + "responded" TEXT, + "responseId" INTEGER, + CONSTRAINT "Sub_storyId_fkey" FOREIGN KEY ("storyId") REFERENCES "Story" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "Sub_pubId_fkey" FOREIGN KEY ("pubId") REFERENCES "Pub" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "Sub_responseId_fkey" FOREIGN KEY ("responseId") REFERENCES "Response" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_Sub" ("id", "pubId", "responded", "responseId", "storyId", "submitted") SELECT "id", "pubId", "responded", "responseId", "storyId", "submitted" FROM "Sub"; +DROP TABLE "Sub"; +ALTER TABLE "new_Sub" RENAME TO "Sub"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20240619155628_init/migration.sql b/prisma/migrations/20240619155628_init/migration.sql new file mode 100644 index 0000000..5351932 --- /dev/null +++ b/prisma/migrations/20240619155628_init/migration.sql @@ -0,0 +1,19 @@ +/* + Warnings: + + - You are about to drop the column `deleted` on the `Story` table. All the data in the column will be lost. + +*/ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Story" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "word_count" INTEGER NOT NULL, + "title" TEXT NOT NULL +); +INSERT INTO "new_Story" ("id", "title", "word_count") SELECT "id", "title", "word_count" FROM "Story"; +DROP TABLE "Story"; +ALTER TABLE "new_Story" RENAME TO "Story"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20240619155716_init/migration.sql b/prisma/migrations/20240619155716_init/migration.sql new file mode 100644 index 0000000..269dfe7 --- /dev/null +++ b/prisma/migrations/20240619155716_init/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - You are about to drop the column `deleted` on the `Pub` table. All the data in the column will be lost. + +*/ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Pub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "title" TEXT NOT NULL, + "link" TEXT NOT NULL DEFAULT '', + "query_after_days" INTEGER NOT NULL +); +INSERT INTO "new_Pub" ("id", "link", "query_after_days", "title") SELECT "id", "link", "query_after_days", "title" FROM "Pub"; +DROP TABLE "Pub"; +ALTER TABLE "new_Pub" RENAME TO "Pub"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8a99d2a..3cbe396 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,7 +14,6 @@ model Story { id Int @id @default(autoincrement()) word_count Int title String - deleted Int @default(0) subs Sub[] genres Genre[] } @@ -24,7 +23,6 @@ model Pub { title String link String @default("") query_after_days Int - deleted Int @default(0) subs Sub[] genres Genre[] } @@ -44,12 +42,12 @@ model Response { model Sub { id Int @id @default(autoincrement()) - story Story @relation(fields: [storyId], references: [id]) - storyId Int - pub Pub @relation(fields: [pubId], references: [id]) - pubId Int + story Story? @relation(fields: [storyId], references: [id]) + storyId Int? + pub Pub? @relation(fields: [pubId], references: [id]) + pubId Int? submitted String - responded String - response Response @relation(fields: [responseId], references: [id]) - responseId Int + responded String? + response Response? @relation(fields: [responseId], references: [id]) + responseId Int? } diff --git a/src/app/lib/del.ts b/src/app/lib/del.ts new file mode 100644 index 0000000..37d3150 --- /dev/null +++ b/src/app/lib/del.ts @@ -0,0 +1,10 @@ +"use server" +import prisma from "./db"; + +export async function deleteStory(id) { + console.log(`id: ${id}`) + const res = await prisma.story.delete({ + where: { id } + }) + console.log(res) +} diff --git a/src/app/story/columns.tsx b/src/app/story/columns.tsx index c1a8879..8181a60 100644 --- a/src/app/story/columns.tsx +++ b/src/app/story/columns.tsx @@ -4,11 +4,14 @@ import { StoryWithGenres } from "./page" import { ArrowUpDown, MoreHorizontal } from "lucide-react" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" - +import { CircleX } from "lucide-react" +import { deleteStory } from "app/lib/del" const columnHelper = createColumnHelper() + + export const columns: ColumnDef[] = [ { accessorKey: "title", @@ -40,29 +43,22 @@ export const columns: ColumnDef[] = [ }, enableColumnFilter: false }, - // { - // accessorFn: row => { - // let unpacked = "" - // for (let i = 0; i < row.genres.length; i++) { - // unpacked = unpacked + " " + row.genres[i].name - // } - // return unpacked - // }, - // header: "Genres" - // - // - // }, columnHelper.accessor("genres", { cell: props => { const genres = props.getValue() .map(e => {e.name}) return genres } - }) - // { - // accessorKey: "deleted", - // header: "Deleted" - // }, + }), + { + id: "actions", + header: "Actions", + cell: ({ row }) => { + return + } + } ] diff --git a/src/app/story/data-table.tsx b/src/app/story/data-table.tsx index d8969d9..166606d 100644 --- a/src/app/story/data-table.tsx +++ b/src/app/story/data-table.tsx @@ -31,6 +31,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table" +import { EyeIcon } from "lucide-react" interface DataTableProps { columns: ColumnDef[] @@ -105,7 +106,7 @@ export function DataTable({ diff --git a/src/app/tailwind.css b/src/app/tailwind.css index 4bbecb0..8b3d7ec 100644 --- a/src/app/tailwind.css +++ b/src/app/tailwind.css @@ -907,6 +907,10 @@ body { gap: 0.25rem; } +.gap-2 { + gap: 0.5rem; +} + .space-x-1 > :not([hidden]) ~ :not([hidden]) { --tw-space-x-reverse: 0; margin-right: calc(0.25rem * var(--tw-space-x-reverse)); @@ -967,6 +971,18 @@ body { margin-bottom: calc(2rem * var(--tw-space-y-reverse)); } +.justify-self-start { + justify-self: start; +} + +.justify-self-end { + justify-self: end; +} + +.justify-self-center { + justify-self: center; +} + .overflow-auto { overflow: auto; } @@ -987,6 +1003,10 @@ body { border-radius: calc(var(--radius) - 4px); } +.rounded-full { + border-radius: 9999px; +} + .border { border-width: 1px; } @@ -1011,6 +1031,10 @@ body { border-color: hsl(var(--primary)); } +.border-transparent { + border-color: transparent; +} + .bg-accent { background-color: hsl(var(--accent)); } @@ -1121,6 +1145,21 @@ body { padding-bottom: 1rem; } +.px-2\.5 { + padding-left: 0.625rem; + padding-right: 0.625rem; +} + +.py-0 { + padding-top: 0px; + padding-bottom: 0px; +} + +.py-0\.5 { + padding-top: 0.125rem; + padding-bottom: 0.125rem; +} + .pl-3 { padding-left: 0.75rem; } @@ -1400,6 +1439,14 @@ body { background-color: hsl(var(--secondary) / 0.8); } +.hover\:bg-destructive\/80:hover { + background-color: hsl(var(--destructive) / 0.8); +} + +.hover\:bg-primary\/80:hover { + background-color: hsl(var(--primary) / 0.8); +} + .hover\:text-accent-foreground:hover { color: hsl(var(--accent-foreground)); } diff --git a/src/app/ui/forms/genresTrigger.tsx b/src/app/ui/forms/genresTrigger.tsx index 3e457be..e54e0c7 100644 --- a/src/app/ui/forms/genresTrigger.tsx +++ b/src/app/ui/forms/genresTrigger.tsx @@ -24,4 +24,4 @@ export default function GenresTrigger({ value, genres }) { ) -} +}