aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/home/TimelineBoard.tsx
blob: 2e017bf7eb2195c762528da8556649f0abfc1e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import clsx from 'clsx';
import { Link } from 'react-router-dom';
import { Spinner } from 'reactstrap';

import { TimelineInfo } from '../data/timeline';

import TimelineLogo from '../common/TimelineLogo';
import UserTimelineLogo from '../common/UserTimelineLogo';

export interface TimelineBoardProps {
  title?: string;
  timelines?: TimelineInfo[];
  className?: string;
}

const TimelineBoard: React.FC<TimelineBoardProps> = props => {
  const { title, timelines, className } = props;

  return (
    <div className={clsx('timeline-board', className)}>
      {title != null && <h3 className="text-center">{title}</h3>}
      {(() => {
        if (timelines == null) {
          return (
            <div className="d-flex flex-grow-1 justify-content-center align-items-center">
              <Spinner color="primary" />
            </div>
          );
        } else {
          return timelines.map(timeline => {
            const { name } = timeline;
            const isPersonal = name.startsWith('@');
            const url = isPersonal
              ? `/users/${timeline.owner.username}`
              : `/timelines/${name}`;
            return (
              <div key={name} className="timeline-board-item">
                {isPersonal ? (
                  <UserTimelineLogo className="icon" />
                ) : (
                  <TimelineLogo className="icon" />
                )}
                <Link to={url}>{name}</Link>
              </div>
            );
          });
        }
      })()}
    </div>
  );
};

export default TimelineBoard;