diff options
| author | crupest <crupest@outlook.com> | 2020-09-03 21:10:58 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-09-03 21:10:58 +0800 |
| commit | 01446b3c8306112cd965eeaaa40a0ac573cc374e (patch) | |
| tree | 92516444e0955624dc0bc1d9109eff46d977052d /Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx | |
| parent | d8a2ca7d0ad9afdd01c654bea29b2a6c2b92ff2c (diff) | |
| download | timeline-01446b3c8306112cd965eeaaa40a0ac573cc374e.tar.gz timeline-01446b3c8306112cd965eeaaa40a0ac573cc374e.tar.bz2 timeline-01446b3c8306112cd965eeaaa40a0ac573cc374e.zip | |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx')
| -rw-r--r-- | Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx b/Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx new file mode 100644 index 00000000..e67cfb43 --- /dev/null +++ b/Timeline/ClientApp/src/app/views/timeline-common/SyncStatusBadge.tsx @@ -0,0 +1,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; |
