forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGalleryCard.jsx
More file actions
116 lines (111 loc) · 3.68 KB
/
GalleryCard.jsx
File metadata and controls
116 lines (111 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React from 'react';
import PropTypes from 'prop-types';
import {
Badge,
Image,
Truncate,
} from '@openedx/paragon';
import { FormattedMessage, FormattedDate, FormattedTime } from '@edx/frontend-platform/i18n';
// SelectableBox in paragon has a bug where you can't change selection. So we override it
import SelectableBox from '../SelectableBox';
import messages from './messages';
import { formatDuration } from '../../utils';
import LanguageNamesWidget from '../../containers/VideoEditor/components/VideoSettingsModal/components/VideoPreviewWidget/LanguageNamesWidget';
const GalleryCard = ({
asset,
thumbnailFallback,
}) => {
const [thumbnailError, setThumbnailError] = React.useState(false);
return (
<SelectableBox
className="card bg-white shadow-none border-0 py-0"
key={asset.externalUrl}
type="radio"
value={asset.id}
>
<div className="card-div d-flex flex-row flex-nowrap align-items-center">
<div
className="position-relative"
style={{
width: '200px',
height: '100px',
}}
>
{(thumbnailError && thumbnailFallback) ? (
<div style={{ width: '200px', height: '100px' }}>
{ thumbnailFallback }
</div>
) : (
<Image
style={{ border: 'none', width: '200px', height: '100px' }}
src={asset.externalUrl}
onError={thumbnailFallback && (() => setThumbnailError(true))}
/>
)}
{ asset.statusMessage && asset.statusBadgeVariant && (
<Badge variant={asset.statusBadgeVariant} style={{ position: 'absolute', left: '6px', top: '6px' }}>
<FormattedMessage {...asset.statusMessage} />
</Badge>
)}
{ asset.duration >= 0 && (
<Badge
variant="dark"
style={{
position: 'absolute',
right: '6px',
bottom: '6px',
backgroundColor: 'black',
}}
>
{formatDuration(asset.duration)}
</Badge>
)}
</div>
<div className="card-text px-3 py-2" style={{ marginTop: '10px' }}>
<h3 className="text-primary-500">
<Truncate.Deprecated>{asset.displayName}</Truncate.Deprecated>
</h3>
{ asset.transcripts && (
<div style={{ margin: '0 0 5px 0' }}>
<LanguageNamesWidget
transcripts={asset.transcripts}
/>
</div>
)}
<p className="text-gray-500" style={{ fontSize: '11px' }}>
<FormattedMessage
{...messages.addedDate}
values={{
date: <FormattedDate value={asset.dateAdded} />,
time: <FormattedTime value={asset.dateAdded} />,
}}
/>
</p>
</div>
</div>
</SelectableBox>
);
};
GalleryCard.defaultProps = {
thumbnailFallback: undefined,
};
GalleryCard.propTypes = {
asset: PropTypes.shape({
contentType: PropTypes.string,
displayName: PropTypes.string,
externalUrl: PropTypes.string,
id: PropTypes.string,
dateAdded: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
locked: PropTypes.bool,
portableUrl: PropTypes.string,
thumbnail: PropTypes.string,
url: PropTypes.string,
duration: PropTypes.number,
status: PropTypes.string,
statusMessage: PropTypes.objectOf(PropTypes.string),
statusBadgeVariant: PropTypes.string,
transcripts: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
thumbnailFallback: PropTypes.element,
};
export default GalleryCard;