Commit 6dad6f3a authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert AnnotationTimestamps to TS

parent 92da12dd
...@@ -73,7 +73,7 @@ function AnnotationHeader({ ...@@ -73,7 +73,7 @@ function AnnotationHeader({
// Link (URL) to single-annotation view for this annotation, if it has // Link (URL) to single-annotation view for this annotation, if it has
// been provided by the service. Note: this property is not currently // been provided by the service. Note: this property is not currently
// present on third-party annotations. // present on third-party annotations.
const annotationUrl = annotation.links?.html || ''; const annotationURL = annotation.links?.html || '';
const showEditedTimestamp = useMemo(() => { const showEditedTimestamp = useMemo(() => {
return hasBeenEdited(annotation) && !isCollapsedReply; return hasBeenEdited(annotation) && !isCollapsedReply;
...@@ -92,7 +92,7 @@ function AnnotationHeader({ ...@@ -92,7 +92,7 @@ function AnnotationHeader({
// is a third-party annotation. // is a third-party annotation.
// Also, of course, verify that there is a URL to the document (titleLink) // Also, of course, verify that there is a URL to the document (titleLink)
const documentLink = const documentLink =
annotationUrl && documentInfo.titleLink ? documentInfo.titleLink : ''; annotationURL && documentInfo.titleLink ? documentInfo.titleLink : '';
// Show document information on non-sidebar routes, assuming there is a title // Show document information on non-sidebar routes, assuming there is a title
// to show, at the least // to show, at the least
const showDocumentInfo = const showDocumentInfo =
...@@ -131,7 +131,7 @@ function AnnotationHeader({ ...@@ -131,7 +131,7 @@ function AnnotationHeader({
<AnnotationTimestamps <AnnotationTimestamps
annotationCreated={annotation.created} annotationCreated={annotation.created}
annotationUpdated={annotation.updated} annotationUpdated={annotation.updated}
annotationUrl={annotationUrl} annotationURL={annotationURL}
withEditedTimestamp={showEditedTimestamp} withEditedTimestamp={showEditedTimestamp}
/> />
</div> </div>
......
...@@ -7,14 +7,13 @@ import { ...@@ -7,14 +7,13 @@ import {
formatDate, formatDate,
} from '../../util/time'; } from '../../util/time';
/** export type AnnotationTimestampProps = {
* @typedef AnnotationTimestampsProps annotationCreated: string;
* @prop {string} annotationCreated annotationUpdated: string;
* @prop {string} annotationUpdated annotationURL?: string;
* @prop {string} [annotationUrl] /** Display a relative last-updated timestamp */
* @prop {boolean} [withEditedTimestamp] - Should a timestamp for when this withEditedTimestamp?: boolean;
* annotation was last edited be rendered? };
*/
/** /**
* Render textual timestamp information for an annotation. This includes * Render textual timestamp information for an annotation. This includes
...@@ -29,9 +28,9 @@ import { ...@@ -29,9 +28,9 @@ import {
export default function AnnotationTimestamps({ export default function AnnotationTimestamps({
annotationCreated, annotationCreated,
annotationUpdated, annotationUpdated,
annotationUrl, annotationURL,
withEditedTimestamp, withEditedTimestamp,
}) { }: AnnotationTimestampProps) {
// "Current" time, used when calculating the relative age of `timestamp`. // "Current" time, used when calculating the relative age of `timestamp`.
const [now, setNow] = useState(() => new Date()); const [now, setNow] = useState(() => new Date());
const createdDate = useMemo( const createdDate = useMemo(
...@@ -88,14 +87,14 @@ export default function AnnotationTimestamps({ ...@@ -88,14 +87,14 @@ export default function AnnotationTimestamps({
({editedString}){' '} ({editedString}){' '}
</span> </span>
)} )}
{annotationUrl ? ( {annotationURL ? (
<LinkBase <LinkBase
// The light-text hover color is not a standard color for a Link, so // The light-text hover color is not a standard color for a Link, so
// LinkBase is used here // LinkBase is used here
classes="text-color-text-light hover:text-color-text-light hover:underline" classes="text-color-text-light hover:text-color-text-light hover:underline"
target="_blank" target="_blank"
title={created.absolute} title={created.absolute}
href={annotationUrl} href={annotationURL}
> >
{created.relative} {created.relative}
</LinkBase> </LinkBase>
......
...@@ -14,7 +14,7 @@ describe('AnnotationTimestamps', () => { ...@@ -14,7 +14,7 @@ describe('AnnotationTimestamps', () => {
<AnnotationTimestamps <AnnotationTimestamps
annotationCreated="2015-05-10T20:18:56.613388+00:00" annotationCreated="2015-05-10T20:18:56.613388+00:00"
annotationUpdated="2015-05-10T20:18:56.613388+00:00" annotationUpdated="2015-05-10T20:18:56.613388+00:00"
annotationUrl="http://www.example.com" annotationURL="http://www.example.com"
withEditedTimestamp={false} withEditedTimestamp={false}
{...props} {...props}
/> />
...@@ -49,7 +49,7 @@ describe('AnnotationTimestamps', () => { ...@@ -49,7 +49,7 @@ describe('AnnotationTimestamps', () => {
}); });
it('renders an unlinked created timestamp if annotation does not have a link', () => { it('renders an unlinked created timestamp if annotation does not have a link', () => {
const wrapper = createComponent({ annotationUrl: '' }); const wrapper = createComponent({ annotationURL: '' });
const link = wrapper.find('Link'); const link = wrapper.find('Link');
const span = wrapper.find('span[data-testid="timestamp-created"]'); const span = wrapper.find('span[data-testid="timestamp-created"]');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment