Skip to content

Instantly share code, notes, and snippets.

@cindywu
Created October 11, 2020 01:42
Show Gist options
  • Select an option

  • Save cindywu/3264008bccebfef129bb74f869a8fa5a to your computer and use it in GitHub Desktop.

Select an option

Save cindywu/3264008bccebfef129bb74f869a8fa5a to your computer and use it in GitHub Desktop.
ChangesIndicator from js to function component using tsx
/* 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