-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from GiuseppeArbore/OQ-21-Notification-UI
OQ-21-Notification-UI
- Loading branch information
Showing
8 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import { useEffect, useState } from "react" | ||
import { Button, Card } from 'react-bootstrap'; | ||
|
||
function SeeCounter() { | ||
|
||
const [counter, setCounter] = useState<string>(""); // this value will be updated | ||
const [error, setError] = useState<string>(""); | ||
const [ticketId, setTicketId] = useState<number>(1); | ||
|
||
|
||
useEffect(() => { | ||
|
||
const server_url='ws://localhost:3001/tickets/notification/'; | ||
const ws = new WebSocket(server_url + ticketId); | ||
|
||
ws.onmessage = (event) => { | ||
const counter_ = event.data; | ||
setCounter(counter_); | ||
console.log("Message received:", counter_); | ||
}; | ||
|
||
ws.onerror = (err) => { | ||
console.log("WebSocket error:", err); | ||
setError("Failed to connect to the server."); | ||
}; | ||
|
||
// Clean up WebSocket connection when the component is unmounted | ||
return () => { | ||
ws.close(); | ||
}; | ||
}, []); | ||
return ( | ||
<> | ||
|
||
<div> | ||
{ | ||
counter == "" && | ||
<> | ||
<h3>Please wait to be called by a counter... </h3> | ||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '3rem', justifyContent: 'space-around' }} > | ||
|
||
<Card key={counter} > | ||
<Card.Body> | ||
<img src="../../../../public/loading.gif"/> | ||
</Card.Body> | ||
</Card> | ||
</div> | ||
</> | ||
} | ||
{ | ||
counter != "" && | ||
<> | ||
<h1>Please go to the counter: </h1> | ||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '3rem', justifyContent: 'space-around' }} > | ||
|
||
<Card key={counter} > | ||
<Card.Body> | ||
<Button value={counter} variant="primary"> | ||
{counter} | ||
</Button> | ||
</Card.Body> | ||
</Card> | ||
</div> | ||
</> | ||
} | ||
</div> | ||
|
||
</> | ||
) | ||
} | ||
|
||
export default SeeCounter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters