From 8f84caef070a6dda9f3f229b8fd61de57eaf6b6f Mon Sep 17 00:00:00 2001 From: Priyanshu Date: Thu, 8 Aug 2024 16:10:06 +0530 Subject: [PATCH] Fix: Document data visibility --- app/components/Card/Card.tsx | 8 +++++++- app/writer/[id]/actions.ts | 7 ++++--- app/writer/[id]/page.tsx | 1 + helpers/prettifyDates.ts | 26 ++++++++++++++++++-------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/components/Card/Card.tsx b/app/components/Card/Card.tsx index bbec467..4909f95 100644 --- a/app/components/Card/Card.tsx +++ b/app/components/Card/Card.tsx @@ -84,7 +84,13 @@ export default function DocCard({ docId, thumbnail, title, updatedAt, users }: D ) })} -

{prettifyDate(String(updatedAt))}

+

+ {prettifyDate(String(updatedAt), { + year: "numeric", + month: "short", + day: "2-digit" + })} +

diff --git a/app/writer/[id]/actions.ts b/app/writer/[id]/actions.ts index abc378c..4131ca8 100644 --- a/app/writer/[id]/actions.ts +++ b/app/writer/[id]/actions.ts @@ -1,6 +1,8 @@ "use server" +import prettifyDate from "@/helpers/prettifyDates" import prisma from "@/prisma/prismaClient" +import { revalidatePath } from "next/cache" export const GetDocDetails = async (id: any, userId: string) => { try { @@ -18,7 +20,6 @@ export const GetDocDetails = async (id: any, userId: string) => { } export const UpdateDocData = async (id: any, userId: string, data: string) => { - console.log("here3") try { const doc = await prisma.document.findFirst({ where: { id, userId } }) if (!doc) return { @@ -26,13 +27,12 @@ export const UpdateDocData = async (id: any, userId: string, data: string) => { error: "Document does not exist", } - console.log("here4") await prisma.document.update( { where: { id, userId }, data: { data: data, - updatedAt: Date(), + updatedAt: new Date(), } }) @@ -52,6 +52,7 @@ export const UpdateThumbnail = async (id: any, userId: string, thumbnail: string } await prisma.document.update({ where: { id, userId }, data: { thumbnail } }) + revalidatePath('/'); return { success: true, data: "Internal server error" } } catch (e) { diff --git a/app/writer/[id]/page.tsx b/app/writer/[id]/page.tsx index d6357eb..6dbc796 100644 --- a/app/writer/[id]/page.tsx +++ b/app/writer/[id]/page.tsx @@ -101,6 +101,7 @@ export default function Dashboard() { }); useEffect(() => { + console.log(docData); if (editor && docData) { editor.commands.setContent(docData); } diff --git a/helpers/prettifyDates.ts b/helpers/prettifyDates.ts index ad7d991..4667475 100644 --- a/helpers/prettifyDates.ts +++ b/helpers/prettifyDates.ts @@ -1,13 +1,23 @@ -const prettifyDate = (dateString: string | undefined) => { - if(!dateString) return "" +type OptionsType = { + weekday?: "narrow" | "short" | "long"; + year?: "numeric" | "2-digit"; + month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; + day?: "numeric" | "2-digit"; + hour?: "numeric" | "2-digit"; + minute?: "numeric" | "2-digit"; + second?: "numeric" | "2-digit"; + timeZoneName?: "short" | "long"; + hour12?: boolean; + era?: "narrow" | "short" | "long"; + timeZone?: string; + fractionalSecondDigits?: 1 | 2 | 3; +}; + +const prettifyDate = (dateString: string | undefined, options: OptionsType) => { + if (!dateString) return "" const date = new Date(dateString); - return new Intl.DateTimeFormat("en-US", { - // weekday: "short", - year: "numeric", - month: "short", - day: "numeric", - }).format(date); + return new Intl.DateTimeFormat("en-US", options).format(date); }; export default prettifyDate;