Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Nov 16, 2023
1 parent 3cf0fa9 commit 7777a02
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 214 deletions.
3 changes: 3 additions & 0 deletions main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ entity User {=psl

externalAuthAssociations SocialLogin[]
chats Chat[]
conversations Conversation[]
psl=}
// relatedObject RelatedObject[] - add in line 86
entity SocialLogin {=psl
Expand Down Expand Up @@ -130,6 +131,8 @@ entity Conversation {=psl
updatedAt DateTime @updatedAt
chat Chat? @relation(fields: [chatId], references: [id])
chatId Int?
user User? @relation(fields: [userId], references: [id])
userId Int?
psl=}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Conversation" ADD COLUMN "userId" INTEGER;

-- AddForeignKey
ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
213 changes: 0 additions & 213 deletions src/client/ChatPage.jsx

This file was deleted.

42 changes: 42 additions & 0 deletions src/client/ChatPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useState, useEffect, useRef } from "react";

import { useQuery } from "@wasp/queries";
import getChats from "@wasp/queries/getChats";
import type { Chat } from "@wasp/entities";

import CreateNewChatBtn from "./components/CreateNewChat";
import ChatsList from "./components/ChatList";
import ConversationWrapper from "./components/ConversationWrapper";

export default function ChatPage() {
let { data: chats, isLoading: isLoadingChats } = useQuery(getChats);

return (
<div className="relative z-0 flex h-full w-full overflow-hidden h-screen">
<div
id="default-sidebar"
className="md:w-[260px] flex-shrink-0 overflow-x-hidden dark bg-captn-dark-blue"
aria-label="Sidebar"
>
<div
style={{ borderRight: "1px solid #eae4d9" }}
className="border-x-captn-light-cream h-full px-3 py-4 overflow-y-auto bg-captn-dark-blue"
>
<CreateNewChatBtn />
<div className="flex-col flex-1 transition-opacity duration-500 -mr-2 pr-2 overflow-y-auto">
<ul className="py-5 space-y-2 font-medium">
{
// Todo: remove the below ignore comment
// @ts-ignore
chats && <ChatsList chats={chats} />
}
</ul>
</div>
</div>
</div>
<div className="relative z-0 flex h-full w-full overflow-hidden h-screen">
<ConversationWrapper />
</div>
</div>
);
}
36 changes: 36 additions & 0 deletions src/client/components/ChatList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Link } from "@wasp/router";
import type { Chat } from "@wasp/entities";

export default function ChatsList(chats: Chat[]) {
return (
<div>
{
// Todo: remove the below ignore comment
// @ts-ignore
chats.chats.map((chat, idx) => (
<Link key={chat.id} to="/chat/:id?" params={{ id: chat.id }}>
<li key={idx}>
<div className="flex items-center p-2 text-white hover:bg-captn-light-blue hover:text-captn-dark-blue group rounded-lg ">
<svg
stroke="currentColor"
fill="none"
strokeWidth="2"
viewBox="0 0 24 24"
strokeLinecap="round"
strokeLinejoin="round"
className="icon-sm"
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
</svg>
<span className="ml-3">{chat.id}</span>
</div>
</li>
</Link>
))
}
</div>
);
}
Loading

0 comments on commit 7777a02

Please sign in to comment.