diff --git a/prisma/migrations/20240325154103_init/migration.sql b/prisma/migrations/20240809152643_init/migration.sql
similarity index 74%
rename from prisma/migrations/20240325154103_init/migration.sql
rename to prisma/migrations/20240809152643_init/migration.sql
index d8532eb..5c116ab 100644
--- a/prisma/migrations/20240325154103_init/migration.sql
+++ b/prisma/migrations/20240809152643_init/migration.sql
@@ -74,6 +74,26 @@ CREATE TABLE "Draft" (
CONSTRAINT "Draft_pkey" PRIMARY KEY ("id")
);
+-- CreateTable
+CREATE TABLE "CourseDraft" (
+ "id" TEXT NOT NULL,
+ "userId" TEXT NOT NULL,
+ "title" TEXT NOT NULL,
+ "summary" TEXT NOT NULL,
+ "image" TEXT,
+ "price" INTEGER DEFAULT 0,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "CourseDraft_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "_CourseDraftToResource" (
+ "A" TEXT NOT NULL,
+ "B" TEXT NOT NULL
+);
+
-- CreateIndex
CREATE UNIQUE INDEX "User_pubkey_key" ON "User"("pubkey");
@@ -86,6 +106,12 @@ CREATE UNIQUE INDEX "Course_noteId_key" ON "Course"("noteId");
-- CreateIndex
CREATE UNIQUE INDEX "Resource_noteId_key" ON "Resource"("noteId");
+-- CreateIndex
+CREATE UNIQUE INDEX "_CourseDraftToResource_AB_unique" ON "_CourseDraftToResource"("A", "B");
+
+-- CreateIndex
+CREATE INDEX "_CourseDraftToResource_B_index" ON "_CourseDraftToResource"("B");
+
-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -109,3 +135,12 @@ ALTER TABLE "Resource" ADD CONSTRAINT "Resource_courseId_fkey" FOREIGN KEY ("cou
-- AddForeignKey
ALTER TABLE "Draft" ADD CONSTRAINT "Draft_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "CourseDraft" ADD CONSTRAINT "CourseDraft_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "_CourseDraftToResource" ADD CONSTRAINT "_CourseDraftToResource_A_fkey" FOREIGN KEY ("A") REFERENCES "CourseDraft"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "_CourseDraftToResource" ADD CONSTRAINT "_CourseDraftToResource_B_fkey" FOREIGN KEY ("B") REFERENCES "Resource"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index dea4080..1710cf5 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -16,6 +16,7 @@ model User {
courses Course[] // Relation field added for courses created by the user
resources Resource[] // Relation field added for resources created by the user
drafts Draft[] // Relation field added for drafts created by the user
+ courseDrafts CourseDraft[] // Relation field added for course drafts created by the user
role Role? @relation(fields: [roleId], references: [id])
roleId String?
createdAt DateTime @default(now())
@@ -61,6 +62,7 @@ model Resource {
courseId String?
price Int @default(0)
purchases Purchase[]
+ courseDrafts CourseDraft[]
noteId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -81,3 +83,15 @@ model Draft {
updatedAt DateTime @updatedAt
}
+model CourseDraft {
+ id String @id @default(uuid())
+ userId String
+ user User @relation(fields: [userId], references: [id])
+ resources Resource[]
+ title String
+ summary String
+ image String?
+ price Int? @default(0)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+}
diff --git a/src/components/content/lists/ContentListItem.js b/src/components/content/lists/ContentListItem.js
index 40bdfe5..023618b 100644
--- a/src/components/content/lists/ContentListItem.js
+++ b/src/components/content/lists/ContentListItem.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, {useEffect} from "react";
import Image from "next/image";
import { Button } from "primereact/button";
import { useImageProxy } from "@/hooks/useImageProxy";
@@ -8,6 +8,25 @@ const ContentListItem = (content) => {
const { returnImageProxy } = useImageProxy();
const router = useRouter();
const isDraft = Object.keys(content).includes('type');
+ const isCourse = content && content?.resources && content?.resources?.length > 0;
+
+ const handleClick = () => {
+ let path = '';
+
+ if (isDraft) {
+ path = '/draft';
+ } else if (isCourse) {
+ path = '/course';
+ } else {
+ path = '/details';
+ }
+
+ const draftSuffix = isCourse ? '/draft' : '';
+ const fullPath = `${path}/${content.id}${draftSuffix}`;
+
+ router.push(fullPath);
+ };
+
return (
@@ -26,7 +45,7 @@ const ContentListItem = (content) => {
);
-}
\ No newline at end of file
+}
diff --git a/src/pages/draft/[slug]/index.js b/src/pages/draft/[slug]/index.js
index bb83ef5..1a8828d 100644
--- a/src/pages/draft/[slug]/index.js
+++ b/src/pages/draft/[slug]/index.js
@@ -84,7 +84,7 @@ export default function Draft() {
return;
}
- console.log('unsignedEvent:', unsignedEvent.validate());
+ console.log('unsignedEvent:', unsignedEvent.validate(), unsignedEvent);
console.log('unsignedEvent validation:', validationResult);
if (unsignedEvent) {
diff --git a/src/utils/nostr.js b/src/utils/nostr.js
index 5613d25..e6f6522 100644
--- a/src/utils/nostr.js
+++ b/src/utils/nostr.js
@@ -1,7 +1,6 @@
import { nip19 } from "nostr-tools";
export const findKind0Fields = async (kind0) => {
- console.log('kind0', kind0);
let fields = {}
const usernameProperties = ['name', 'displayName', 'display_name', 'username', 'handle', 'alias'];