basic conv display + fetch messages fnc
This commit is contained in:
@@ -23,20 +23,31 @@ export function HotelProvider({ accessToken, children }) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function updateRoomStatus(roomId, status) {
|
||||
await fetch(`${API_BASE}/rooms/clean_db_update/${roomId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessTokenSingle}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
async function updateRoomStatus(roomId, status) {
|
||||
await fetch(`${API_BASE}/rooms/clean_db_update/${roomId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessTokenSingle}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
|
||||
// refresh cached rooms
|
||||
const updated = await fetchRooms();
|
||||
setRooms(updated);
|
||||
}
|
||||
// refresh cached rooms
|
||||
const updated = await fetchRooms();
|
||||
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() {
|
||||
const res = await fetch(`${API_BASE}/chat/get_conv`, {
|
||||
@@ -53,13 +64,30 @@ async function updateRoomStatus(roomId, status) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function fetchHotelUsers() {
|
||||
const res = await fetch(`${API_BASE}/chat/hotel_users`, {
|
||||
headers: { Authorization: `Bearer ${accessTokenSingle}` },
|
||||
async function fetchMessages({ conv_id }) {
|
||||
|
||||
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 ---
|
||||
useEffect(() => {
|
||||
if (!accessToken) return;
|
||||
@@ -68,12 +96,12 @@ async function updateRoomStatus(roomId, status) {
|
||||
const [roomsData, convData, usersData] = await Promise.all([
|
||||
fetchRooms(),
|
||||
fetchConversations(),
|
||||
//fetchHotelUsers(),
|
||||
fetchHotelUsers(),
|
||||
]);
|
||||
|
||||
setRooms(roomsData);
|
||||
setConversations(convData);
|
||||
//setUsers(usersData);
|
||||
setUsers(usersData);
|
||||
}
|
||||
|
||||
load();
|
||||
@@ -86,6 +114,7 @@ async function updateRoomStatus(roomId, status) {
|
||||
conversations,
|
||||
users,
|
||||
updateRoomStatus,
|
||||
fetchMessages,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user