From 239c7bc790ba3889b653d9677d25a3eedc39c802 Mon Sep 17 00:00:00 2001 From: xuwenyang Date: Mon, 17 Jun 2019 23:12:35 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=A6=96=E9=A1=B5=EF=BC=8C=E5=85=B3?= =?UTF-8?q?=E6=B3=A8=EF=BC=8C=E6=88=91=E7=9A=84=E6=97=A5=E8=AE=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0ok=E7=BB=B7=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E7=82=B9/=E5=8F=AF=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{ => about}/Icon.png | Bin src/{ => about}/updateInfo.js | 0 src/component/diary/diaryBrief.js | 38 +++----- src/component/diary/diaryIconComment.js | 42 +++++++++ src/component/diary/diaryIconOkB.js | 97 ++++++++++++++++++++ src/component/diary/diaryList.js | 2 +- src/component/notebook/notebookDiaryList.js | 14 ++- src/img/ok-beng1.png | Bin 0 -> 618 bytes src/img/ok-beng2.png | Bin 0 -> 1453 bytes src/page/AboutPage.js | 4 +- src/page/FollowPage.js | 11 ++- src/util/api.js | 69 ++++++++------ 12 files changed, 212 insertions(+), 65 deletions(-) rename src/{ => about}/Icon.png (100%) rename src/{ => about}/updateInfo.js (100%) create mode 100644 src/component/diary/diaryIconComment.js create mode 100644 src/component/diary/diaryIconOkB.js create mode 100644 src/img/ok-beng1.png create mode 100644 src/img/ok-beng2.png diff --git a/src/Icon.png b/src/about/Icon.png similarity index 100% rename from src/Icon.png rename to src/about/Icon.png diff --git a/src/updateInfo.js b/src/about/updateInfo.js similarity index 100% rename from src/updateInfo.js rename to src/about/updateInfo.js diff --git a/src/component/diary/diaryBrief.js b/src/component/diary/diaryBrief.js index 4702d86..baad127 100644 --- a/src/component/diary/diaryBrief.js +++ b/src/component/diary/diaryBrief.js @@ -7,6 +7,8 @@ import Color from '../../style/color'; import UserIcon from '../userIcon'; import Photo from '../photo'; +import DiaryIconComment from './diaryIconComment'; +import DiaryIconOkB from './diaryIconOkB'; import DiaryAction from './diaryAction'; @@ -16,9 +18,10 @@ export default class DiaryBrief extends Component { super(props); this.diary = props.diary; + this.diary.isExpired = props.isExpired || false; this.editable = props.editable || false; - this.showField = ['icon', 'userName', 'subject', 'createdTime']; + this.showField = ['userIcon', 'userName', 'subject', 'createdTime']; if(props.showField && props.showField.length > 0) { this.showField = props.showField } @@ -42,7 +45,7 @@ export default class DiaryBrief extends Component { return ( - {(user && user.iconUrl && this.show('icon')) + {(user && user.iconUrl && this.show('userIcon')) ? : null} @@ -72,16 +75,13 @@ export default class DiaryBrief extends Component { - { - diary.comment_count > 0 - ? - - {diary.comment_count} - - : null - } + + + + { this.editable @@ -143,19 +143,11 @@ const localStyle = StyleSheet.create({ marginTop: 10, justifyContent: 'space-between' }, + icons: { + flexDirection: 'row' + }, moreIcon: { paddingVertical: 5, paddingHorizontal: 5 - }, - commentIconBox: { - flexDirection: "row" - }, - buttonIcon: { - marginRight: 8, - marginLeft: 2 - }, - commentIconIext: { - fontSize: 15, - color: Color.inactiveText } }); diff --git a/src/component/diary/diaryIconComment.js b/src/component/diary/diaryIconComment.js new file mode 100644 index 0000000..e6e02ef --- /dev/null +++ b/src/component/diary/diaryIconComment.js @@ -0,0 +1,42 @@ +import React, {Component} from 'react'; +import {StyleSheet, Text, View, Image, TouchableOpacity} from 'react-native'; +import Ionicons from 'react-native-vector-icons/Ionicons'; + +import Color from '../../style/color'; + + +export default class DiaryIconComment extends Component { + + constructor(props) { + super(props); + + this.state = { + count: props.count || 0 + } + } + + render() { + return this.state.count > 0 ? ( + + + {this.state.count} + + ) : null; + } +} + +const localStyle = StyleSheet.create({ + wrap: { + flexDirection: 'row', + marginRight: 6 + }, + icon: { + marginLeft: 2, + marginRight: 4 + }, + text: { + fontSize: 15, + color: Color.inactiveText + } +}); diff --git a/src/component/diary/diaryIconOkB.js b/src/component/diary/diaryIconOkB.js new file mode 100644 index 0000000..8b3a6c1 --- /dev/null +++ b/src/component/diary/diaryIconOkB.js @@ -0,0 +1,97 @@ +import React, {Component} from 'react'; +import {StyleSheet, Text, View, Image, TouchableOpacity} from 'react-native'; + +import Color from '../../style/color'; +import Api from '../../util/api'; +import Msg from '../../util/msg'; + + +export default class DiaryIconOkB extends Component { + + constructor(props) { + super(props); + + this.state = { + diaryId: props.diaryId || null, + count: props.count || 0, + active: props.active || false, + clickable: props.clickable && true + } + } + + onPress() { + if(!this.state.clickable) { + return; + } + + let count = this.state.count; + let isActive = this.state.active; + + if(!isActive) { + Api.likeDiary(this.state.diaryId) + .then(re => { + this.setState({ + count: count + 1, + active: true + }) + }) + .catch(e => { + Msg.showMsg('操作失败'); + }) + .done(); + + } else { + Api.cancelLikeDiary(this.state.diaryId) + .then(re => { + this.setState({ + count: count - 1, + active: false + }) + }) + .catch(e => { + Msg.showMsg('操作失败'); + }) + .done(); + } + } + + render() { + return ( + + + + + {this.state.count} + + + ); + } +} + +const localStyle = StyleSheet.create({ + wrap: { + flexDirection: 'row', + marginRight: 6 + }, + icon: { + width: 18, + height: 18, + marginLeft: 2, + marginRight: 4 + }, + text: { + fontSize: 15 + } +}); diff --git a/src/component/diary/diaryList.js b/src/component/diary/diaryList.js index 208ff70..6a5710b 100644 --- a/src/component/diary/diaryList.js +++ b/src/component/diary/diaryList.js @@ -200,7 +200,7 @@ export default class DiaryList extends Component { data={this.state.diaries} keyExtractor={(item, index) => { - return item.id + item.updated + item.comment_count; + return item.id + item.updated + item.comment_count + item.like_count; }} renderItem={({item}) => { diff --git a/src/component/notebook/notebookDiaryList.js b/src/component/notebook/notebookDiaryList.js index 88746cd..4e86401 100644 --- a/src/component/notebook/notebookDiaryList.js +++ b/src/component/notebook/notebookDiaryList.js @@ -81,7 +81,6 @@ export default class NotebookDiaryList extends Component { }); } - console.log('format result:', result); return result; } @@ -177,7 +176,13 @@ export default class NotebookDiaryList extends Component { } render() { - return this.notebook ? ( + if(!this.notebook) { + return null; + } + + let isExpired = this.notebook.isExpired; + + return ( { return ( this._onDiaryPress(rowData.item)}> - + } ); }} @@ -225,7 +231,7 @@ export default class NotebookDiaryList extends Component { /> - ) : null; + ); } } diff --git a/src/img/ok-beng1.png b/src/img/ok-beng1.png new file mode 100644 index 0000000000000000000000000000000000000000..9c72d35920cfed5fc988fd58c64f0457f168653e GIT binary patch literal 618 zcmV-w0+s!VP)8e&i*Lut{GpzTm5D%4mZyFxtd z{`*3(cBRw4>YJQbcjo@)%8LxhrDJ>R0bGEeBYFOL4F{KRWuUWgrazs9G)YU|o-;TB^GOpiTBrSuJX5E=xG36FYwk-sPJ*E;JlJ(# zkgb-Rg8|o}l{GQ&)#RMZ!SrA zf1ed+eQy;hv4Y}gU=@_Py_NJsr*wqf%^Qdr9fMX&_=Tx!UlQli+=CVI5dhE>%D{-H z=aM)=Pk8ARetO)nnZOc2gZ~a-7AdOjf~cV9j0A{?>sh*c6OHLWxQOS{3{YJ(&5J{5 zDgG=FtlCDw!k^U96#6oi08NaIwIW|LFwbzs6LVuG#h0jvnegP^fZpK(_~8lHKl81V zLq-kx2FRYzujm%Ip~CWMnIx|I%0yb{xXeR5;&%*t8WxI6k~z=t_3<@IaFOfL*L?dRDvm~iRX&p<4 zt1!mZjz}~ZBvX#YQN}UMj4|`s-+rIh@BRA+zF+!bn*%D!OO+KA6jUq@Qjd_|;Qyzj zNUG=`Ku&L~Krk={=YxVQUi1lH_Jd*pZB#$=Lk>dmhO4reNDx4@E8Y)R9K|K zDn)3W1{)$Bw!~8$d4{7z2JA9mpMhh4;{=fj$4s1jHsO>7=WMv-;B=^sE&iv)s=J8ax#<6bS2Y9^E3aTeB4eV~z5a0r*-__t=@%xruFNx@y|rdLrgj z&a_?oINnksGv&@u}#P)vX1rE%P#pkGNKDd(m4) zVfGz7tIb}&diQ*)cbV9^cv?qpqU0ObVr<+RrY`7pj5*_YxA%l5N8Q};*E;jm?#NAN zJcCsVuFXBQ#yBmMC7}4X`=?$RqQQgX;Ze0N#iT6mxLJC(dzmt0*lURY=OLp&?6hYoS$oehJy+_j zDvpeAjn{PB6=Y;@xBvHLs@8tTOy+BJvC+Dq?9hdRk!SUjN z=lmg2iJn*A@%Oi*1}kF9xpemq?GBkl8qu=cgU4ro7TJ$9upHSbubX({9hM>wV>hWt zkf0UivLisPhTTa^rv}{rnCP>@4 zw12;RFz-s;+p0CQS$}+FH`KFpxVF>^ao{z7=kq-bQF=@DZoSzG-3mcz`J)b#WET}I M%x$Q-dtJl+0|hsN9smFU literal 0 HcmV?d00001 diff --git a/src/page/AboutPage.js b/src/page/AboutPage.js index d80bbfa..c8a628f 100644 --- a/src/page/AboutPage.js +++ b/src/page/AboutPage.js @@ -11,7 +11,7 @@ import Api from '../util/api'; import Token from '../util/token'; import Event from '../util/event'; import Color from '../style/color'; -import UpdateInfo from '../updateInfo'; +import UpdateInfo from '../about/updateInfo'; export default class AboutPage extends Component { @@ -48,7 +48,7 @@ export default class AboutPage extends Component { return ( - 版本: {Api.VERSION}{label} {this.state.news.date} 更新日志 diff --git a/src/page/FollowPage.js b/src/page/FollowPage.js index e3ec75b..3827505 100644 --- a/src/page/FollowPage.js +++ b/src/page/FollowPage.js @@ -2,10 +2,11 @@ import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; import {Navigation} from 'react-native-navigation'; -import Api from '../util/api' -import {Icon} from '../style/icon' +import Api from '../util/api'; +import {Icon} from '../style/icon'; +import Color from '../style/color'; -import DiaryList from '../component/diary/diaryList' +import DiaryList from '../component/diary/diaryList'; import FollowDiaryData from '../dataLoader/followDiaryData'; @@ -28,7 +29,7 @@ export default class FollowPage extends Component { id: 'followIcon', icon: Icon.followIcon, - color: '#aaa' // android + color: Color.primary // android }] } }; @@ -68,7 +69,7 @@ const localStyle = StyleSheet.create({ wrap: { flex: 1, backgroundColor: '#fff', - paddingTop: 20 + paddingTop: 1 }, header: { paddingLeft: 20, diff --git a/src/util/api.js b/src/util/api.js index 2ed12f9..2103045 100644 --- a/src/util/api.js +++ b/src/util/api.js @@ -260,6 +260,41 @@ async function deleteDiary(id) { return call('DELETE', '/diaries/' + id); } +async function addDiary(bookId, content, photoUri = null, join_topic = null) { + if(!photoUri) { + return call('POST', '/notebooks/' + bookId + '/diaries', { + content, + join_topic + }); + + } else { + return upload('POST', '/notebooks/' + bookId + '/diaries', { + content, + join_topic, + photo: { + uri: photoUri, + name: 'image.jpg', + type: 'image/jpg' + } + }); + } +} + +async function updateDiary(id, bookId, content) { + return call('PUT', '/diaries/' + id, { + content, + notebook_id: bookId + }); +} + +async function likeDiary(id) { + return callV2('PUT', '/like/diaries/' + id); +} + +async function cancelLikeDiary(id) { + return callV2('DELETE', '/like/diaries/' + id); +} + async function updateNotebookCover(bookId, photoUri) { return upload('POST', `/notebooks/${bookId}/cover`, { @@ -292,33 +327,6 @@ async function deleteNotebook(id) { return call('DELETE', '/notebooks/' + id) } -async function addDiary(bookId, content, photoUri = null, join_topic = null) { - if(!photoUri) { - return call('POST', '/notebooks/' + bookId + '/diaries', { - content, - join_topic - }); - - } else { - return upload('POST', '/notebooks/' + bookId + '/diaries', { - content, - join_topic, - photo: { - uri: photoUri, - name: 'image.jpg', - type: 'image/jpg' - } - }); - } -} - -async function updateDiary(id, bookId, content) { - return call('PUT', '/diaries/' + id, { - content, - notebook_id: bookId - }); -} - async function report(user_id, diary_id) { return call('POST', '/reports/', { @@ -494,6 +502,10 @@ export default { getDiary, deleteDiary, + addDiary, + updateDiary, + likeDiary, + cancelLikeDiary, getDiaryComments, deleteComment, @@ -516,9 +528,6 @@ export default { updateNotebook, deleteNotebook, - addDiary, - updateDiary, - report, feedback } \ No newline at end of file