mirror of
https://github.com/timepill/timepill-app.git
synced 2025-04-30 09:59:31 +08:00
存草稿逻辑
写日记页面每隔5秒保存一次编辑内容作为草稿 保存日记或取消保存,退出页面时清空草稿 异常退出时,若有之前保存下来的草稿则恢复
This commit is contained in:
parent
a52ede2fcb
commit
d95a224c60
4 changed files with 35 additions and 15 deletions
|
@ -28,7 +28,6 @@ export default class Notification extends Component {
|
||||||
if(msg && msg.type) {
|
if(msg && msg.type) {
|
||||||
if(msg.type == 1) {
|
if(msg.type == 1) {
|
||||||
return this.renderComment(msg);
|
return this.renderComment(msg);
|
||||||
|
|
||||||
} else if(msg.type == 2) {
|
} else if(msg.type == 2) {
|
||||||
return this.renderFollow(msg);
|
return this.renderFollow(msg);
|
||||||
} else if(msg.type == 3) {
|
} else if(msg.type == 3) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ export default class NotificationList extends Component {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
let notifications = await this.getMessages();
|
let notifications = await this.getMessages();
|
||||||
|
|
||||||
this.notificationsData = notifications;
|
this.notificationsData = notifications;
|
||||||
this.setNotifications(notifications);
|
this.setNotifications(notifications);
|
||||||
this.setState({error: false});
|
this.setState({error: false});
|
||||||
|
@ -230,16 +231,7 @@ export default class NotificationList extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationList.propTypes = {
|
|
||||||
// isHistory: PropTypes.boolean,
|
|
||||||
// onRefresh: PropTypes.func,
|
|
||||||
// isSetRead: PropTypes.boolean
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// NotificationList.defaultProps = {
|
|
||||||
// isHistory: true,
|
|
||||||
// isSetRead: false,
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ import {Icon} from '../style/icon';
|
||||||
import Color from '../style/color';
|
import Color from '../style/color';
|
||||||
import Api from '../util/api';
|
import Api from '../util/api';
|
||||||
import Msg from '../util/msg';
|
import Msg from '../util/msg';
|
||||||
import Event from "../util/event";
|
import Event from '../util/event';
|
||||||
|
import Token from '../util/token';
|
||||||
|
|
||||||
import NotebookLine from '../component/notebook/notebookLine';
|
import NotebookLine from '../component/notebook/notebookLine';
|
||||||
import ImageAction from '../component/image/imageAction'
|
import ImageAction from '../component/image/imageAction'
|
||||||
|
@ -54,6 +55,8 @@ export default class WritePage extends Component {
|
||||||
fadeAnimOpacity: new Animated.Value(0),
|
fadeAnimOpacity: new Animated.Value(0),
|
||||||
fadeAnimHeight: new Animated.Value(0)
|
fadeAnimHeight: new Animated.Value(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.draftTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static options(passProps) {
|
static options(passProps) {
|
||||||
|
@ -102,6 +105,9 @@ export default class WritePage extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
closePage() {
|
closePage() {
|
||||||
|
clearInterval(this.draftTimer);
|
||||||
|
Token.setDraft('');
|
||||||
|
|
||||||
this.contentInput.blur();
|
this.contentInput.blur();
|
||||||
if (this.diary || this.topic) {
|
if (this.diary || this.topic) {
|
||||||
Navigation.pop(this.props.componentId);
|
Navigation.pop(this.props.componentId);
|
||||||
|
@ -112,10 +118,20 @@ export default class WritePage extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
Token.getDraft().then(draft => {
|
||||||
|
if(draft) {
|
||||||
|
this.setState({
|
||||||
|
content: draft,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.resetDraftTimer();
|
||||||
|
|
||||||
this.loadNotebook().then(notebookCount => {
|
this.loadNotebook().then(notebookCount => {
|
||||||
if(notebookCount > 0) {
|
if(notebookCount > 0) {
|
||||||
InteractionManager.runAfterInteractions(() => {
|
InteractionManager.runAfterInteractions(() => {
|
||||||
this && this.contentInput && this.contentInput.focus();
|
this.contentInput && this.contentInput.focus();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Alert.alert('提示', '没有可用日记本,无法写日记',[
|
Alert.alert('提示', '没有可用日记本,无法写日记',[
|
||||||
|
@ -140,6 +156,19 @@ export default class WritePage extends Component {
|
||||||
this.notebookListener.remove();
|
this.notebookListener.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetDraftTimer() {
|
||||||
|
if(this.draftTimer) {
|
||||||
|
clearInterval(this.draftTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draftTimer = setInterval(() => {
|
||||||
|
let content = this.state.content;
|
||||||
|
if(content) {
|
||||||
|
Token.setDraft(content);
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
openModal() {
|
openModal() {
|
||||||
this.contentInput.blur();
|
this.contentInput.blur();
|
||||||
this.setState({modalVisible: true});
|
this.setState({modalVisible: true});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage';
|
||||||
var base64 = require('base-64');
|
var base64 = require('base-64');
|
||||||
|
|
||||||
|
|
||||||
class TokenManager {
|
class Token {
|
||||||
|
|
||||||
generateToken(username, password) {
|
generateToken(username, password) {
|
||||||
return 'Basic ' + base64.encode(username + ":" + password);
|
return 'Basic ' + base64.encode(username + ":" + password);
|
||||||
|
@ -101,4 +101,4 @@ class TokenManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new TokenManager()
|
export default new Token()
|
||||||
|
|
Loading…
Reference in a new issue