diff --git a/convex/files.tsx b/convex/files.tsx index 51a5d37..aad9428 100644 --- a/convex/files.tsx +++ b/convex/files.tsx @@ -20,6 +20,10 @@ export const createFile = mutation({ document, whiteboard, private: false, + read:true, + write:false, + writtenBy:[createdBy], + readBy:[createdBy] }); return result; }, @@ -189,11 +193,11 @@ export const updateWrite = mutation({ export const updateRead = mutation({ args: { _id: v.id("files"), - writtenBy: v.array(v.string()) + readBy: v.array(v.string()) }, handler: async (ctx, args) => { - const { _id,writtenBy } = args; - const res = await ctx.db.patch(_id, { writtenBy, write:false, read:true }); + const { _id,readBy } = args; + const res = await ctx.db.patch(_id, { readBy, write:false, read:true }); return res; }, }); \ No newline at end of file diff --git a/convex/schemas.ts b/convex/schemas.ts index 32969ac..1bfe194 100644 --- a/convex/schemas.ts +++ b/convex/schemas.ts @@ -21,6 +21,7 @@ export default defineSchema({ whiteboard: v.string(), private: v.string(), writtenBy: v.array(v.string()), + readBy: v.array(v.string()), write:v.boolean(), read:v.boolean() }), diff --git a/src/app/api/files/read/route.ts b/src/app/api/files/read/route.ts index e6266d5..95da066 100644 --- a/src/app/api/files/read/route.ts +++ b/src/app/api/files/read/route.ts @@ -3,7 +3,7 @@ import { ConvexHttpClient } from "convex/browser"; export const PUT = async (req: Request) => { try { - const { teamId, email, memberEmail, writtenBy, fileId } = await req.json(); + const { teamId, email, memberEmail, readBy, fileId } = await req.json(); if (!teamId || !memberEmail || !email || !fileId) return new Response("Parameters missing!!", { status: 401 }); @@ -20,11 +20,11 @@ export const PUT = async (req: Request) => { return new Response("Only owner can make changes!!", { status: 400 }); } - const updatedWrittenBy = Array.isArray(writtenBy) - ? writtenBy.filter(writer => writer !== memberEmail) + const updatedReadBy = Array.isArray(readBy) + ? readBy.filter(writer => writer !== memberEmail) : []; - await client.mutation(api.files.updateRead, { _id: fileId, writtenBy:updatedWrittenBy }); + await client.mutation(api.files.updateRead, { _id: fileId, readBy:updatedReadBy }); return new Response("Changed to Public!!", { status: 200 }); } catch (err) { diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index ce0b790..97d5bbc 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -26,6 +26,10 @@ export interface FILE { whiteboard: string; _id: string; _creationTime: number; + read:boolean; + write:boolean; + writtenBy: string[]; + readBy: string[]; } function Dashboard() { diff --git a/src/components/shared/MemberModal.tsx b/src/components/shared/MemberModal.tsx index 9799f63..fdfa3e4 100644 --- a/src/components/shared/MemberModal.tsx +++ b/src/components/shared/MemberModal.tsx @@ -11,6 +11,10 @@ import { import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; import { useSelector } from "react-redux"; import { RootState } from "@/app/store"; +import { FileListContext } from "@/app/_context/FilesListContext"; +import { useState, useContext, useEffect } from "react"; +import { FILE } from "@/app/dashboard/page"; +import { Badge } from "../ui/badge"; type Props = { image: string; @@ -28,6 +32,18 @@ export default function MemberModal({ email, }: Props) { const teamName = useSelector((state: RootState) => state.team.teamName); + const [fileData, setFileList] = useState([]); + const { fileList_ } = useContext(FileListContext); + + useEffect(() => { + if (fileList_) { + const nonArchivedFiles = fileList_.filter( + (file: { archive: boolean }) => !file.archive + ); + setFileList(nonArchivedFiles); + } + }, [fileList_]); + return ( {teamName} -

File Access :

+ + { +
+
+

File Name

+

File Access

+
+ {fileData.map((file: FILE, index) => ( +
+

{file.fileName}

+ +
+ { file.readBy?.includes(email) && Read} + { file.writtenBy?.includes(email) && Write} +
+
+ ))} +
+ } + Email : {email}