add: added homepage

This commit is contained in:
Lukian 2025-03-24 14:41:48 +01:00
parent 1f24907c80
commit 4ea8c9f2b3
11 changed files with 239 additions and 68 deletions

View file

@ -1,37 +1,22 @@
import { useParams } from "react-router-dom";
import { useEffect, useState } from "react";
import { Channel_type, Messages } from "../types";
import axios from "axios";
type Channel ={
id: number,
name: string
description: string
}
type Message = {
id: number,
user_id: number,
username: string,
content: string,
date: number
}
type Messages = Message[]
export default function Channel() {
const { id } = useParams();
const [channel, setChannel] = useState<Channel>();
const { name } = useParams();
const [channel, setChannel] = useState<Channel_type>();
const [messages, setMessages] = useState<Messages>();
useEffect(() => {
axios.get(`/api/channels/${id}`).then((res) => {
axios.get(`/api/channels/${name}`).then((res) => {
setChannel(res.data);
});
axios.get(`/api/channels/${id}/messages`).then((res) => {
axios.get(`/api/channels/${name}/messages`).then((res) => {
setMessages(res.data);
});
}, [id]);
}, [name]);
if (!channel || !messages) {
return <div>Loading...</div>;