-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommonItemRenderer.js
221 lines (211 loc) · 7.69 KB
/
CommonItemRenderer.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { flattenToAppURL } from '@plone/volto/helpers';
import { Link } from 'react-router-dom';
import moment from 'moment';
import { useIntl } from 'react-intl';
import { getEventCard, getEventDate, getEventTime } from './sharedUtils';
import processItemsForRecurrence from './processItemsForRecurrence';
import RenderImage from './renderImage';
const columnClassMap = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine',
10: 'ten',
11: 'eleven',
12: 'twelve',
};
const CommonItemRenderer = ({
items,
showRecurrence,
quote,
showTitle,
eventCard,
titleTag: TitleTag = 'h3',
eventDate,
eventTime,
eventLocation,
showDescription,
effectiveDate,
expirationDate,
isEditMode,
imageSide,
imageWidth = 4,
howManyColumns,
fetchPriority,
}) => {
const intl = useIntl();
// Process items based on recurrence setting
const processedItems = useMemo(() => {
if (showRecurrence) {
return processItemsForRecurrence(items); // Sort by next recurrence date
}
return items.map(item => ({
...item,
url: flattenToAppURL(item['@id']),
imageSrc: item.image_field
? `${flattenToAppURL(item['@id'])}/@@images/preview_image`
: null,
}));
}, [items, showRecurrence]);
const renderMetadata = useMemo(() => {
return item => (
<>
{eventDate && <span className='start-date'>{getEventDate(item)}</span>}
{eventTime && eventDate && <span> | </span>}
{eventTime && (
<span className='start-time'>
{getEventTime(item) === '12:00 AM - 11:59 PM' ? 'All Day' : getEventTime(item)}
</span>
)}
</>
);
}, [eventDate, eventTime]);
const renderContent = item => (
<>
{quote && (
<>
<blockquote>{item.description}</blockquote>
<div className='styled-slate right has--align--right align styled'>
{item.title || item.id}
</div>
</>
)}
{eventCard && getEventCard(item)}
{(eventDate || eventTime) && <div className='advancedDatetime'>{renderMetadata(item)}</div>}
{showTitle && (
<TitleTag className='threelines'>
{imageSide === 'background' ? (
item.title || item.id
) : (
!isEditMode ? (
<Link to={item.url}>
{item.title ? item.title : item.id}
</Link>
) : (
item.title || item.id
)
)}
</TitleTag>
)}
{eventLocation && <p>{item.location}</p>}
{effectiveDate && <p className='effectiveDate'>{moment(item.effective).format('L')}</p>}
{expirationDate && <p>Expiration: {moment(item.expires).format('L')}</p>}
{showDescription && item.description && <p>{item.description}</p>}
</>
);
return (
<div className='fade-in loaded'>
{processedItems.map(item => (
<div key={item['@id']} className='ui one column grid advanced-item'>
<div className={`column ${imageSide}`}>
{imageSide === 'background' ? (
<div className='backgroundimage'>
<Link to={item.url} condition={!isEditMode}>
<div className='focuspoint'>
{item.imageSrc ? (
<Link to={item.url}>
<img
sizes='(min-width: 768px) and (max-width: 991px) 171px, (min-width: 992px) and (max-width: 1199px) 223px, (min-width: 1200px) 272px'
srcSet={`
${item.imageSrc}/mini 200w,
${item.imageSrc}/preview 400w,
${item.imageSrc}/teaser 600w,
${item.imageSrc}/large 800w,
${item.imageSrc}/larger 1000w,
${item.imageSrc}/great 1200w,
${item.imageSrc}/huge 1600w
`}
src={`${item.imageSrc}/preview`}
alt={item.title || ''}
className='ui image listImage'
loading={fetchPriority === 'high' ? 'eager' : 'lazy'}
fetchpriority={fetchPriority}
width='100%'
height='auto'
style={{ aspectRatio: '16/9' }}
/>
</Link>
) : (
<RenderImage
item={item}
isEditMode={isEditMode}
howManyColumns={howManyColumns}
fetchPriority={fetchPriority}
/>
)}
</div>
<div className='info-text'>{renderContent(item)}</div>
</Link>
</div>
) : (
<div className='ui grid'>
{['up', 'left'].includes(imageSide) && (
<div className={`${
['up', 'down'].includes(imageSide) ? 'twelve' : columnClassMap[imageWidth]
} wide column advancedImage`}>
<Link to={item.url}>
<RenderImage
item={item}
isEditMode={isEditMode}
howManyColumns={howManyColumns}
fetchPriority={fetchPriority}
/>
</Link>
</div>
)}
<div className={`${
['up', 'down'].includes(imageSide) || !['left', 'right'].includes(imageSide)
? 'twelve'
: columnClassMap[12 - imageWidth]
} wide column`}>
{renderContent(item)}
</div>
{['right', 'down'].includes(imageSide) && (
<div className={`${
['up', 'down'].includes(imageSide) ? 'twelve' : columnClassMap[imageWidth]
} wide column advancedImage`}>
<Link to={item.url}>
<RenderImage
item={item}
isEditMode={isEditMode}
howManyColumns={howManyColumns}
fetchPriority={fetchPriority}
/>
</Link>
</div>
)}
</div>
)}
</div>
</div>
))}
</div>
);
};
CommonItemRenderer.propTypes = {
items: PropTypes.arrayOf(PropTypes.object).isRequired,
showRecurrence: PropTypes.bool,
quote: PropTypes.bool,
showTitle: PropTypes.bool,
eventCard: PropTypes.bool,
titleTag: PropTypes.string,
eventDate: PropTypes.bool,
eventTime: PropTypes.bool,
eventLocation: PropTypes.bool,
showDescription: PropTypes.bool,
effectiveDate: PropTypes.bool,
expirationDate: PropTypes.bool,
isEditMode: PropTypes.bool,
imageSide: PropTypes.string,
imageWidth: PropTypes.number,
howManyColumns: PropTypes.number,
fetchPriority: PropTypes.string,
};
export default CommonItemRenderer;