Skip to content

Commit

Permalink
Move messages into components
Browse files Browse the repository at this point in the history
  • Loading branch information
max committed Apr 5, 2023
1 parent af3a96f commit 8b82fdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/src/components/chat/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FC } from "react"

const Avatar: FC = () => {
return <div className="bg-red-500 rounded h-8 w-8"></div>
}

export default Avatar
23 changes: 23 additions & 0 deletions app/src/components/chat/message.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FC } from "react"
import ReactMarkdown from "react-markdown"
import remarkGfm from "remark-gfm"
import { IMessage } from "../../pages/chat"
import Avatar from "./avatar"

interface Props {
message: IMessage
}

const Message: FC<Props> = ({ message }) => {
return (
<div className="flex gap-4">
<Avatar />

<div className="prose">
<ReactMarkdown children={message.content} remarkPlugins={[remarkGfm]} />
</div>
</div>
)
}

export default Message
23 changes: 9 additions & 14 deletions app/src/pages/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from "react"
import NavBar from "../components/navbar"
import ReactMarkdown from "react-markdown"
import remarkGfm from "remark-gfm"
import Message from "../components/chat/message"

export interface IMessage {
author: string
content: string
}

const initialMessages = [
{ author: "me", content: "How do I set up a Node.js TypeScript project?" },
Expand Down Expand Up @@ -40,7 +44,7 @@ npm install --save-dev typescript
This file specifies the TypeScript compiler options and tells it to compile all files in the src directory.`,
},
]
] as IMessage[]

export default function Chat() {
const [messages, setMessages] = React.useState(initialMessages)
Expand All @@ -63,17 +67,8 @@ export default function Chat() {
<div className="mx-auto flex flex-col flex-1">
<div className="flex-1">
{messages.map((message, index) => (
<div className="p-4">
<div className="flex gap-4">
<div className="bg-red-500 rounded h-8 w-8"></div>

<div className="prose">
<ReactMarkdown
children={message.content}
remarkPlugins={[remarkGfm]}
/>
</div>
</div>
<div className="p-4" key={index}>
<Message message={message} />
</div>
))}
</div>
Expand Down

0 comments on commit 8b82fdb

Please sign in to comment.