Skip to content

Commit 9b1363a

Browse files
author
Erika Perugachi
authored
Merge pull request #123 from JulianAdams4/attachments
Attachments
2 parents 9cfa8f5 + 5883d07 commit 9b1363a

File tree

24 files changed

+519
-195
lines changed

24 files changed

+519
-195
lines changed

electron_app/src/windows/mailbox.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { BrowserWindow } = require('electron');
1+
const { BrowserWindow, shell } = require('electron');
22
const { mailboxUrl } = require('./../window_routing');
33

44
let mailboxWindow;
@@ -23,6 +23,10 @@ const create = () => {
2323
mailboxWindow.on('closed', () => {
2424
mailboxWindow = undefined;
2525
});
26+
mailboxWindow.webContents.on('new-window', function(e, url) {
27+
e.preventDefault();
28+
shell.openExternal(url);
29+
});
2630
};
2731

2832
const show = async () => {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { convertToHumanSize } from './../utils/StringUtils';
4+
import { identifyFileType } from './../utils/FileUtils';
5+
import './attachment.css';
6+
7+
const Attachment = props => {
8+
return (
9+
<div
10+
className={`file-container ${props.isLoading ? 'container-loading' : ''}`}
11+
>
12+
<div className="file-icon">{renderFileIcon(props.file.type)}</div>
13+
<div className="file-info">
14+
<span>{props.file.name}</span>
15+
<span>{convertToHumanSize(props.file.size, true)}</span>
16+
</div>
17+
<div
18+
className="file-delete"
19+
onClick={() => props.onClearFile(props.file.name)}
20+
>
21+
<i className="icon-exit" />
22+
</div>
23+
{props.isLoading ? <div className="loading-file-bar" /> : null}
24+
</div>
25+
);
26+
};
27+
28+
const renderFileIcon = type => {
29+
const filetype = identifyFileType(type);
30+
return (
31+
<span className={`icon-container-${filetype}`}>
32+
<i className={`icon-${filetype}`} />
33+
</span>
34+
);
35+
};
36+
37+
Attachment.propTypes = {
38+
isLoading: PropTypes.bool,
39+
file: PropTypes.object,
40+
onClearFile: PropTypes.func
41+
};
42+
43+
export default Attachment;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react';
2+
import Attachment from './Attachment';
3+
4+
class AttachmentWrapper extends Component {
5+
constructor(props) {
6+
super(props);
7+
this.state = {
8+
isLoading: true
9+
};
10+
}
11+
12+
render() {
13+
return <Attachment {...this.props} isLoading={this.state.isLoading} />;
14+
}
15+
16+
componentDidMount() {
17+
setTimeout(() => {
18+
this.setState({
19+
isLoading: false
20+
});
21+
}, 3000);
22+
}
23+
}
24+
25+
export default AttachmentWrapper;
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import DropfileField from './DropfileFieldWrapper';
3+
import DropfileField from './DropfileField';
44
import Control from './Control';
55
import './body.css';
66

77
const Body = props => (
88
<div className="body-container">
99
<DropfileField
1010
isToolbarHidden={props.isToolbarHidden}
11-
htmlBody={props.htmlBody}
12-
getHtmlBody={props.getHtmlBody}
1311
blockRenderMap={props.blockRenderMap}
12+
getHtmlBody={props.getHtmlBody}
13+
htmlBody={props.htmlBody}
14+
files={props.files}
15+
isDragActive={props.isDragActive}
16+
onDragLeave={props.handleDragLeave}
17+
onDragOver={props.handleDragOver}
18+
onClearFile={props.onClearFile}
19+
onDrop={props.onDrop}
1420
/>
1521
<Control
1622
onClickTextEditor={props.onClickTextEditor}
1723
onClickSendMessage={props.onClickSendMessage}
1824
status={props.status}
25+
onDrop={props.onDrop}
1926
/>
2027
</div>
2128
);
@@ -27,7 +34,13 @@ Body.propTypes = {
2734
isToolbarHidden: PropTypes.bool,
2835
onClickSendMessage: PropTypes.func,
2936
onClickTextEditor: PropTypes.func,
30-
status: PropTypes.number
37+
status: PropTypes.number,
38+
files: PropTypes.array,
39+
onDrop: PropTypes.func,
40+
onClearFile: PropTypes.func,
41+
handleDragLeave: PropTypes.func,
42+
handleDragOver: PropTypes.func,
43+
isDragActive: PropTypes.bool
3144
};
3245

3346
export default Body;

email_composer/src/components/BodyWrapper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BodyWrapper extends Component {
1818
htmlBody={this.props.htmlBody}
1919
isToolbarHidden={this.state.isToolbarHidden}
2020
onClickTextEditor={this.handleTextEditor}
21+
onDrop={this.props.onDrop}
2122
/>
2223
);
2324
}
@@ -29,7 +30,8 @@ class BodyWrapper extends Component {
2930

3031
BodyWrapper.propTypes = {
3132
getHtmlBody: PropTypes.func,
32-
htmlBody: PropTypes.object
33+
htmlBody: PropTypes.object,
34+
onDrop: PropTypes.func
3335
};
3436

3537
export default BodyWrapper;

email_composer/src/components/Composer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ const Composer = props => (
2222
getHtmlBody={props.getHtmlBody}
2323
status={props.status}
2424
blockRenderMap={props.blockRenderMap}
25+
files={props.files}
26+
isDragActive={props.isDragActive}
27+
onClearFile={props.onClearFile}
28+
onDrop={props.onDrop}
29+
handleDragLeave={props.handleDragLeave}
30+
handleDragOver={props.handleDragOver}
2531
/>
2632
</div>
2733
);
@@ -39,7 +45,13 @@ Composer.propTypes = {
3945
onClickSendMessage: PropTypes.func,
4046
status: PropTypes.number,
4147
textSubject: PropTypes.string,
42-
toEmails: PropTypes.array
48+
toEmails: PropTypes.array,
49+
files: PropTypes.array,
50+
onDrop: PropTypes.func,
51+
onClearFile: PropTypes.func,
52+
handleDragLeave: PropTypes.func,
53+
handleDragOver: PropTypes.func,
54+
isDragActive: PropTypes.bool
4355
};
4456

4557
export default Composer;

email_composer/src/components/Control.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ const Control = props => (
1919
<div disabled={props.status === Status.WAITING}>
2020
<div className="buttons-container">
2121
<div className="button-editor">
22-
<i className="icon-attach" />
22+
<input
23+
id="input-attachments"
24+
type="file"
25+
className="hide-file-input"
26+
onChange={props.onDrop}
27+
multiple={true}
28+
/>
29+
<label htmlFor="input-attachments">
30+
<i className="icon-attach" />
31+
</label>
2332
</div>
2433
<div
2534
className="button-editor button-editor-border-left button-editor-border-right"
@@ -65,7 +74,8 @@ export const Status = {
6574
Control.propTypes = {
6675
onClickSendMessage: PropTypes.func,
6776
onClickTextEditor: PropTypes.func,
68-
status: PropTypes.number
77+
status: PropTypes.number,
78+
onDrop: PropTypes.func
6979
};
7080

7181
export default Control;

email_composer/src/components/DropfileField.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import Editor from './EditorWrapper';
4+
import AttachmentWrapper from './AttachmentWrapper';
45
import './dropfilefield.css';
56

67
const DropfileField = props => (
@@ -39,16 +40,7 @@ const DropfileField = props => (
3940
const renderPreview = (files, onClearFile) =>
4041
files.map((file, index) => {
4142
return (
42-
<div key={index} className="file-container">
43-
<div className="file-icon" />
44-
<div className="file-info">
45-
<span>{file.name}</span>
46-
<span>{file.size}</span>
47-
</div>
48-
<div className="file-delete" onClick={() => onClearFile(file.name)}>
49-
<i className="icon-exit" />
50-
</div>
51-
</div>
43+
<AttachmentWrapper key={index} file={file} onClearFile={onClearFile} />
5244
);
5345
});
5446

email_composer/src/components/DropfileFieldWrapper.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)