Skip to content

Commit

Permalink
implemented text-area and basic message box
Browse files Browse the repository at this point in the history
  • Loading branch information
SyedMSawaid committed Oct 24, 2024
1 parent e7725b5 commit dc1cfd7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/atoms/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const playerState = atom({
export const applicationState = atom({
key: "applicationState",
default: {
isChatScreen: false,
isChatScreen: true,
},
});

Expand Down
34 changes: 34 additions & 0 deletions src/components/MessageBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useRecoilState } from "recoil";
import { Button } from "./Button";
import { TextArea } from "./TextArea";
import { chatState } from "../atoms/state";
import { useState } from "react";

export const MessageBox = () => {
const [, setChatState] = useRecoilState(chatState);

const [message, setMessage] = useState("");

const onSend = () => {
setChatState((prev) => ({
chats: [
...prev.chats,
{
id: prev.chats.length + 1,
player: 1,
message: message,
timeStamp: new Date(),
},
],
}));

setMessage("");
};

return (
<div>
<TextArea value={message} onChange={(e) => setMessage(e.target.value)} />
<Button onClick={onSend}>Send</Button>
</div>
);
};
11 changes: 11 additions & 0 deletions src/components/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ComponentProps } from "react";

type Props = {} & ComponentProps<"textarea">;

export const TextArea = ({ id, name, ...props }: Props) => {
return (
<div>
<textarea name={name} id={id} {...props}></textarea>
</div>
);
};
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from "./Input";
export * from "./Button";
export * from "./ChatOptions";
export * from "./MessageBubble";
export * from "./MessageBox";
export * from "./TextArea";
6 changes: 5 additions & 1 deletion src/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageBubble } from "../components";
import { MessageBox, MessageBubble } from "../components";
import { Chat } from "../data";

type Props = {
Expand All @@ -18,6 +18,10 @@ export const ChatPage = ({ chats }: Props) => {
/>
))}
</div>

<div>
<MessageBox />
</div>
</div>
);
};

0 comments on commit dc1cfd7

Please sign in to comment.