generated from lucien/api-template
fix: fixed data refreshing on home page
This commit is contained in:
parent
9434aad013
commit
56d171439e
1 changed files with 28 additions and 1 deletions
|
@ -62,7 +62,7 @@ export default function Home({socket}: {socket: WebSocket}) {
|
|||
socket.addEventListener('message', function (event)
|
||||
{
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "new_message" || data.type === "delete_message" || data.type === "purge_channel" || data.type === "new_channel" || data.type === "delete_channel") {
|
||||
if (data.type === "new_message" || data.type === "delete_message" || data.type === "purge_channel") {
|
||||
axios
|
||||
.get("/api/lastmessages")
|
||||
.then((res) => {
|
||||
|
@ -98,6 +98,33 @@ export default function Home({socket}: {socket: WebSocket}) {
|
|||
.catch((err) => {
|
||||
console.error(err.response)
|
||||
})
|
||||
} else if (data.type === "delete_channel") {
|
||||
axios
|
||||
.get("/api/activechannels")
|
||||
.then((res) => {
|
||||
setChannels(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err.response)
|
||||
})
|
||||
|
||||
axios
|
||||
.get("/api/newchannels")
|
||||
.then((res) => {
|
||||
setNewChannels(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err.response)
|
||||
})
|
||||
|
||||
axios
|
||||
.get("/api/lastmessages")
|
||||
.then((res) => {
|
||||
setMessages(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err.response)
|
||||
})
|
||||
}
|
||||
});
|
||||
}, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue