signal-desktop/ts/components/conversation/media-gallery/MediaGallery.md
Scott Nonnenberg 2988da0981 Turn on all of Microsoft's recommend lint rules
Biggest changes forced by this: alt tags for all images, resulting in
new strings added to messages.json, and a new i18n paramter/prop added
in a plot of places.

Another change of note is that there are two new tslint.json files under
ts/test and ts/styleguide to relax our rules a bit there. This required
a change to our package.json script, as manually specifying the config
file there made it ignore our tslint.json files in subdirectories
2018-05-23 16:26:47 -07:00

2.1 KiB

Empty states for missing media and documents

<div style={{width: '100%', height: 300}}>
  <MediaGallery
    i18n={window.i18n}
    media={[]}
    documents={[]}
    i18n={util.i18n}
  />
</div>
const DAY_MS = 24 * 60 * 60 * 1000;
const MONTH_MS = 30 * DAY_MS;
const YEAR_MS = 12 * MONTH_MS;
const tokens = ['foo', 'bar', 'baz', 'qux', 'quux'];
const fileExtensions = ['docx', 'pdf', 'txt', 'mp3', 'wmv', 'tiff'];
const createRandomMessage = ({ startTime, timeWindow } = {}) => props => {
  const now = Date.now();
  const fileName = `${_.sample(tokens)}${_.sample(tokens)}.${_.sample(
    fileExtensions
  )}`;
  return {
    id: _.random(now).toString(),
    received_at: _.random(startTime, startTime + timeWindow),
    attachments: [
      {
        data: null,
        fileName,
        size: _.random(1000, 1000 * 1000 * 50),
      },
    ],

    objectURL: `https://placekitten.com/${_.random(50, 150)}/${_.random(
      50,
      150
    )}`,
    ...props,
  };
};

const createRandomMessages = ({ startTime, timeWindow }) =>
  _.range(_.random(5, 10)).map(createRandomMessage({ startTime, timeWindow }));

const startTime = Date.now();
const messages = _.sortBy(
  [
    ...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,
    }),
  ],
  message => -message.received_at
);

<MediaGallery i18n={util.i18n} media={messages} documents={messages} />;
const messages = [
  {
    attachments: [{ fileName: 'foo.jpg', contentType: 'application/json' }],
  },
];
<MediaGallery i18n={util.i18n} media={messages} documents={messages} />;