Skip to content

Commit

Permalink
registers all previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfiej-k committed Dec 6, 2023
1 parent 8da8ad0 commit 4abdc46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/messages/chat-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ChatDisplay({ userId, previews, messages }: ChatDisplayP

useEffect(() => {
const getData = async () => {
const { data, error } = await supabase.from("latest_messages").select().eq("receiver", userId);
const { data, error } = await supabase.from("latest_messages").select().or(`sender.eq.${userId}, receiver.eq.${userId}`);
if (!error && data) {
setPrevs(data);
}
Expand Down
6 changes: 5 additions & 1 deletion app/messages/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createServerSupabaseClient } from "@/lib/server-utils";
import { redirect } from "next/navigation";
import ChatDisplay from "./chat-display";
import { type Database } from "@/lib/schema";

type Views<T extends keyof Database["public"]["Views"]> = Database["public"]["Views"][T]["Row"];
type Preview = Views<"latest_messages">;

export default async function Page() {
const supabase = createServerSupabaseClient();
Expand All @@ -13,7 +17,7 @@ export default async function Page() {
}

const userId = session.user.id;
const previews = await supabase.from("latest_messages").select().eq("receiver", userId);
const previews = await supabase.from("latest_messages").select().or(`sender.eq.${userId}, receiver.eq.${userId}`);
const messages = await supabase.from("messages").select().or(`sender.eq.${userId}, receiver.eq.${userId}`);

if (previews.error ?? messages.error) {
Expand Down

0 comments on commit 4abdc46

Please sign in to comment.