session-desktop/ts/components/conversation/media-gallery/MediaGallery.md

77 lines
1.8 KiB
Markdown
Raw Normal View History

2018-04-27 01:06:48 +02:00
### Empty states for missing media and documents
```
<div style={{width: '100%', height: 300}}>
<MediaGallery
i18n={window.i18n}
media={[]}
documents={[]}
/>
</div>
```
### Media gallery with media and documents
2018-04-12 22:23:26 +02:00
```jsx
2018-04-13 22:27:06 +02:00
const DAY_MS = 24 * 60 * 60 * 1000;
const MONTH_MS = 30 * DAY_MS;
const YEAR_MS = 12 * MONTH_MS;
2018-04-12 22:23:26 +02:00
const tokens = ['foo', 'bar', 'baz', 'qux', 'quux'];
const fileExtensions = ['docx', 'pdf', 'txt', 'mp3', 'wmv', 'tiff'];
const createRandomMessage = ({ startTime, timeWindow } = {}) => props => {
2018-04-12 22:23:26 +02:00
const now = Date.now();
const fileName = `${_.sample(tokens)}${_.sample(tokens)}.${_.sample(
fileExtensions
)}`;
2018-04-12 22:23:26 +02:00
return {
id: _.random(now).toString(),
2018-04-13 22:27:06 +02:00
received_at: _.random(startTime, startTime + timeWindow),
attachments: [
{
data: null,
fileName,
size: _.random(1000, 1000 * 1000 * 50),
},
],
2018-04-12 22:23:26 +02:00
objectURL: `https://placekitten.com/${_.random(50, 150)}/${_.random(
50,
150
)}`,
2018-04-12 22:23:26 +02:00
...props,
};
};
const createRandomMessages = ({ startTime, timeWindow }) =>
_.range(_.random(5, 10)).map(createRandomMessage({ startTime, timeWindow }));
2018-04-13 22:27:06 +02:00
2018-04-12 22:23:26 +02:00
const startTime = Date.now();
const messages = _.sortBy(
2018-04-13 22:27:06 +02:00
[
...createRandomMessages({
startTime,
timeWindow: DAY_MS,
}),
...createRandomMessages({
startTime: startTime - DAY_MS,
timeWindow: DAY_MS,
}),
...createRandomMessages({
startTime: startTime - 3 * DAY_MS,
timeWindow: 3 * DAY_MS,
}),
...createRandomMessages({
startTime: startTime - 30 * DAY_MS,
timeWindow: 15 * DAY_MS,
}),
...createRandomMessages({
startTime: startTime - 365 * DAY_MS,
timeWindow: 300 * DAY_MS,
}),
],
2018-04-12 22:23:26 +02:00
message => -message.received_at
);
<MediaGallery i18n={window.i18n} media={messages} documents={messages} />;
2018-04-12 22:23:26 +02:00
```