Kopie van https://gitlab.com/studieverenigingvia/ict/centurion met een paar aanpassingen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

4 years ago
import React, {useState} from 'react';
4 years ago
import {Col, Timeline} from "antd"
import {Tick, TimestampEvent} from "../types/types";
4 years ago
import {useSocket} from "use-socketio/lib";
4 years ago
import FeedItem from "./FeedItem"
import { TransitionGroup, CSSTransition } from 'react-transition-group'
4 years ago
const Feed = () => {
4 years ago
const [feedItems, setFeedItems] = useState<TimestampEvent[]>([]);
4 years ago
4 years ago
useSocket("tick_event", async (tick: Tick) => {
if (!tick.next) {
return;
}
4 years ago
4 years ago
if (tick.current === tick.next.timestamp) {
// Current tick is a new event.
4 years ago
4 years ago
const newItems: any[] = [];
for (let i = 0; i < feedItems.length; i++) {
newItems.push(feedItems[i]);
}
for (let j = 0; j < tick.next.events.length; j++) {
newItems.push(tick.next.events[j]);
4 years ago
}
4 years ago
4 years ago
// @ts-ignore
4 years ago
setFeedItems(newItems);
4 years ago
}
4 years ago
});
4 years ago
return (
4 years ago
<Col className="time-feed" span={24} md={16}>
<TransitionGroup className="feed-reverse">
{feedItems.map((item, i) =>
<CSSTransition timeout={500} classNames="fade" key={i}>
<FeedItem {...item}/>
</CSSTransition>
4 years ago
)}
4 years ago
</TransitionGroup>
4 years ago
</Col>
);
};
export default Feed;