Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/372 #375

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions convex/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const createFile = mutation({
document,
whiteboard,
private: false,
read:true,
write:false,
writtenBy:[createdBy],
readBy:[createdBy]
});
return result;
},
Expand Down Expand Up @@ -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;
},
});
1 change: 1 addition & 0 deletions convex/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}),
Expand Down
8 changes: 4 additions & 4 deletions src/app/api/files/read/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface FILE {
whiteboard: string;
_id: string;
_creationTime: number;
read:boolean;
write:boolean;
writtenBy: string[];
readBy: string[];
}

function Dashboard() {
Expand Down
40 changes: 39 additions & 1 deletion src/components/shared/MemberModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
<Dialog key={index}>
<DialogTrigger
Expand All @@ -54,7 +70,29 @@ export default function MemberModal({
<span className=" font-bold">{teamName}</span>
</DialogDescription>
</DialogHeader>
<h1>File Access : </h1>

{
<div className="flex flex-col max-h-[350px] p-2 overflow-x-hidden overflow-y-auto">
<div className="flex font-semibold p-2 text-base items-center justify-between w-full">
<h1>File Name</h1>
<h1>File Access</h1>
</div>
{fileData.map((file: FILE, index) => (
<div
className="w-full bg-secondary border-t-[1px] border-gray-400 flex p-2 items-center justify-between"
key={index}
>
<h1>{file.fileName}</h1>

<div className="flex gap-3">
{ file.readBy?.includes(email) && <Badge>Read</Badge>}
{ file.writtenBy?.includes(email) && <Badge>Write</Badge>}
</div>
</div>
))}
</div>
}

<DialogFooter className=" text-gray-500">Email : {email}</DialogFooter>
</DialogContent>
</Dialog>
Expand Down
Loading