Skip to content

Commit a8c7068

Browse files
authored
Merge pull request #171 from ant-design/update-history
Update history
2 parents 64d0d4f + 259a074 commit a8c7068

File tree

15 files changed

+127
-113
lines changed

15 files changed

+127
-113
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "landing",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"title": "Landing Pages",
55
"description": "site of Landing Pages",
66
"homepage": "http://landing.ant.design/",

site/edit/en-US.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = {
123123
'app.login.title': 'This page is locked. Please enter your password.',
124124
'app.login.noPassword': 'If you don\'t know the password, please delete current page or create a new page',
125125
'app.login.new': 'New Page',
126-
'app.layout.notification.title': '3.0 Release Notes',
127-
'app.layout.notification.content': '3.0 has been officially released. As we have made some adjustments to some templates, if your previously edited templates can not be displayed, please re-edit the new page.',
126+
'app.layout.notification.title': 'Editor update description',
127+
'app.layout.notification.content': 'In order to improve the performance and experience of editing, the style editing is currently triggered by pressing enter or leaving the input box.',
128128
},
129129
};

site/edit/template/components/ListComponents/EditorComp.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let funcData = {};
2020
const { ClassName, State, Layout, Font, BackGround, Border, Interface, Margin, Shadow, Transition } = EditorList;
2121
class EditorComp extends React.Component {
2222
onChange = (cb) => {
23-
const { cssName, currentEditCssString } = cb;
23+
const { cssName, currentEditCssString, isDrag } = cb;
2424
const { currentEditData, dispatch, templateData } = this.props;
2525
const { id } = currentEditData;
2626
const ids = id.split('-');
@@ -43,6 +43,7 @@ class EditorComp extends React.Component {
4343
};
4444
newTemplateData.data.style = (newTemplateData.data.style || []).filter(c => c.id !== cb.id);
4545
newTemplateData.data.style.push(data);
46+
newTemplateData.noHistory = isDrag;
4647
dispatch(actions.setTemplateData(newTemplateData));
4748
}
4849

site/edit/template/components/NavController/HistoryButton.jsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,33 @@ import { Tooltip, Icon } from 'antd';
33
import { FormattedMessage } from 'react-intl';
44
import classnames from 'classnames';
55
import { connect } from 'react-redux';
6-
7-
import { objectEqual } from '../../../../utils';
8-
import { getHistory, getCurrentData } from '../../../../shared/localStorage';
6+
import { mapStateToProps } from '../../../../shared/utils';
97
import * as actions from '../../../../shared/redux/actions';
108

119
class HistoryButton extends React.Component {
12-
getCurrentDataIndex = (data) => {
13-
return data.findIndex((item) => {
14-
return objectEqual(item, getCurrentData());
15-
});
16-
}
10+
currentHistory = 0;
1711

1812
onHistoryClick = (num, e) => {
1913
if (e) {
2014
e.target.focus();
2115
}
22-
23-
const history = getHistory();
24-
const current = this.getCurrentDataIndex(history);
25-
if ((!current && num === -1) || (current >= history.length - 1 && num === 1)) {
16+
const { currentEditData, dispatch, historyEdit: { num: historyNum, history } } = this.props;
17+
const { reRect } = currentEditData || {};
18+
let currentHistory = historyNum;
19+
currentHistory -= num;
20+
if ((!currentHistory && num === -1) || (currentHistory >= history.length - 1 && num === 1)) {
2621
return;
2722
}
28-
const currentData = history[current + num];
29-
30-
const { reRect, dispatch } = this.props;
23+
dispatch(actions.setCurrentHistoryNum(currentHistory));
24+
const currentData = history[currentHistory];
3125

3226
dispatch(actions.setTemplateData({
3327
data: currentData.attributes,
3428
uid: currentData.id,
35-
date: currentData.date,
3629
noHistory: 'handle',
3730
}));
3831

32+
3933
if (reRect) {
4034
reRect();
4135
}
@@ -62,16 +56,14 @@ class HistoryButton extends React.Component {
6256
}
6357

6458
render() {
65-
const history = getHistory();
66-
const undoBool = history.length > 1 && this.getCurrentDataIndex(history) > 0;
59+
const { historyEdit: { num: currentHistory, history } } = this.props;
60+
6761
const undoClassName = classnames('undo', {
68-
disabled: !undoBool,
62+
disabled: currentHistory >= history.length - 1,
6963
});
70-
const redoBool = history.length > 1 && history.length - 1 - this.getCurrentDataIndex(history) > 0;
7164
const redoClassName = classnames('redo', {
72-
disabled: !redoBool,
65+
disabled: !currentHistory,
7366
});
74-
7567
return (
7668
<ul className="history-button-wrapper">
7769
<li className={undoClassName}>
@@ -89,4 +81,4 @@ class HistoryButton extends React.Component {
8981
}
9082
}
9183

92-
export default connect()(HistoryButton);
84+
export default connect(mapStateToProps)(HistoryButton);

site/edit/template/components/NavController/index.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class NavController extends React.PureComponent {
161161
}
162162

163163
render() {
164-
const { currentEditData } = this.props;
165164
const { saveLoad, downloadLoad, publishLoad, code, codeModalShow, publishModalShow } = this.state;
166165
const menuChild = [
167166
{
@@ -220,7 +219,6 @@ class NavController extends React.PureComponent {
220219
</li>
221220
);
222221
});
223-
224222
return (
225223
<div className={this.props.className}>
226224
<a href={getNewHref('7111', null, true)}>
@@ -235,10 +233,7 @@ class NavController extends React.PureComponent {
235233
{menuChild}
236234
</ul>
237235
<NewFileButton />
238-
<HistoryButton
239-
templateData={this.props.templateData}
240-
reRect={currentEditData ? currentEditData.reRect : null}
241-
/>
236+
<HistoryButton />
242237
<Modal
243238
title={<FormattedMessage id="app.header.edit-data.header" />}
244239
visible={codeModalShow}

site/edit/template/layout.jsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ class Layout extends React.PureComponent {
3131
}
3232

3333
componentDidMount() {
34-
notification.open({
35-
placement: 'bottomRight',
36-
duration: null,
37-
message: this.props.intl.formatMessage({ id: 'app.layout.notification.title' }),
38-
description: (
39-
<div>
40-
{this.props.intl.formatMessage({ id: 'app.layout.notification.content' })}
41-
</div>
42-
),
43-
});
34+
const date = new Date();
35+
const endDate = new Date('2019/11/29 23:59:59');
36+
if (endDate.getTime() - date.getTime() > 0) {
37+
notification.open({
38+
placement: 'bottomRight',
39+
duration: 10000,
40+
message: this.props.intl.formatMessage({ id: 'app.layout.notification.title' }),
41+
description: (
42+
<div>
43+
{this.props.intl.formatMessage({ id: 'app.layout.notification.content' })}
44+
</div>
45+
),
46+
});
47+
}
4448
}
4549

4650
componentDidUpdate() {

site/edit/zh-CN.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = {
124124
'app.login.title': '此页面已加锁,请输入密码。',
125125
'app.login.noPassword': '不知道密码请删除当前面页或新建',
126126
'app.login.new': '新建页面',
127-
'app.layout.notification.title': '3.0 发布说明',
128-
'app.layout.notification.content': '3.0 已正式发布,由于我们对有些模板做了调整,如果你以前编辑的模板不能显示,请新建页面重新编辑。',
127+
'app.layout.notification.title': '编辑器功能更新说明',
128+
'app.layout.notification.content': '为提高编辑时的性能与体验,目前将样式编辑调整为按回车或离开输入框才触发。',
129129
},
130130
};

site/shared/localStorage.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import store from 'store';
22

3-
import { objectEqual } from '../utils';
4-
5-
export const LOCAL_STORAGE_HISTORY_KEY = 'ant-design-landing-record';
6-
export const LOCAL_STORAGE_CURRENT_DATA_KEY = 'ant-design-landing-current';
7-
83
/**
94
* Auth
105
*/
@@ -55,46 +50,3 @@ export function saveTemplate(template) {
5550
export function removeTemplate(tid) {
5651
store.remove(tid);
5752
}
58-
59-
60-
/**
61-
* History
62-
*/
63-
64-
export const getHistory = () => store.get(LOCAL_STORAGE_HISTORY_KEY, []);
65-
66-
// TODO: why 30?
67-
export const pushToHistory = (data) => {
68-
const history = getHistory();
69-
if (history.length >= 15) {
70-
history.shift();
71-
}
72-
history.push(data);
73-
74-
store.set(LOCAL_STORAGE_HISTORY_KEY, history);
75-
};
76-
77-
export const removeHistoryAfter = (data) => {
78-
const history = getHistory();
79-
80-
const index = history.findIndex(c => objectEqual(c, data));
81-
if (index === -1) {
82-
return;
83-
}
84-
85-
store.set(LOCAL_STORAGE_HISTORY_KEY, history.slice(0, index + 1));
86-
};
87-
88-
export const resetHistory = () => {
89-
store.set(LOCAL_STORAGE_HISTORY_KEY, []);
90-
};
91-
92-
/**
93-
* CurrentData
94-
*/
95-
96-
export const saveCurrentData = (data) => {
97-
store.set(LOCAL_STORAGE_CURRENT_DATA_KEY, data);
98-
};
99-
100-
export const getCurrentData = () => store.get(LOCAL_STORAGE_CURRENT_DATA_KEY, {});

site/shared/redux/actionTypes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const CREATE_NEW_TEMPLATE = '[landing] CREATE_NEW_TEMPLATE';
33
export const SET_TEMPLATE_DATA = '[landing] SET_TEMPLATE_DATA';
44
export const CHANGE_CHILD = '[landing] CHANGE_CHILD';
55
export const SET_USER_AND_TEMPLATE_DATA = '[landing] SET_USER_AND_TEMPLATE_DATA';
6+
export const UPDATE_HISTORY = '[landing] UPDATE_HISTORY';
67

78
export const POST_TYPE = {
89
POST_DEFAULT: '[landing] default',
@@ -13,5 +14,8 @@ export const POST_TYPE = {
1314
SET_EDIT: '[landing] setEdit',
1415
SET_MEDIA: '[landing] setMedia',
1516
SET_USER: '[landing] setUser',
17+
SET_HISTORY_NUM: '[landing] setHistoryNum',
18+
UPDATE_HISTORY_RE_NUM: '[landing] updateHistoryReNum',
19+
SAVE_HISTORY: '[landing] saveHistory',
1620
SET_USERTEMPLATE: '[landing] setUserTemplate',
1721
};

site/shared/redux/actions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,18 @@ export const setUserData = (data) => {
4747
data,
4848
};
4949
};
50+
51+
// 记录 history 步数;
52+
export const setCurrentHistoryNum = (data) => {
53+
return {
54+
type: POST_TYPE.SET_HISTORY_NUM,
55+
data,
56+
};
57+
};
58+
// 删除之前,保存当前的
59+
export const updateHistoryReNum = (data) => {
60+
return {
61+
type: POST_TYPE.UPDATE_HISTORY_RE_NUM,
62+
data,
63+
};
64+
};

0 commit comments

Comments
 (0)