diff --git a/src/component/comment/comment.js b/src/component/comment/comment.js
index b037835..e1711b5 100644
--- a/src/component/comment/comment.js
+++ b/src/component/comment/comment.js
@@ -10,10 +10,25 @@ import UserIcon from '../userIcon';
export default class Comment extends Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ comment: props.comment,
+
+ isMyDiary: props.isMyDiary || false,
+ isMyComment: props.isMyComment || false,
+ expired: props.expired || false
+ };
+ }
+
render() {
- let comment = this.props.comment;
+ let comment = this.state.comment;
let user = comment.user;
- let editable = this.props.editable;
+
+ let isMyDiary = this.state.isMyDiary;
+ let isMyComment = this.state.isMyComment;
+ let expired = this.state.expired;
return (
@@ -39,7 +54,7 @@ export default class Comment extends Component {
{
- editable
+ (isMyDiary || isMyComment) && !expired
?
diff --git a/src/component/comment/commentList.js b/src/component/comment/commentList.js
index 800061a..7545702 100644
--- a/src/component/comment/commentList.js
+++ b/src/component/comment/commentList.js
@@ -17,7 +17,7 @@ import Touchable from '../touchable';
import Color from '../../style/color';
import Api from '../../util/api';
import Event from '../../util/event';
-import Msg from '../../util/msg'
+import Msg from '../../util/msg';
import Comment from './comment';
@@ -27,14 +27,27 @@ export default class CommentList extends Component {
constructor(props) {
super(props);
- this.diaryId = props.diaryId;
- this.editable = props.editable || false;
-
this.state = {
+ diaryId: props.diaryId,
+ selfInfo: props.selfInfo,
+
+ isMine: props.isMine || false,
+ expired: props.expired || false,
+
comments: []
};
}
+ componentWillReceiveProps(nextProps) {
+ this.setState({
+ diaryId: nextProps.diaryId,
+ selfInfo: nextProps.selfInfo,
+
+ isMine: nextProps.isMine || false,
+ expired: nextProps.expired || false
+ });
+ }
+
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
this.refresh();
@@ -42,7 +55,7 @@ export default class CommentList extends Component {
}
async refresh() {
- let comments = await Api.getDiaryComments(this.diaryId);
+ let comments = await Api.getDiaryComments(this.state.diaryId);
if(comments && comments.length > 0) {
if (comments.length > 1) {
comments = comments.reverse();
@@ -59,6 +72,10 @@ export default class CommentList extends Component {
}
_onUserIconPress(comment) {
+ if(this.state.selfInfo.id == comment.user_id) {
+ return;
+ }
+
Navigation.push(this.props.componentId, {
component: {
name: 'User',
@@ -114,6 +131,8 @@ export default class CommentList extends Component {
}
render() {
+ let selfInfo = this.state.selfInfo;
+
return (
this.list = r}
@@ -127,7 +146,11 @@ export default class CommentList extends Component {
renderItem={({item}) => {
return (
this._onCommentPress(item)}>
- this._onUserIconPress(item)}
onCommentAction={() => this._onCommentAction(item)}>
diff --git a/src/component/diary/diaryBrief.js b/src/component/diary/diaryBrief.js
index ed42f0c..8d78cf1 100644
--- a/src/component/diary/diaryBrief.js
+++ b/src/component/diary/diaryBrief.js
@@ -19,11 +19,11 @@ export default class DiaryBrief extends Component {
super(props);
this.state = {
- diary: props.diary
- }
+ diary: props.diary,
- this.expired = props.expired || false;
- this.editable = props.editable || false;
+ isMine: props.isMine || false,
+ expired: props.expired || false
+ }
this.showField = ['userIcon', 'userName', 'subject', 'createdTime'];
if(props.showField && props.showField.length > 0) {
@@ -51,6 +51,9 @@ export default class DiaryBrief extends Component {
return null;
}
+ let isMine = this.state.isMine;
+ let expired = this.state.expired;
+
let user = diary.user;
return (
@@ -91,13 +94,13 @@ export default class DiaryBrief extends Component {
{
- this.editable
+ isMine && !expired
?
0) {
+ this.showField = props.showField
+ }
}
- refreshDiaryContent(diary) {
- if(diary) {
- this.setState({diary})
- }
+ show(field) {
+ return this.showField.indexOf(field) >= 0;
+ }
+
+ componentWillReceiveProps(nextProps) {
+ this.setState({
+ diary: nextProps.diary,
+ selfInfo: nextProps.selfInfo,
+
+ isMine: nextProps.isMine || false,
+ expired: nextProps.expired || false
+ });
}
async refreshComment() {
@@ -76,12 +91,12 @@ export default class DiaryFull extends Component {
return (
- {user && user.iconUrl
+ {user && user.iconUrl && this.show('userIcon')
? : null}
- {user && user.name
+ {user && user.name && this.show('userName')
? (
{user.name}
@@ -112,10 +127,10 @@ export default class DiaryFull extends Component {
this.commentList = r}
- diaryId={diary.id}
- editable={this.state.editable}
- onUserIconPress={this._onUserIconPress.bind(this)}
{...this.props}
+ diaryId={diary.id}
+ isMine={this.state.isMine}
+ expired={this.state.expired}
>
diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js
index e6a246a..e1620ff 100644
--- a/src/component/diary/diaryList.js
+++ b/src/component/diary/diaryList.js
@@ -30,7 +30,7 @@ export default class DiaryList extends Component {
constructor(props) {
super(props);
- this.editable = props.editable || false;
+ this.isMine = props.isMine || false;
this.dataSource = props.dataSource;
this.state = {
@@ -95,7 +95,7 @@ export default class DiaryList extends Component {
diary: diary,
user: diary.user,
- editable: this.editable,
+ showField: this.props.showField,
refreshBack: this.refreshOne.bind(this, index)
}
}
@@ -199,7 +199,7 @@ export default class DiaryList extends Component {
render() {
if(!this.state.mounting && (!this.state.diaries || this.state.diaries.length == 0)) {
- let message = this.editable
+ let message = this.isMine
? '今天还没有写日记,马上写一篇吧'
: '今天还没有人写日记';
return (
@@ -227,7 +227,6 @@ export default class DiaryList extends Component {
this._onUserIconPress(item)}
diff --git a/src/component/notebook/notebookDiaryList.js b/src/component/notebook/notebookDiaryList.js
index dccf81d..8e2b564 100644
--- a/src/component/notebook/notebookDiaryList.js
+++ b/src/component/notebook/notebookDiaryList.js
@@ -9,7 +9,7 @@ import {
ActivityIndicator
} from 'react-native';
import {Navigation} from 'react-native-navigation';
-import moment from 'moment'
+import moment from 'moment';
import Api from '../../util/api';
import Color from '../../style/color';
@@ -30,7 +30,7 @@ export default class NotebookDiaryList extends Component {
super(props);
this.notebook = props.notebook;
- this.editable = props.editable || false;
+ this.isMine = props.isMine || false;
this.dataSource = new NotebookDiaryData();
this.state = {
@@ -186,9 +186,9 @@ export default class NotebookDiaryList extends Component {
},
passProps: {
diary: diary,
- editable: this.editable,
- expired: this.notebook.isExpired,
+ showField: ['createdTime'],
+ expired: this.notebook.isExpired,
refreshBack: this.refreshOne.bind(this, index)
}
}
@@ -201,6 +201,7 @@ export default class NotebookDiaryList extends Component {
}
let expired = this.notebook.isExpired;
+ let isMine = this.isMine;
return (
@@ -218,6 +219,7 @@ export default class NotebookDiaryList extends Component {
diary={rowData.item}
showField={['createdTime']}
expired={expired}
+ isMine={isMine}
onDiaryPress={this._onDiaryPress.bind(this, rowData.index)}
diff --git a/src/component/notebook/notebookList.js b/src/component/notebook/notebookList.js
index 014cab6..49d5c10 100644
--- a/src/component/notebook/notebookList.js
+++ b/src/component/notebook/notebookList.js
@@ -86,7 +86,7 @@ export default class NotebookList extends Component {
},
passProps: {
notebook: notebook,
- editable: !this.state.user
+ isMine: !this.state.user
}
}
});
diff --git a/src/component/notification/notification.js b/src/component/notification/notification.js
index 015ec28..acf8fe4 100644
--- a/src/component/notification/notification.js
+++ b/src/component/notification/notification.js
@@ -3,7 +3,7 @@ import {StyleSheet, Text, View} from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import Touchable from '../touchable';
-import Color from '../../style/color'
+import Color from '../../style/color';
function unique(array) {
diff --git a/src/component/notification/notificationList.js b/src/component/notification/notificationList.js
index 5e3cfd1..e61cbf8 100644
--- a/src/component/notification/notificationList.js
+++ b/src/component/notification/notificationList.js
@@ -50,8 +50,6 @@ export default class NotificationList extends Component {
return ret;
}, []);
-
- console.log('notifications:', reducedNoti);
this.setState({
notifications: reducedNoti
@@ -77,8 +75,7 @@ export default class NotificationList extends Component {
}
},
passProps: {
- diaryId: msg.link_id,
- editable: true
+ diaryId: msg.link_id
}
}
});
diff --git a/src/page/DiaryDetailPage.js b/src/page/DiaryDetailPage.js
index 572d50d..08d5b6b 100644
--- a/src/page/DiaryDetailPage.js
+++ b/src/page/DiaryDetailPage.js
@@ -10,11 +10,12 @@ import {
} from 'react-native';
import {Navigation} from 'react-native-navigation';
import KeyboardSpacer from "react-native-keyboard-spacer";
+import {Button} from 'react-native-elements';
import Color from '../style/color';
import {Icon} from '../style/icon';
import Msg from '../util/msg';
-import Api from '../util/api'
+import Api from '../util/api';
import Event from '../util/event';
import DiaryFull from '../component/diary/diaryFull';
@@ -22,6 +23,16 @@ import DiaryAction from '../component/diary/diaryAction';
import CommentInput from '../component/comment/commentInput';
+function getTodayStr() {
+ let now = new Date();
+
+ let year = now.getFullYear();
+ let month = now.getMonth() + 1;
+ let date = now.getDate();
+
+ return year + '-' + (month > 9 ? month : '0' + month) + '-' + date;
+}
+
export default class DiaryDetailPage extends Component {
constructor(props) {
@@ -35,9 +46,13 @@ export default class DiaryDetailPage extends Component {
diary: props.diary,
user: props.user,
- editable: props.editable || false,
+ isMine: false,
+ todayCreated: false,
expired: props.expired || false,
- needScrollToBottom: false
+
+ needScrollToBottom: false,
+
+ error: null
}
}
@@ -48,22 +63,17 @@ export default class DiaryDetailPage extends Component {
}
}
- if(!passProps.expired) {
- topBar.rightButtons = [{
- id: 'navButtonMore',
- icon: Icon.navButtonMore,
-
- color: Color.primary // android
- }]
- }
-
return {
topBar
};
}
navigationButtonPressed({buttonId}) {
- if(this.state.editable || this.state.diary.user_id == this.state.selfInfo.id) {
+ if(!this.state.selfInfo || !this.state.diary) {
+ return;
+ }
+
+ if(this.state.isMine) {
let componentId = this.props.componentId;
DiaryAction.action(componentId, this.state.diary, {
onDelete: () => {
@@ -87,14 +97,13 @@ export default class DiaryDetailPage extends Component {
}
componentDidMount() {
- if(!this.state.diary && this.state.diaryId) {
- this.refreshDiary();
- }
-
Api.getSelfInfoByStore()
.then(user => {
this.setState({
selfInfo: user
+
+ }, () =>{
+ this.refreshDiary(this.state.diary);
});
}).done();
@@ -117,34 +126,67 @@ export default class DiaryDetailPage extends Component {
this.commentListener.remove();
}
- refreshDiary() {
- let diaryId = this.state.diaryId;
- if(!diaryId) {
- diaryId = this.state.diary.id;
+ async refreshDiary(diary) {
+ if(!diary) {
+ let diaryId = this.state.diaryId;
+ if(!diaryId) {
+ diaryId = this.state.diary.id;
+ }
+
+ try {
+ diary = await Api.getDiary(diaryId);
+ } catch(e) {
+ this.setState({
+ error: e
+ });
+
+ return;
+ }
}
- Api.getDiary(diaryId)
- .then(result => {
- if(!result) {
- throw {
- message: 'get diary no result'
- }
- }
+ let isMine = this.state.selfInfo.id == diary.user_id;
- this.props.refreshBack(result);
- this.diaryFull.refreshDiaryContent(result);
- })
- .done();
+ let createdTime = diary.created;
+ let todayCreated = getTodayStr() == createdTime.substring(0, createdTime.indexOf(' '));
+
+ this.setState({
+ diary,
+ isMine,
+ todayCreated
+
+ }, () => {
+ if(this.props.refreshBack) {
+ this.props.refreshBack(diary);
+ }
+
+ if(todayCreated || (this.props.expired && !isMine)) {
+ Navigation.mergeOptions(this.props.componentId, {
+ topBar: {
+ rightButtons: [{
+ id: 'navButtonMore',
+ icon: Icon.navButtonMore,
+
+ color: Color.primary // android
+ }]
+ }
+ });
+ }
+ });
}
render() {
- if(!this.state.selfInfo || !this.state.diary) {
- return null;
- }
+ if(this.state.error) {
+ return (
+
+ {'日记加载失败:('}
+
+ );
- let isMine = false;
- if(this.state.selfInfo.id == this.state.diary.user_id) {
- isMine = true;
+ } else if(!this.state.selfInfo || !this.state.diary) {
+ return null;
}
return (
@@ -162,14 +204,15 @@ export default class DiaryDetailPage extends Component {
this.diaryFull = r}
{...this.props}
diary={this.state.diary}
- editable={this.state.editable || isMine}
- expired={this.state.expired}
+ selfInfo={this.state.selfInfo}
+ isMine={this.state.isMine}
+ expired={this.state.expired || !this.state.todayCreated}
>
{
- !this.state.expired ? (
+ this.state.todayCreated ? (
this.commentInput = r}
diary={this.state.diary}
selfInfo={this.state.selfInfo}
@@ -189,5 +232,14 @@ const localStyle = StyleSheet.create({
wrap: {
flex: 1,
flexDirection: 'column'
+ },
+ container: {
+ alignItems:'center',
+ justifyContent: 'center',
+ height: '100%'
+ },
+ text: {
+ paddingBottom: 15,
+ color: Color.text
}
});
diff --git a/src/page/NotebookDetailPage.js b/src/page/NotebookDetailPage.js
index cbf801c..ff3121c 100644
--- a/src/page/NotebookDetailPage.js
+++ b/src/page/NotebookDetailPage.js
@@ -22,7 +22,7 @@ export default class NotebookDetailPage extends Component {
}
}
- if(passProps.editable) {
+ if(passProps.isMine) {
topBar.rightButtons = [{
id: 'navButtonNotebookSetting',
icon: Icon.navButtonNotebookSetting,
diff --git a/src/page/UserPage.js b/src/page/UserPage.js
index 582d8e4..303e823 100644
--- a/src/page/UserPage.js
+++ b/src/page/UserPage.js
@@ -192,15 +192,17 @@ export default class UserPage extends Component {
/>,
diary: () => this.diaryList = r}
+ {...this.props}
+
dataSource={this.dataSource}
showField={['subject', 'createdTime']}
- editable={!this.user}
- {...this.props}
+ isMine={!this.user}
/>,
notebook: () => this.notebookList = r}
- user={this.user}
{...this.props}
+
+ user={this.user}
/>
});