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

76 lines
1.8 KiB
Markdown
Raw Normal View History

2018-04-26 23:06:48 +00: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 20:23:26 +00:00
```jsx
2018-04-13 20:27:06 +00:00
const DAY_MS = 24 * 60 * 60 * 1000;
const MONTH_MS = 30 * DAY_MS;
const YEAR_MS = 12 * MONTH_MS;
2018-04-12 20:23:26 +00:00
const tokens = ['foo', 'bar', 'baz', 'qux', 'quux'];
const fileExtensions = ['docx', 'pdf', 'txt', 'mp3', 'wmv', 'tiff'];
2018-04-13 20:27:06 +00:00
const createRandomMessage = ({startTime, timeWindow} = {}) => (props) => {
2018-04-12 20:23:26 +00:00
const now = Date.now();
const fileName =
`${_.sample(tokens)}${_.sample(tokens)}.${_.sample(fileExtensions)}`;
return {
id: _.random(now).toString(),
2018-04-13 20:27:06 +00:00
received_at: _.random(startTime, startTime + timeWindow),
2018-04-12 20:23:26 +00:00
attachments: [{
data: null,
2018-04-13 00:56:05 +00:00
fileName,
size: _.random(1000, 1000 * 1000 * 50),
2018-04-12 20:23:26 +00:00
}],
2018-04-13 00:56:05 +00:00
objectURL: `https://placekitten.com/${_.random(50, 150)}/${_.random(50, 150)}`,
2018-04-12 20:23:26 +00:00
...props,
};
};
2018-04-13 20:27:06 +00:00
const createRandomMessages = ({startTime, timeWindow}) =>
_.range(_.random(5, 10)).map(createRandomMessage({startTime, timeWindow}));
2018-04-12 20:23:26 +00:00
const startTime = Date.now();
const messages = _.sortBy(
2018-04-13 20:27:06 +00: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 20:23:26 +00:00
message => -message.received_at
);
<MediaGallery
2018-04-13 00:56:05 +00:00
i18n={window.i18n}
media={messages}
documents={messages}
2018-04-12 20:23:26 +00:00
/>
```