Added basic frontend

This commit is contained in:
Lukian 2025-03-24 10:49:09 +01:00
parent eb0136097e
commit ae1fea3790
12 changed files with 411 additions and 155 deletions

View file

@ -0,0 +1,30 @@
import { useParams } from "react-router-dom";
import { useEffect, useState } from "react";
import axios from "axios";
export default function Channel() {
const { id } = useParams();
const [channel, setChannel] = useState({});
const [messages, setMessages] = useState([]);
useEffect(() => {
axios.get(`/api/channels/${id}`).then((res) => {
setChannel(res.data);
});
axios.get(`/api/channels/${id}/messages`).then((res) => {
setMessages(res.data);
});
}, [id]);
return (
<div>
<h1>Channel {channel.name}</h1>
<ul>
{messages.map((message) => (
<li key={message.id}>{`${message.username}: ${message.content}`}</li>
))}
</ul>
</div>
);
}