|
|
@ -1,26 +1,46 @@ |
|
|
|
import React, {useEffect, useState} from 'react'; |
|
|
|
import React, {useEffect, useState} from 'react'; |
|
|
|
import {Col, Row} from "antd" |
|
|
|
import {Col, Timeline} from "antd" |
|
|
|
import socket from "../util/socket"; |
|
|
|
import socket from "../util/socket"; |
|
|
|
import {Tick} from "../types/types"; |
|
|
|
import {Tick, TimestampEvent} from "../types/types"; |
|
|
|
|
|
|
|
import shot from "../img/shot.png"; |
|
|
|
|
|
|
|
import song from "../img/song.png"; |
|
|
|
|
|
|
|
import talk from "../img/talk.png"; |
|
|
|
|
|
|
|
import time from "../img/time.png"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const images = { |
|
|
|
|
|
|
|
shot, song, talk, time |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Event extends TimestampEvent { |
|
|
|
|
|
|
|
key: number |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const Feed = () => { |
|
|
|
const Feed = () => { |
|
|
|
const [count, setCount] = useState(0); |
|
|
|
const [feedItems, setFeedItems] = useState<Event[]>([]); |
|
|
|
const [feedItems, setFeedItems] = useState([{ |
|
|
|
|
|
|
|
title: "Ha1", body: "Doei", key: -1 |
|
|
|
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
socket.on("tick_event", (tick: Tick) => { |
|
|
|
socket.on("tick_event", (tick: Tick) => { |
|
|
|
|
|
|
|
if (!tick.next) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tick.current === tick.next.timestamp) { |
|
|
|
|
|
|
|
const newItems = tick.next.events as Event[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const limit = Math.min(8, feedItems.length) |
|
|
|
|
|
|
|
for (let i = 0; i < limit; i++) { |
|
|
|
|
|
|
|
newItems.push(feedItems[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let j = 0; j < newItems.length; j++) { |
|
|
|
|
|
|
|
newItems[j].key = j; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// console.log("Shot:", tick.nextShot?.timestamp, tick.nextShot?.count)
|
|
|
|
setFeedItems(newItems); |
|
|
|
// setCount(c => c + 1);
|
|
|
|
console.log(newItems) |
|
|
|
// const newItems = feedItems;
|
|
|
|
} |
|
|
|
// newItems.push({
|
|
|
|
|
|
|
|
// title: "Ha1", body: "Doei", key: count
|
|
|
|
console.log(feedItems) |
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// setFeedItems(newItems);
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
return () => { |
|
|
@ -29,15 +49,27 @@ const Feed = () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Col className="feed" span={16}> |
|
|
|
// <Col className="feed" span={16}>
|
|
|
|
{feedItems.map(o => |
|
|
|
// {feedItems.map(o =>
|
|
|
|
<Row key={o.key} className="feed-item"> |
|
|
|
// <Row key={o.key} className="feed-item">
|
|
|
|
<Col span={4}>Tijd</Col> |
|
|
|
// <Col span={4}>Tijd</Col>
|
|
|
|
<Col span={3} offset={5}>{o.title}</Col> |
|
|
|
// <Col span={3} offset={5}>{o.title}</Col>
|
|
|
|
<Col span={3}>Icoon</Col> |
|
|
|
// <Col span={3}>Icoon</Col>
|
|
|
|
<Col span={3}>{o.body}</Col> |
|
|
|
// <Col span={3}>{o.body}</Col>
|
|
|
|
</Row> |
|
|
|
// </Row>
|
|
|
|
|
|
|
|
// )}
|
|
|
|
|
|
|
|
// </Col>
|
|
|
|
|
|
|
|
<Col className="time-feed" span={16}> |
|
|
|
|
|
|
|
<Timeline mode="alternate"> |
|
|
|
|
|
|
|
{feedItems.map(item => |
|
|
|
|
|
|
|
<Timeline.Item> |
|
|
|
|
|
|
|
{/*dot={<img src={images[item.type]} alt="logo"/>}>*/} |
|
|
|
|
|
|
|
{/*{item.text[0]} - {item.text[1]}*/} |
|
|
|
|
|
|
|
{item} |
|
|
|
|
|
|
|
</Timeline.Item> |
|
|
|
)} |
|
|
|
)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</Timeline> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|