Implement click to save for document list
This commit is contained in:
parent
8ca5a391af
commit
b74b761255
11 changed files with 61 additions and 40 deletions
|
@ -588,29 +588,44 @@
|
||||||
WhisperMessageCollection,
|
WhisperMessageCollection,
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadMessages = Signal.Components.PropTypes.Message
|
const loadMessages = Signal.Components.Types.Message
|
||||||
.loadWithObjectURL(Signal.Migrations.loadMessage);
|
.loadWithObjectURL(Signal.Migrations.loadMessage);
|
||||||
const media = await loadMessages(rawMedia);
|
const media = await loadMessages(rawMedia);
|
||||||
|
|
||||||
const mediaGalleryProps = {
|
const onItemClick = async ({ message, type }) => {
|
||||||
media,
|
switch (type) {
|
||||||
documents,
|
case 'documents': {
|
||||||
onItemClick: ({ message }) => {
|
const loadedMessage = await Signal.Migrations.loadMessage(message);
|
||||||
const lightboxProps = {
|
const attachment = loadedMessage.attachments[0];
|
||||||
imageURL: message.objectURL,
|
const timestamp = loadedMessage.received_at;
|
||||||
};
|
Signal.Types.AttachmentTS.save({ attachment, timestamp });
|
||||||
this.lightboxView = new Whisper.ReactWrapperView({
|
break;
|
||||||
Component: Signal.Components.Lightbox,
|
}
|
||||||
props: lightboxProps,
|
|
||||||
onClose: () => Signal.Backbone.Views.Lightbox.hide(),
|
case 'media': {
|
||||||
});
|
this.lightboxView = new Whisper.ReactWrapperView({
|
||||||
Signal.Backbone.Views.Lightbox.show(this.lightboxView.el);
|
Component: Signal.Components.Lightbox,
|
||||||
},
|
props: {
|
||||||
|
imageURL: message.objectURL,
|
||||||
|
},
|
||||||
|
onClose: () => Signal.Backbone.Views.Lightbox.hide(),
|
||||||
|
});
|
||||||
|
Signal.Backbone.Views.Lightbox.show(this.lightboxView.el);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new TypeError(`Unknown attachment type: '${type}'`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const view = new Whisper.ReactWrapperView({
|
const view = new Whisper.ReactWrapperView({
|
||||||
Component: Signal.Components.MediaGallery,
|
Component: Signal.Components.MediaGallery,
|
||||||
props: mediaGalleryProps,
|
props: {
|
||||||
|
documents,
|
||||||
|
media,
|
||||||
|
onItemClick,
|
||||||
|
},
|
||||||
onClose: () => this.resetPanel(),
|
onClose: () => this.resetPanel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -169,14 +169,14 @@ const { MediaGallery } =
|
||||||
require('./ts/components/conversation/media-gallery/MediaGallery');
|
require('./ts/components/conversation/media-gallery/MediaGallery');
|
||||||
const { Quote } = require('./ts/components/conversation/Quote');
|
const { Quote } = require('./ts/components/conversation/Quote');
|
||||||
|
|
||||||
const PropTypesMessage =
|
const MediaGalleryMessage =
|
||||||
require('./ts/components/conversation/media-gallery/propTypes/Message');
|
require('./ts/components/conversation/media-gallery/types/Message');
|
||||||
|
|
||||||
window.Signal.Components = {
|
window.Signal.Components = {
|
||||||
Lightbox,
|
Lightbox,
|
||||||
MediaGallery,
|
MediaGallery,
|
||||||
PropTypes: {
|
Types: {
|
||||||
Message: PropTypesMessage,
|
Message: MediaGalleryMessage,
|
||||||
},
|
},
|
||||||
Quote,
|
Quote,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,10 +3,11 @@
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { AttachmentType } from './types/AttachmentType';
|
||||||
import { DocumentListItem } from './DocumentListItem';
|
import { DocumentListItem } from './DocumentListItem';
|
||||||
import { ItemClickEvent } from './events/ItemClickEvent';
|
import { ItemClickEvent } from './types/ItemClickEvent';
|
||||||
import { MediaGridItem } from './MediaGridItem';
|
import { MediaGridItem } from './MediaGridItem';
|
||||||
import { Message } from './propTypes/Message';
|
import { Message } from './types/Message';
|
||||||
import { missingCaseError } from '../../../util/missingCaseError';
|
import { missingCaseError } from '../../../util/missingCaseError';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
|
@ -30,7 +31,7 @@ const styles = {
|
||||||
interface Props {
|
interface Props {
|
||||||
i18n: (value: string) => string;
|
i18n: (value: string) => string;
|
||||||
header?: string;
|
header?: string;
|
||||||
type: 'media' | 'documents';
|
type: AttachmentType;
|
||||||
messages: Array<Message>;
|
messages: Array<Message>;
|
||||||
onItemClick?: (event: ItemClickEvent) => void;
|
onItemClick?: (event: ItemClickEvent) => void;
|
||||||
}
|
}
|
||||||
|
@ -82,11 +83,11 @@ export class AttachmentSection extends React.Component<Props, {}> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private createClickHandler = (message: Message) => () => {
|
private createClickHandler = (message: Message) => () => {
|
||||||
const { onItemClick } = this.props;
|
const { onItemClick, type } = this.props;
|
||||||
if (!onItemClick) {
|
if (!onItemClick) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemClick({ message });
|
onItemClick({ type, message });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,10 @@ import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { AttachmentSection } from './AttachmentSection';
|
import { AttachmentSection } from './AttachmentSection';
|
||||||
|
import { AttachmentType } from './types/AttachmentType';
|
||||||
import { groupMessagesByDate } from './groupMessagesByDate';
|
import { groupMessagesByDate } from './groupMessagesByDate';
|
||||||
import { ItemClickEvent } from './events/ItemClickEvent';
|
import { ItemClickEvent } from './types/ItemClickEvent';
|
||||||
import { Message } from './propTypes/Message';
|
import { Message } from './types/Message';
|
||||||
|
|
||||||
type AttachmentType = 'media' | 'documents';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
documents: Array<Message>;
|
documents: Array<Message>;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Message } from './propTypes/Message';
|
import { Message } from './types/Message';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
message: Message;
|
message: Message;
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
/**
|
|
||||||
* @prettier
|
|
||||||
*/
|
|
||||||
import { Message } from '../propTypes/Message';
|
|
||||||
|
|
||||||
export interface ItemClickEvent {
|
|
||||||
message: Message;
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { compact, groupBy, sortBy } from 'lodash';
|
import { compact, groupBy, sortBy } from 'lodash';
|
||||||
|
|
||||||
import { Message } from './propTypes/Message';
|
import { Message } from './types/Message';
|
||||||
// import { missingCaseError } from '../../../util/missingCaseError';
|
// import { missingCaseError } from '../../../util/missingCaseError';
|
||||||
|
|
||||||
type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth';
|
type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth';
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
export type AttachmentType = 'media' | 'documents';
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
import { AttachmentType } from './AttachmentType';
|
||||||
|
import { Message } from './Message';
|
||||||
|
|
||||||
|
export interface ItemClickEvent {
|
||||||
|
message: Message;
|
||||||
|
type: AttachmentType;
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ import {
|
||||||
groupMessagesByDate,
|
groupMessagesByDate,
|
||||||
Section,
|
Section,
|
||||||
} from '../../../components/conversation/media-gallery/groupMessagesByDate';
|
} from '../../../components/conversation/media-gallery/groupMessagesByDate';
|
||||||
import { Message } from '../../../components/conversation/media-gallery/propTypes/Message';
|
import { Message } from '../../../components/conversation/media-gallery/types/Message';
|
||||||
|
|
||||||
const toMessage = (date: Date): Message => ({
|
const toMessage = (date: Date): Message => ({
|
||||||
id: date.toUTCString(),
|
id: date.toUTCString(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue