index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from "react";
  2. import TimelineItem from "./Item";
  3. import { Event, Post, ProposalDetail } from "../../types";
  4. const Timeline = (props: {
  5. posts: Post[];
  6. proposals: ProposalDetail[];
  7. status: { startTime: number };
  8. }) => {
  9. const { posts, proposals, status } = props;
  10. let events: Event[] = [];
  11. proposals.forEach(
  12. (p) =>
  13. p &&
  14. events.push({
  15. text: p.description,
  16. date: p.createdAt,
  17. category: {
  18. tag: `${p.result} Proposal`,
  19. color: p.result === `Approved` ? `green` : `red`,
  20. },
  21. link: {
  22. url: `/proposals/${p.id}`,
  23. text: `Proposal ${p.id}: ${p.title} by ${p.author.handle}`,
  24. },
  25. })
  26. );
  27. posts.forEach(
  28. (p) =>
  29. p &&
  30. events.push({
  31. text: p.text.slice(0, 200),
  32. date: p.createdAt.block,
  33. category: {
  34. tag: "Forum Post",
  35. color: `blue`,
  36. },
  37. link: {
  38. url: `/forum/threads/${p.threadId}`,
  39. text: `Post ${p.id} by ${p.author.handle}`,
  40. },
  41. })
  42. );
  43. if (!events.length) return <div />;
  44. return (
  45. <div className="timeline-container">
  46. {events
  47. .sort((a, b) => b.date - a.date)
  48. .map((event: Event, i) => (
  49. <TimelineItem event={event} key={i} startTime={status.startTime} />
  50. ))}
  51. </div>
  52. );
  53. };
  54. export default Timeline;