Skip to content

Commit

Permalink
Fix: Document data visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
git-init-priyanshu committed Aug 8, 2024
1 parent d199a36 commit 8f84cae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
8 changes: 7 additions & 1 deletion app/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export default function DocCard({ docId, thumbnail, title, updatedAt, users }: D
</Avatar>
)
})}
<p className="text-neutral-600 cursor-default">{prettifyDate(String(updatedAt))}</p>
<p className="text-neutral-600 cursor-default">
{prettifyDate(String(updatedAt), {
year: "numeric",
month: "short",
day: "2-digit"
})}
</p>
</div>
<CardOptions docId={docId} inputRef={inputRef} />
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/writer/[id]/actions.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,21 +20,19 @@ 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 {
success: false,
error: "Document does not exist",
}

console.log("here4")
await prisma.document.update(
{
where: { id, userId },
data: {
data: data,
updatedAt: Date(),
updatedAt: new Date(),
}
})

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/writer/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function Dashboard() {
});

useEffect(() => {
console.log(docData);
if (editor && docData) {
editor.commands.setContent(docData);
}
Expand Down
26 changes: 18 additions & 8 deletions helpers/prettifyDates.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 8f84cae

Please sign in to comment.