aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx
blob: e67cfb4384c9d6542b9b3701853ee8bf201dbd9f (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
55
56
57
58
import React from "react";
import clsx from "clsx";
import { useTranslation } from "react-i18next";

import { UiLogicError } from "@/common";

export type TimelineSyncStatus = "syncing" | "synced" | "offline";

const SyncStatusBadge: React.FC<{
  status: TimelineSyncStatus;
  style?: React.CSSProperties;
  className?: string;
}> = ({ status, style, className }) => {
  const { t } = useTranslation();

  return (
    <div style={style} className={clsx("timeline-sync-state-badge", className)}>
      {(() => {
        switch (status) {
          case "syncing": {
            return (
              <>
                <span className="timeline-sync-state-badge-pin bg-warning" />
                <span className="text-warning">
                  {t("timeline.postSyncState.syncing")}
                </span>
              </>
            );
          }
          case "synced": {
            return (
              <>
                <span className="timeline-sync-state-badge-pin bg-success" />
                <span className="text-success">
                  {t("timeline.postSyncState.synced")}
                </span>
              </>
            );
          }
          case "offline": {
            return (
              <>
                <span className="timeline-sync-state-badge-pin bg-danger" />
                <span className="text-danger">
                  {t("timeline.postSyncState.offline")}
                </span>
              </>
            );
          }
          default:
            throw new UiLogicError("Unknown sync state.");
        }
      })()}
    </div>
  );
};

export default SyncStatusBadge;