Skip to content

Commit

Permalink
leftovers cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
Diivvuu committed Oct 16, 2024
1 parent 5bc81aa commit a8a4807
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
12 changes: 11 additions & 1 deletion convex/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ export const remove = mutation({
throw new Error("Unauthorized");
}

// const [messagess]
const [messages] = await Promise.all([
ctx.db
.query("messages")
.withIndex("by_channel_id", (q) => q.eq("channelId", args.id))
.collect(),
]);

for (const message of messages) {
await ctx.db.delete(message._id);
}

await ctx.db.delete(args.id);

return args.id;
Expand Down
41 changes: 35 additions & 6 deletions convex/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,45 @@ export const remove = mutation({
throw new Error("Unauthorized");
}

const [members] = await Promise.all([
ctx.db
.query("members")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
]);
const [members, channels, conversations, messages, reactions] =
await Promise.all([
ctx.db
.query("members")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
ctx.db
.query("channels")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
ctx.db
.query("conversations")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
ctx.db
.query("messages")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
ctx.db
.query("reactions")
.withIndex("by_workspace_id", (q) => q.eq("workspaceId", args.id))
.collect(),
]);

for (const member of members) {
await ctx.db.delete(member._id);
}
for (const channel of channels) {
await ctx.db.delete(channel._id);
}
for (const conversation of conversations) {
await ctx.db.delete(conversation._id);
}
for (const message of messages) {
await ctx.db.delete(message._id);
}
for (const reaction of reactions) {
await ctx.db.delete(reaction._id);
}

await ctx.db.delete(args.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Loader } from "lucide-react";
import { Header } from "./header";
import { ChatInput } from "./chat-input";
import { MessageList } from "@/components/message-list";
import { usePanel } from "@/hooks/use-panel";

interface ConversationProps {
id: Id<"conversations">;
Expand All @@ -14,6 +15,8 @@ interface ConversationProps {
export const Conversations = ({ id }: ConversationProps) => {
const memberId = useMemberId();

const { onOpenProfile, onClose } = usePanel();

const { data: member, isLoading: memberLoading } = useGetMember({
id: memberId,
});
Expand All @@ -34,7 +37,9 @@ export const Conversations = ({ id }: ConversationProps) => {
<Header
memberName={member?.user.name}
memberImage={member?.user.image}
onClick={() => {}}
onClick={() => {
onOpenProfile(memberId);
}}
/>
<MessageList
data={results}
Expand Down

0 comments on commit a8a4807

Please sign in to comment.