refactoring of claim preview aria-label format
This commit is contained in:
parent
083aff2ceb
commit
86e1cfc3dd
4 changed files with 38 additions and 42 deletions
|
@ -2058,6 +2058,7 @@
|
||||||
"Skip Navigation": "Skip Navigation",
|
"Skip Navigation": "Skip Navigation",
|
||||||
"Reset": "Reset",
|
"Reset": "Reset",
|
||||||
"Reset to original (previous) publish date": "Reset to original (previous) publish date",
|
"Reset to original (previous) publish date": "Reset to original (previous) publish date",
|
||||||
|
"%title% by %channelTitle%": "%title% by %channelTitle%",
|
||||||
"%title% by %channelTitle% %ariaDate%": "%title% by %channelTitle% %ariaDate%",
|
"%title% by %channelTitle% %ariaDate%": "%title% by %channelTitle% %ariaDate%",
|
||||||
"%title% by %channelTitle% %ariaDate%, %mediaDuration%": "%title% by %channelTitle% %ariaDate%, %mediaDuration%",
|
"%title% by %channelTitle% %ariaDate%, %mediaDuration%": "%title% by %channelTitle% %ariaDate%, %mediaDuration%",
|
||||||
"--end--": "--end--"
|
"--end--": "--end--"
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
import type { Node } from 'react';
|
import type { Node } from 'react';
|
||||||
import React, { useEffect, forwardRef } from 'react';
|
import React, { useEffect, forwardRef } from 'react';
|
||||||
import { NavLink, withRouter } from 'react-router-dom';
|
import { NavLink, withRouter } from 'react-router-dom';
|
||||||
|
import { isEmpty } from 'util/object';
|
||||||
import { lazyImport } from 'util/lazyImport';
|
import { lazyImport } from 'util/lazyImport';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { parseURI, COLLECTIONS_CONSTS, isURIEqual } from 'lbry-redux';
|
import { parseURI, COLLECTIONS_CONSTS, isURIEqual } from 'lbry-redux';
|
||||||
import { formatLbryUrlForWeb } from 'util/url';
|
import { formatLbryUrlForWeb } from 'util/url';
|
||||||
import { isEmpty } from 'util/object';
|
import { formatClaimPreviewTitle } from 'util/formatAriaLabel';
|
||||||
import FileThumbnail from 'component/fileThumbnail';
|
import FileThumbnail from 'component/fileThumbnail';
|
||||||
import UriIndicator from 'component/uriIndicator';
|
import UriIndicator from 'component/uriIndicator';
|
||||||
import PreviewOverlayProperties from 'component/previewOverlayProperties';
|
import PreviewOverlayProperties from 'component/previewOverlayProperties';
|
||||||
|
@ -27,7 +28,6 @@ import ClaimPreviewHidden from './claim-preview-no-mature';
|
||||||
import ClaimPreviewNoContent from './claim-preview-no-content';
|
import ClaimPreviewNoContent from './claim-preview-no-content';
|
||||||
import { ENABLE_NO_SOURCE_CLAIMS } from 'config';
|
import { ENABLE_NO_SOURCE_CLAIMS } from 'config';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import DateTime from 'component/dateTime';
|
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
|
|
||||||
const AbandonedChannelPreview = lazyImport(() =>
|
const AbandonedChannelPreview = lazyImport(() =>
|
||||||
|
@ -194,33 +194,7 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aria-label value for claim preview
|
// Aria-label value for claim preview
|
||||||
let ariaDate = date ? DateTime.getTimeAgoStr(date) : null;
|
let ariaLabelData = isChannelUri ? title : formatClaimPreviewTitle(title, channelTitle, date, mediaDuration);
|
||||||
let ariaLabelData = title;
|
|
||||||
|
|
||||||
if (!isChannelUri && channelTitle) {
|
|
||||||
if (mediaDuration) {
|
|
||||||
if (ariaDate) {
|
|
||||||
ariaLabelData += ariaLabelData = __('%title% by %channelTitle% %ariaDate%, %mediaDuration%', {
|
|
||||||
title,
|
|
||||||
channelTitle,
|
|
||||||
ariaDate,
|
|
||||||
mediaDuration,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
ariaLabelData += ariaLabelData = __('%title% by %channelTitle%, %mediaDuration%', {
|
|
||||||
title,
|
|
||||||
channelTitle,
|
|
||||||
mediaDuration,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (ariaDate) {
|
|
||||||
ariaLabelData += ariaLabelData = __('%title% by %channelTitle% %ariaDate%', { title, channelTitle, ariaDate });
|
|
||||||
} else {
|
|
||||||
ariaLabelData += ariaLabelData = __('%title% by %channelTitle%', { title, channelTitle });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let navigateUrl = formatLbryUrlForWeb((claim && claim.canonical_url) || uri || '/');
|
let navigateUrl = formatLbryUrlForWeb((claim && claim.canonical_url) || uri || '/');
|
||||||
if (listId) {
|
if (listId) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ChannelThumbnail from 'component/channelThumbnail';
|
||||||
import SubscribeButton from 'component/subscribeButton';
|
import SubscribeButton from 'component/subscribeButton';
|
||||||
import useGetThumbnail from 'effects/use-get-thumbnail';
|
import useGetThumbnail from 'effects/use-get-thumbnail';
|
||||||
import { formatLbryUrlForWeb } from 'util/url';
|
import { formatLbryUrlForWeb } from 'util/url';
|
||||||
|
import { formatClaimPreviewTitle } from 'util/formatAriaLabel';
|
||||||
import { parseURI, COLLECTIONS_CONSTS, isURIEqual } from 'lbry-redux';
|
import { parseURI, COLLECTIONS_CONSTS, isURIEqual } from 'lbry-redux';
|
||||||
import PreviewOverlayProperties from 'component/previewOverlayProperties';
|
import PreviewOverlayProperties from 'component/previewOverlayProperties';
|
||||||
import FileDownloadLink from 'component/fileDownloadLink';
|
import FileDownloadLink from 'component/fileDownloadLink';
|
||||||
|
@ -122,19 +123,7 @@ function ClaimPreviewTile(props: Props) {
|
||||||
const channelTitle = signingChannel && (signingChannel.value.title || signingChannel.name);
|
const channelTitle = signingChannel && (signingChannel.value.title || signingChannel.name);
|
||||||
|
|
||||||
// Aria-label value for claim preview
|
// Aria-label value for claim preview
|
||||||
let ariaLabelData = title;
|
let ariaLabelData = isChannel ? title : formatClaimPreviewTitle(title, channelTitle, date, mediaDuration);
|
||||||
|
|
||||||
if (!isChannel && channelTitle) {
|
|
||||||
ariaLabelData += ' ' + __('by %channelTitle%', { channelTitle });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (date) {
|
|
||||||
ariaLabelData += ' ' + DateTime.getTimeAgoStr(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mediaDuration) {
|
|
||||||
ariaLabelData += ', ' + mediaDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleClick(e) {
|
function handleClick(e) {
|
||||||
if (navigateUrl) {
|
if (navigateUrl) {
|
||||||
|
|
32
ui/util/formatAriaLabel.js
Normal file
32
ui/util/formatAriaLabel.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import DateTime from 'component/dateTime';
|
||||||
|
|
||||||
|
export function formatClaimPreviewTitle(title, channelTitle, date, mediaDuration) {
|
||||||
|
// Aria-label value for claim preview
|
||||||
|
let ariaDate = date ? DateTime.getTimeAgoStr(date) : null;
|
||||||
|
let ariaLabelData = title;
|
||||||
|
|
||||||
|
if (mediaDuration) {
|
||||||
|
if (ariaDate) {
|
||||||
|
ariaLabelData += ariaLabelData = __('%title% by %channelTitle% %ariaDate%, %mediaDuration%', {
|
||||||
|
title,
|
||||||
|
channelTitle,
|
||||||
|
ariaDate,
|
||||||
|
mediaDuration,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ariaLabelData += ariaLabelData = __('%title% by %channelTitle%, %mediaDuration%', {
|
||||||
|
title,
|
||||||
|
channelTitle,
|
||||||
|
mediaDuration,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ariaDate) {
|
||||||
|
ariaLabelData += ariaLabelData = __('%title% by %channelTitle% %ariaDate%', { title, channelTitle, ariaDate });
|
||||||
|
} else {
|
||||||
|
ariaLabelData += ariaLabelData = __('%title% by %channelTitle%', { title, channelTitle });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ariaLabelData;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue