Created
October 11, 2020 01:42
-
-
Save cindywu/3264008bccebfef129bb74f869a8fa5a to your computer and use it in GitHub Desktop.
ChangesIndicator from js to function component using tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint-disable jsx-a11y/no-autofocus */ | |
| import React from 'react' | |
| import { formatDistanceToNow } from 'date-fns' | |
| interface Props { | |
| isLoading: boolean | |
| hasUnsavedChanges: boolean | |
| isNewPost: boolean | |
| lastSavedAtDate: any | |
| } | |
| export default function ChangesIndicator({ | |
| isLoading, | |
| hasUnsavedChanges, | |
| isNewPost, | |
| lastSavedAtDate, | |
| }) { | |
| return ( | |
| <div className={'py-1 px-2 loading-indicator ' + (isLoading && 'active')}> | |
| <i className="fa fa-circle" /> | |
| <span> | |
| {isLoading | |
| ? 'Saving...' | |
| : hasUnsavedChanges | |
| ? isNewPost | |
| ? 'Not saved yet' | |
| : `Last saved ${formatDistanceToNow(lastSavedAtDate, { | |
| includeSeconds: true, | |
| addSuffix: true, | |
| })}` | |
| : 'All changes saved'} | |
| </span> | |
| </div> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment