Deployed at: https://nathaliearnoux.github.io/challenge-upfluence/
- Connection to SSE stream
- Receiving posts and storing useful data for every received post
- Punchcard-like grid system to display messages per day and hour
- Counters (dynamic) to visualize number of posts received (total and per type)
- Simple header and footer
I've never used SSE streams before so I had to research it. Seems similar to Websockets, but uni-directionel (server-sent) when WS are bi-directional.
I needed to understand the form of the data sent so I copied an example taken from the stream:
data: {"youtube_video":{"id":138486971,"name":"Becoming Super Saiyan 😂 #cat #explore #meme #shorts","description":"","link":"https://www.youtube.com/watch?v=aSnmxMw8bGw","views":31,"comments":0,"likes":1,"dislikes":0,"timestamp":1713383491,"post_id":"aSnmxMw8bGw"}}
Network > click on "stream" line > EventStream
Discovered this convenient tab that lets me see the messages received live from the server.
With the EventSource class (https://developer.mozilla.org/en-US/docs/Web/API/EventSource)
New object (OOP?) with SSE URL as parameter
new EventSource("https://stream.upfluence.co/stream")
Object.entries(obj) => returns array of property-value pairs, used to store type on one hand and details on the other, gives easier access to details.
Object.entries(obj)[0] => why [0]? because it's already considered an array here.
A lot of grid and flex but the result looks ok.
Realized a little late that I forgot to handle post types independently so I had to reorganize my code. Struggled with how to structure the code so it's not too hard to read.
I ended up spending so much time on understanding the needed functions and researching everything that I forgot to consider a "mobile-first" approach and use TailwindCSS...
- RESPONSIVE !! :'(
- button to connect / disconnect to SSE stream.
- french week format: starting by monday instead of sunday. Or option to toggle.
- count displays when hovering a dot