diff --git a/src/component/notification/notification.js b/src/component/notification/notification.js index 70d3898..efb2657 100644 --- a/src/component/notification/notification.js +++ b/src/component/notification/notification.js @@ -2,21 +2,11 @@ import React, {Component} from 'react'; import {Image, StyleSheet, Text, View, TouchableOpacity} from 'react-native'; import Ionicons from 'react-native-vector-icons/Ionicons'; +import UserIcon from '../userIcon'; import Touchable from '../touchable'; import Color from '../../style/color'; -function unique(array) { - let n = []; - for(let i=0; i it.content.author.name)).join('、'); - const body = `${users} 回复了你`; + const max = 5; + const formatMsg = {}; + + let key = null; + for (let i=0; i this.props.onCommentPress(msg)}> - {body} + { + Object.keys(formatMsg).map((it, index) => { + if (index >= max) { + return null; + } + + return ( + this.props.onUserIconPress(formatMsg[it])} + /> + ); + }) + } + + {Object.keys(formatMsg).length > max ? '等' : ''}回复了你 + {this.renderDeleteButton(msg)} @@ -63,13 +81,17 @@ export default class Notification extends Component { } renderFollow(msg) { - const body = `${msg.content.user.name} 关注了你`; + const userIcon = msg.link_user_icon; return ( this.props.onFollowPress(msg)}> - - {body} + + + 关注了你 {this.renderDeleteButton(msg)} @@ -77,7 +99,11 @@ export default class Notification extends Component { } renderLike(msg) { - const body = `${msg.content.user.name} 给了你一个OK绷`; + const userData = { + userId: msg.content.user.id, + userIcon: msg.link_user_icon, + userName: msg.content.user.name, + } return ( this.props.onLikePress(msg)}> @@ -89,7 +115,12 @@ export default class Notification extends Component { } style={localStyle.icon2} /> - {body} + this.props.onUserIconPress(userData)} + /> + 给了你一个OK绷 {this.renderDeleteButton(msg)} @@ -109,17 +140,18 @@ const localStyle = StyleSheet.create({ icon: { marginRight: 10, marginTop: 1, - lineHeight: 20 + lineHeight: 28 }, text: { flex: 1, - lineHeight: 20 + lineHeight: 28 }, icon2: { width: 15, height: 15, - marginRight: 10, - marginTop: 4, + marginLeft: -1, + marginRight: 9, + marginTop: 7, }, delete: { lineHeight: 20, diff --git a/src/component/notification/notificationList.js b/src/component/notification/notificationList.js index 601e4ce..74cb574 100644 --- a/src/component/notification/notificationList.js +++ b/src/component/notification/notificationList.js @@ -34,6 +34,7 @@ export default class NotificationList extends Component { (async () => { try { let notifications = await this.getMessages(); + this.notificationsData = notifications; this.setNotifications(notifications); this.setState({error: false}); @@ -106,6 +107,29 @@ export default class NotificationList extends Component { } } + _onUserIconPress(msg) { + Navigation.push(this.props.componentId, { + component: { + name: 'User', + options: { + bottomTabs: { + visible: false, + + // hide bottom tab for android + drawBehind: true, + animate: true + } + }, + passProps: { + user: { + id: msg.userId, + name: msg.userName, + } + } + } + }); + } + _onCommentPress(msg) { Navigation.push(this.props.componentId, { component: { @@ -159,7 +183,7 @@ export default class NotificationList extends Component { _onLikePress(msg) { Navigation.push(this.props.componentId, { component: { - name: 'User', + name: 'DiaryDetail', options: { bottomTabs: { visible: false, @@ -170,7 +194,7 @@ export default class NotificationList extends Component { } }, passProps: { - user: msg.content.user + diaryId: msg.content.dairy_id } } }); @@ -199,11 +223,12 @@ export default class NotificationList extends Component { renderItem={({item}) => { return ( ); }} @@ -230,16 +255,7 @@ export default class NotificationList extends Component { } } -// NotificationList.propTypes = { -// isHistory: PropTypes.boolean, -// onRefresh: PropTypes.func, -// isSetRead: PropTypes.boolean -// }; -// -// NotificationList.defaultProps = { -// isHistory: true, -// isSetRead: false, -// }; + diff --git a/src/component/userIcon.js b/src/component/userIcon.js index feb6a69..7753a9a 100644 --- a/src/component/userIcon.js +++ b/src/component/userIcon.js @@ -24,8 +24,7 @@ export default class UserIcon extends Component { render() { return ( - r1 !== r2 - // }); - // this.state = ({ - // messages: [], - // messagesDataSource: ds, - // refreshing: true, - // }); } navigationButtonPressed({buttonId}) { diff --git a/src/page/UserPage.js b/src/page/UserPage.js index 8d74bf4..2456fc2 100644 --- a/src/page/UserPage.js +++ b/src/page/UserPage.js @@ -132,21 +132,34 @@ export default class UserPage extends Component { componentDidMount() { if(this.userId) { - Api.getRelation(this.userId) - .then(re => { - this.followed = re; - if(this.followed) { + Api.getSelfInfoByStore() + .then(user => { + if(user && user.id == this.userId) { Navigation.mergeOptions(this.props.componentId, { topBar: { rightButtons: [{ - id: 'navButtonFollowSelected', - icon: Icon.navButtonFollowSelected + id: 'setting', + icon: Icon.navButtonSetting }] } }); + } else { + Api.getRelation(this.userId) + .then(re => { + this.followed = re; + if(this.followed) { + Navigation.mergeOptions(this.props.componentId, { + topBar: { + rightButtons: [{ + id: 'navButtonFollowSelected', + icon: Icon.navButtonFollowSelected + }] + } + }); + } + }); } }); - } this.notebookListener = DeviceEventEmitter.addListener(Event.updateNotebooks, (param) => { diff --git a/src/page/WritePage.js b/src/page/WritePage.js index 3c6f2af..305023e 100644 --- a/src/page/WritePage.js +++ b/src/page/WritePage.js @@ -24,7 +24,8 @@ import {Icon} from '../style/icon'; import Color from '../style/color'; import Api from '../util/api'; 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 ImageAction from '../component/image/imageAction' @@ -54,6 +55,8 @@ export default class WritePage extends Component { fadeAnimOpacity: new Animated.Value(0), fadeAnimHeight: new Animated.Value(0) } + + this.draftTimer = null; } static options(passProps) { @@ -102,6 +105,9 @@ export default class WritePage extends Component { } closePage() { + clearInterval(this.draftTimer); + Token.setDraft(''); + this.contentInput.blur(); if (this.diary || this.topic) { Navigation.pop(this.props.componentId); @@ -112,10 +118,20 @@ export default class WritePage extends Component { } componentDidMount() { + Token.getDraft().then(draft => { + if(draft) { + this.setState({ + content: draft, + }); + } + }); + + this.resetDraftTimer(); + this.loadNotebook().then(notebookCount => { if(notebookCount > 0) { InteractionManager.runAfterInteractions(() => { - this && this.contentInput && this.contentInput.focus(); + this.contentInput && this.contentInput.focus(); }); } else { Alert.alert('提示', '没有可用日记本,无法写日记',[ @@ -140,6 +156,19 @@ export default class WritePage extends Component { 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() { this.contentInput.blur(); this.setState({modalVisible: true}); diff --git a/src/util/token.js b/src/util/token.js index 36fe08c..d0d1bb5 100644 --- a/src/util/token.js +++ b/src/util/token.js @@ -2,7 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage'; var base64 = require('base-64'); -class TokenManager { +class Token { generateToken(username, password) { return 'Basic ' + base64.encode(username + ":" + password); @@ -101,4 +101,4 @@ class TokenManager { } -export default new TokenManager() +export default new Token()