basic conv display + fetch messages fnc

This commit is contained in:
2025-12-04 23:36:54 +01:00
parent 787a248e6f
commit e1b588fc61
8 changed files with 153 additions and 62 deletions

View File

@@ -38,6 +38,17 @@ async function updateRoomStatus(roomId, status) {
setRooms(updated); setRooms(updated);
} }
async function fetchHotelUsers() {
const res = await fetch(`${API_BASE}/chat/hotel_users`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessTokenSingle}`,
"Content-Type": "application/json",
},
});
return res.json();
}
async function fetchConversations() { async function fetchConversations() {
const res = await fetch(`${API_BASE}/chat/get_conv`, { const res = await fetch(`${API_BASE}/chat/get_conv`, {
method: "POST", method: "POST",
@@ -53,13 +64,30 @@ async function updateRoomStatus(roomId, status) {
return res.json(); return res.json();
} }
async function fetchHotelUsers() { async function fetchMessages({ conv_id }) {
const res = await fetch(`${API_BASE}/chat/hotel_users`, {
headers: { Authorization: `Bearer ${accessTokenSingle}` }, const payload = {
conv_id,
timestamp: "2025-09-25 11:05:33",
};
console.log(JSON.stringify(payload));
const res = await fetch(`${API_BASE}/chat/get_message`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessTokenSingle}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
}); });
return res.json();
return res;
//return res.json
} }
// --- INITIAL DATA LOADING --- // --- INITIAL DATA LOADING ---
useEffect(() => { useEffect(() => {
if (!accessToken) return; if (!accessToken) return;
@@ -68,12 +96,12 @@ async function updateRoomStatus(roomId, status) {
const [roomsData, convData, usersData] = await Promise.all([ const [roomsData, convData, usersData] = await Promise.all([
fetchRooms(), fetchRooms(),
fetchConversations(), fetchConversations(),
//fetchHotelUsers(), fetchHotelUsers(),
]); ]);
setRooms(roomsData); setRooms(roomsData);
setConversations(convData); setConversations(convData);
//setUsers(usersData); setUsers(usersData);
} }
load(); load();
@@ -86,6 +114,7 @@ async function updateRoomStatus(roomId, status) {
conversations, conversations,
users, users,
updateRoomStatus, updateRoomStatus,
fetchMessages,
}} }}
> >
{children} {children}

View File

@@ -1,6 +1,8 @@
import { HotelProvider, useHotel } from "./HotelContext"; import { HotelProvider, useHotel } from "./HotelContext";
import RoomWidget from "./widget/roomWidget" import RoomWidget from "./widget/roomWidget"
import ChatWidget from "./widget/chatWidget"
import "./MainApp.css"
export default function MainAppWrapper() { export default function MainAppWrapper() {
const accessToken = localStorage.getItem("access_tokens"); const accessToken = localStorage.getItem("access_tokens");
@@ -22,15 +24,15 @@ function MainApp() {
<h2>Access token</h2> <h2>Access token</h2>
<pre>{accessToken}</pre> <pre>{accessToken}</pre>
<h3>Rooms: {rooms.length}</h3>
<section> <h3>Conversations: {conversations.length}</h3>
<h3>Users: {users.length}</h3>
<h2>Dashboard</h2> <h2>Dashboard</h2>
<ul> <section className="main">
<li>Rooms: {rooms.length}</li>
<RoomWidget roomlist={rooms}/> <RoomWidget roomlist={rooms}/>
<li>Conversations: {conversations.length}</li> <ChatWidget convlist={conversations}/>
<li>Users: {users.length}</li>
</ul>
</section> </section>
</div> </div>
); );

View File

@@ -0,0 +1,6 @@
.main {
display: flex;
justify-content: space-around;
background-color: rgb(160, 149, 199);
}

View File

@@ -1,11 +1,14 @@
.grid { .grid {
display: grid; display: flex;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); justify-items: space-around;
gap: 1px; gap: 1px;
background-color: #777777; background-color: #777777;
} }
.card { .card {
display: flex;
flex-direction: column;
justify-content: space-around;
gap: 1px; gap: 1px;
background-color: #a3a3a3; background-color: #a3a3a3;
padding: 5px; padding: 5px;

View File

@@ -0,0 +1,11 @@
.convcard {
background-color: brown;
}
.convlist {
display: flex;
flex-direction: column;
align-items: right;
background-color: darkcyan;
}

View File

@@ -0,0 +1,40 @@
import { useHotel } from "../HotelContext";
import { useState } from "react";
//import {fetchMessage} from .
import "./chatWidget.css"
export default function ChatWidget({convlist}) {
return (
<div className="convlist">
{convlist.map(conv => (
<ConvCard
key={conv.id}
id={conv.id}
title={conv.title}
/>
))}
</div>
);
}
function ConvCard({id, title}) {
const {fetchMessages} = useHotel();
return(
<div className="convcard">
<h3>ConvId : {id} </h3>
<h3>Name : {title}</h3>
<p onClick={() => fetchMessages({conv_id: 4})}> GET MESSAAGE</p>
</div>
)
}
function MessagesBox({id}) {
}

View File

@@ -19,11 +19,11 @@ export default function RoomWidget({ roomlist }) {
} }
function RoomCard({ number, status ,id}) { function RoomCard({ number, status ,id}) {
const { updateRoomStatus } = useHotel(); const { updateRoomStatus } = useHotel();
const [editing, setEditing] = useState(false); const [editing, setEditing] = useState(false);
const [value, SetValue] = useState(status); const [value, SetValue] = useState(status);
function submit() { function submit() {
updateRoomStatus(id,value); updateRoomStatus(id,value);
setEditing(false); setEditing(false);