Skip to content

Commit

Permalink
fix iframe, version 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Kotseruba committed Mar 14, 2019
1 parent 965aeb4 commit 9484237
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
3 changes: 1 addition & 2 deletions django_happymailer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@
'dummy2'
]

MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Expand Down
12 changes: 6 additions & 6 deletions happymailer/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class App extends Component {
});
}

async preview(sendTest=false) {
preview = async (sendTest=false) => {
const { template } = this.state;
const { previewUrl } = this.props;
let { variables } = this.state;
Expand Down Expand Up @@ -96,7 +96,7 @@ export default class App extends Component {
}
}

async save(redirect=true) {
save = async (redirect=true) => {
const { changeUrl, changelistUrl } = this.props;
const { template } = this.state;

Expand All @@ -116,7 +116,7 @@ export default class App extends Component {
}
}

async loadVersion(versionId) {
loadVersion = async (versionId) => {
const { changelistUrl } = this.props;
const { template } = this.state;
const url = changelistUrl + `${template.pk}/version/${versionId}/`;
Expand All @@ -140,9 +140,9 @@ export default class App extends Component {
const links = Link.state(this, 'template').pick('layout', 'enabled', 'subject', 'body');

const actions = {
save: ::this.save,
preview: ::this.preview,
loadVersion: ::this.loadVersion
save: this.save,
preview: this.preview,
loadVersion: this.loadVersion,
};

return (
Expand Down
10 changes: 7 additions & 3 deletions happymailer/src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ export default class Form extends Component {
<div>{template}</div>
</Row>
<Row label='Version'>
<div className={styles.error}>{errors.version}</div>
{errors &&
<div className={styles.error}>{errors.version}</div>
}
<Select value={this.state.version}
onChange={value => ::this.setVersion(value.value)}
onChange={value => this.setVersion(value.value)}
clearable={false}
options={window.happymailerConfig.history} />
</Row>
Expand Down Expand Up @@ -91,7 +93,9 @@ export default class Form extends Component {
</Row>

<Row label='Body'>
<div className={styles.error}>{errors.template}</div>
{errors &&
<div className={styles.error}>{errors.template}</div>
}
<Codemirror mode='mjml' valueLink={links.body}/>
</Row>

Expand Down
4 changes: 2 additions & 2 deletions happymailer/src/Notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Notify extends Component {
}, duration);
}

hideNotification(key) {
hideNotification = (key) => {
console.log('hide: ', key);
delete this.state[key];
this.setState(this.state);
Expand All @@ -49,7 +49,7 @@ export default class Notify extends Component {
return (
<div className={styles.container}>
{keys.map((key) =>
<Item id={key} key={key} hideNotification={::this.hideNotification} {...this.state[key]} />
<Item id={key} key={key} hideNotification={this.hideNotification} {...this.state[key]} />
)}
</div>
);
Expand Down
44 changes: 32 additions & 12 deletions happymailer/src/Preview.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import React from 'react';

const Preview = ({html, iframeKey})=> (
<div className={styles.root}>
<div className={styles.iphone5}>
<iframe seamless
key={iframeKey}
src={`data:text/html;charset=utf-8,${html}`}
className={styles.frame}/>
</div>
</div>
);

export default Preview;
export default class Preview extends React.PureComponent {

componentDidMount() {
this.setIframeContent();
}

componentDidUpdate(prevProps) {
if (prevProps.html !== this.props.html) {
this.setIframeContent();
}
}

render() {
return (
<div className={styles.root}>
<div className={styles.iphone5}>
<iframe
src="about:blank"
ref="iframe"
className={styles.frame}
/>
</div>
</div>
);
}

setIframeContent() {
this.refs.iframe.contentDocument.write(this.props.html);
this.refs.iframe.contentDocument.close();
}

}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-happymailer',
version='0.2.0',
version='0.2.1',
description='django email templates manager',
author='Victor Kotcheruba',
author_email='barbuzaster@gmail.com',
Expand Down

0 comments on commit 9484237

Please sign in to comment.