Skip to content

Commit eaff1ff

Browse files
lightlight
authored andcommitted
fix: 修复了首页刷新、日记图片、个人数据显示等BUG
1 parent 0172902 commit eaff1ff

File tree

12 files changed

+191
-43
lines changed

12 files changed

+191
-43
lines changed

.DS_Store

0 Bytes
Binary file not shown.

ios/twolife.xcodeproj/project.pbxproj

Lines changed: 91 additions & 6 deletions
Large diffs are not rendered by default.

res/images/profile/.DS_Store

0 Bytes
Binary file not shown.

src/common/util.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,13 @@ export async function updateFile(obj) {
499499

500500
// 不用同步直接删除日记
501501
if (obj.action === 'delete') {
502-
diaryList = diaryList.filter(diary => diary.uuid !== obj.data.uuid)
502+
if (obj.data instanceof Array) {
503+
for (let i = 0; i < obj.data.length; i++) {
504+
diaryList = diaryList.filter(diary => diary.uuid !== obj.data[i].uuid)
505+
}
506+
} else {
507+
diaryList = diaryList.filter(diary => diary.uuid !== obj.data.uuid)
508+
}
503509
}
504510

505511
// 删除匹配对象到日记
@@ -514,7 +520,8 @@ export async function updateFile(obj) {
514520
}
515521

516522
await fs.writeFile(FILE_PATH, JSON.stringify(newContent), 'utf8')
517-
523+
console.log(obj.action)
524+
console.log(obj.data)
518525
DeviceEventEmitter.emit('flush_local_note')
519526
}
520527

src/containers/Index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default class Index extends Component {
5454
})
5555
// 刷新通知、刷新日记、刷新用户
5656
DeviceEventEmitter.emit('flush_notification', {})
57-
5857
const res = await HttpUtils.get(USERS.user, { user_id: this.props.user.id })
5958
if (res.code === 0) {
6059
store.dispatch(fetchProfileSuccess(res.data))

src/containers/home/DiaryBanner.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ export default class DiaryBanner extends Component {
124124
width={WIDTH}
125125
height={getResponsiveWidth(282)}
126126
style={styles.swiper}
127-
loop={false}
127+
autoplay
128+
loop={false} //true有BUG
128129
dot={<View style={styles.swiper_dot}></View>}
129130
activeDot={<View style={[styles.swiper_dot, styles.swiper_active_dot]}></View>}
130131
bounces={true}
131132
onIndexChanged={this._onImgChanged.bind(this)}
133+
onTouchStart={this.props.onTouchStart}
134+
onTouchEnd={this.props.onTouchEnd}
132135
>
133136
{this.state.imgListComponent}
134137
</Swiper>

src/containers/home/DiaryDetail.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ export default class DiaryDetail extends Component {
216216

217217
setKeyboard() {
218218
Keyboard.addListener('keyboardWillShow', event => {
219-
this.setState({showKeyboard: true})
219+
this.setState({ showKeyboard: true })
220220
this.toggleInputComment(true, event)
221221
})
222222
Keyboard.addListener('keyboardWillHide', event => {
223-
this.setState({showKeyboard: false})
223+
this.setState({ showKeyboard: false })
224224
this.toggleInputComment(false, event)
225225
})
226226
}
@@ -275,18 +275,19 @@ export default class DiaryDetail extends Component {
275275
return (
276276
<Container hidePadding={this.state.showBanner}>
277277
<KeyboardAwareScrollView>
278-
<TouchableOpacity
279-
onPress={() => this.setState({ showImgPreview: true })}
280-
activeOpacity={1}
281-
>
282-
<DiaryBanner
283-
showNav={true}
284-
showBanner={this.state.showBanner}
285-
imgPathList={this.state.imgPathList}
286-
leftButton={this.state.leftButton}
287-
rightButton={this.state.rightButton}
288-
/>
289-
</TouchableOpacity>
278+
<DiaryBanner
279+
showNav={true}
280+
showBanner={this.state.showBanner}
281+
imgPathList={this.state.imgPathList}
282+
leftButton={this.state.leftButton}
283+
rightButton={this.state.rightButton}
284+
onTouchStart={() => this.setState({ touchStartTs: Date.now() })}
285+
onTouchEnd={() => {
286+
if (Date.now() - this.state.touchStartTs < 80) {
287+
this.setState({ showImgPreview: true })
288+
}
289+
}}
290+
/>
290291

291292
{/* 在无图片日记下的顶部导航 */}
292293
<CommonNav
@@ -418,7 +419,7 @@ export default class DiaryDetail extends Component {
418419
>
419420
{this.state.likeComponent}
420421
</TouchableOpacity>
421-
422+
422423
<Animated.View
423424
style={[
424425
styles.input_container,
@@ -558,8 +559,8 @@ const styles = StyleSheet.create({
558559
...ifIphoneX({
559560
bottom: 48
560561
}, {
561-
bottom: 24
562-
})
562+
bottom: 24
563+
})
563564
},
564565
img_btn: {
565566
width: getResponsiveWidth(64),

src/containers/home/Home.js

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class Home extends Component {
8787

8888
// 读取日记配置文件
8989
this._formDiaryList(await readFile(this.props.user.id))
90-
this.props.user.id && await this._fetchDiary()
90+
await this._fetchDiary()
9191

9292
DeviceEventEmitter.addListener('flush_note', async () => {
9393
this._fetchDiary()
@@ -98,7 +98,7 @@ export default class Home extends Component {
9898
}
9999

100100
async _fetchDiary() {
101-
this.setState({ isRefreshing: true })
101+
if (!this.props.user.id) return
102102

103103
if (this.props.user.user_other_id === -1) {
104104
await updateFile({
@@ -113,9 +113,10 @@ export default class Home extends Component {
113113
const { partner, recommend, user } = res.data
114114
let diaryList = [...partner, ...user]
115115

116-
// 版本过渡:保存网络日记到本地配置文件
117116
const localDiaryList = await readFile(this.props.user.id)
117+
const localPartnerDiaryList = localDiaryList.filter(diary => diary.user_id !== this.props.user.id)
118118

119+
// 保存新日记
119120
let newDiaryList = []
120121
if (localDiaryList.length) {
121122
for (let i = 0; i < diaryList.length; i++) {
@@ -129,7 +130,31 @@ export default class Home extends Component {
129130
}
130131
}
131132
} else {
132-
newDiaryList = [...diaryList]
133+
newDiaryList = [...diaryList]
134+
}
135+
136+
// 删除、更新伙伴日记,
137+
let deleteDiaryList = [], updateDiaryList = []
138+
if (partner.length) {
139+
for (let i = 0; i < localPartnerDiaryList.length; i++) {
140+
for (let j = 0; j < partner.length; j++) {
141+
if (localPartnerDiaryList[i].id === partner[j].id) {
142+
break
143+
}
144+
if (j === partner.length - 1) {
145+
deleteDiaryList.push(localPartnerDiaryList[i])
146+
}
147+
}
148+
149+
for (let z = 0; z < partner.length; z++) {
150+
if ((localPartnerDiaryList[i].id === partner[z].id) && (localPartnerDiaryList[i].updated_at !== partner[z].updated_at)) {
151+
updateDiaryList.push({ ...localPartnerDiaryList[i], ...partner[z] })
152+
break
153+
}
154+
}
155+
}
156+
} else {
157+
deleteDiaryList = [...localPartnerDiaryList]
133158
}
134159

135160
for (let newDiary of newDiaryList) {
@@ -146,19 +171,40 @@ export default class Home extends Component {
146171
}
147172
}
148173

149-
this._formDiaryList(newDiaryList)
150-
// 更新配置文件
151-
updateFile({
174+
// 增加日记
175+
newDiaryList.length &&
176+
await updateFile({
152177
user_id: this.props.user.id || 0,
153178
action: 'add',
154179
data: newDiaryList
155180
})
156-
}
157181

158-
// this.setState({ isRefreshing: false })
182+
// 更新日记
183+
updateDiaryList.length &&
184+
await updateFile({
185+
user_id: this.props.user.id || 0,
186+
action: 'update',
187+
data: updateDiaryList
188+
})
189+
190+
// 删除日记
191+
deleteDiaryList.length &&
192+
await updateFile({
193+
user_id: this.props.user.id || 0,
194+
action: 'delete',
195+
data: deleteDiaryList
196+
})
197+
198+
this._formDiaryList(await readFile(this.props.user.id))
199+
}
159200
}
160201

161-
_formDiaryList(diaryList) {
202+
async _formDiaryList(diaryList) {
203+
this.setState({ isRefreshing: false })
204+
if (!diaryList) {
205+
diaryList = await readFile(this.props.user.id)
206+
}
207+
162208
diaryList.sort((a, b) => b.date - a.date)
163209
diaryList = diaryClassify(diaryList)
164210

@@ -535,7 +581,7 @@ export default class Home extends Component {
535581
renderItem={this._renderItem}
536582
ListEmptyComponent={() => this._emptyDiary()}
537583
ListFooterComponent={() => this._listFooter()}
538-
onRefresh={async () => this._formDiaryList(await readFile(this.props.user.id))}
584+
onRefresh={() => this._fetchDiary()}
539585
refreshing={this.state.isRefreshing}
540586
/>
541587

src/containers/profile/Profile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export default class Profile extends Component {
7272

7373
// 平均情绪值和日记数量
7474
this.setState({
75-
myAverageMode: Math.floor(myTotalMode / myDiaryList.length),
76-
otherAverageMode: Math.floor(otherTotalMode / otherDiaryList.length),
77-
myDiaryCount: myDiaryList.length,
78-
otherDiaryCount: otherDiaryList.length
75+
myAverageMode: Math.floor(myTotalMode / myDiaryList.length) || 0,
76+
otherAverageMode: Math.floor(otherTotalMode / otherDiaryList.length) || 0,
77+
myDiaryCount: myDiaryList.length || 0,
78+
otherDiaryCount: otherDiaryList.length || 0
7979
})
8080
}
8181

0 commit comments

Comments
 (0)