diff --git a/apps/nextjs/src/app/actions.ts b/apps/nextjs/src/app/actions.ts index b0d64870b..b365ff4bc 100644 --- a/apps/nextjs/src/app/actions.ts +++ b/apps/nextjs/src/app/actions.ts @@ -43,7 +43,7 @@ export async function getChatById( id: string, ): Promise { const session = await prisma?.appSession.findUnique({ - where: { id }, + where: { id, deletedAt: null }, }); if (!session) { diff --git a/apps/nextjs/src/components/DialogControl/ContentOptions/ClearChatHistory.tsx b/apps/nextjs/src/components/DialogControl/ContentOptions/ClearChatHistory.tsx index 07e9ed1ca..bcdb28aa8 100644 --- a/apps/nextjs/src/components/DialogControl/ContentOptions/ClearChatHistory.tsx +++ b/apps/nextjs/src/components/DialogControl/ContentOptions/ClearChatHistory.tsx @@ -61,7 +61,9 @@ const ClearChatHistory = ({ $justifyContent="center" $gap="space-between-m" > - This will permanently delete all of your lesson history. + + This will permanently delete all of your lesson history. + - This will permanently delete this lesson. + This will permanently delete this lesson. {isLoading ? ( diff --git a/apps/nextjs/src/components/DialogControl/DialogContents.tsx b/apps/nextjs/src/components/DialogControl/DialogContents.tsx index 7187dc4e6..ed297f230 100644 --- a/apps/nextjs/src/components/DialogControl/DialogContents.tsx +++ b/apps/nextjs/src/components/DialogControl/DialogContents.tsx @@ -1,5 +1,8 @@ +import { useState } from "react"; + import type { LooseLessonPlan } from "@oakai/aila/src/protocol/schema"; import { + OakModal, OakModalCenter, OakModalCenterBody, type OakIconName, @@ -8,6 +11,7 @@ import type { Message } from "ai"; import styled from "styled-components"; import type { DialogTypes } from "../AppComponents/Chat/Chat/types"; +import { ChatHistory } from "../AppComponents/Chat/chat-history"; import { useDialog } from "../AppComponents/DialogContext"; import ClearChatHistory from "./ContentOptions/ClearChatHistory"; import ClearSingleChatFromChatHistory from "./ContentOptions/ClearSingleChatFromChatHistory"; diff --git a/packages/aila/src/features/persistence/adaptors/prisma/index.ts b/packages/aila/src/features/persistence/adaptors/prisma/index.ts index 28b2923e3..198930700 100644 --- a/packages/aila/src/features/persistence/adaptors/prisma/index.ts +++ b/packages/aila/src/features/persistence/adaptors/prisma/index.ts @@ -39,6 +39,7 @@ export class AilaPrismaPersistence extends AilaPersistence { const appSession = await this._prisma.appSession.findFirst({ where: { id, + deletedAt: null, }, }); diff --git a/packages/api/src/router/appSessions.ts b/packages/api/src/router/appSessions.ts index 7375e1420..29f9042a6 100644 --- a/packages/api/src/router/appSessions.ts +++ b/packages/api/src/router/appSessions.ts @@ -79,6 +79,7 @@ export async function getChat(id: string, prisma: PrismaClientWithAccelerate) { const chatRecord = await prisma.appSession.findUnique({ where: { id: id, + deletedAt: null, }, }); if (!chatRecord) { @@ -205,6 +206,7 @@ export const appSessionsRouter = router({ "app_sessions" WHERE "user_id" = ${userId} AND "app_id" = 'lesson-planner' + AND "deleted_at" IS NULL ORDER BY "updated_at" DESC `; @@ -245,22 +247,27 @@ export const appSessionsRouter = router({ const { userId } = ctx.auth; const { id } = input; - await ctx.prisma.appSession.deleteMany({ + await ctx.prisma.appSession.update({ where: { id, appId: "lesson-planner", userId, }, + data: { + deletedAt: new Date(), + }, }); }), deleteAllChats: protectedProcedure.mutation(async ({ ctx }) => { const { userId } = ctx.auth; - - await ctx.prisma.appSession.deleteMany({ + await ctx.prisma.appSession.updateMany({ where: { userId, appId: "lesson-planner", }, + data: { + deletedAt: new Date(), + }, }); }), shareChat: protectedProcedure @@ -278,6 +285,7 @@ export const appSessionsRouter = router({ id, userId, appId: "lesson-planner", + deletedAt: null, }, }); diff --git a/packages/api/src/router/chats.ts b/packages/api/src/router/chats.ts index 403dc29fb..c63158839 100644 --- a/packages/api/src/router/chats.ts +++ b/packages/api/src/router/chats.ts @@ -45,7 +45,7 @@ export const chatsRouter = router({ const { id } = input; const session = await prisma?.appSession.findUnique({ - where: { id }, + where: { id, deletedAt: null }, }); if (!session) { @@ -72,6 +72,7 @@ export const chatsRouter = router({ where: { userId, appId: "lesson-planner", + deletedAt: null, }, }); diff --git a/packages/core/src/models/apps.ts b/packages/core/src/models/apps.ts index 4c9b6563a..59ba0007d 100644 --- a/packages/core/src/models/apps.ts +++ b/packages/core/src/models/apps.ts @@ -46,6 +46,7 @@ export class Apps { where: { id: sessionId, userId: userId, + deletedAt: null, output: { not: Prisma.AnyNull, }, @@ -59,6 +60,7 @@ export class Apps { return this.prisma.appSession.findMany({ where: { userId: userId, + deletedAt: null, output: { not: Prisma.AnyNull, }, diff --git a/packages/db/prisma/migrations/20241126134932_add_deleted_session_col/migration.sql b/packages/db/prisma/migrations/20241126134932_add_deleted_session_col/migration.sql new file mode 100644 index 000000000..b9e9d9f95 --- /dev/null +++ b/packages/db/prisma/migrations/20241126134932_add_deleted_session_col/migration.sql @@ -0,0 +1,3 @@ + +-- AlterTable +ALTER TABLE "public"."app_sessions" ADD COLUMN "deleted_at" TIMESTAMP(3); diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 4cabd577c..a6f727de3 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -344,14 +344,15 @@ model AppSession { id String @id @default(cuid()) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") - + deletedAt DateTime? @map("deleted_at") + app App @relation(fields: [appId], references: [id], onDelete: Cascade) appId String @map("app_id") userId String @map("user_id") // The user that requested this generation output Json? // The final output of the session - + userTweaks UserTweak[] reGenerations ReGeneration[] generationUserFlags GenerationUserFlag[]