Skip to content

Commit

Permalink
fix: 修复了首页刷新、日记图片、个人数据显示等BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
light authored and light committed Aug 3, 2018
1 parent 0172902 commit eaff1ff
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 43 deletions.
Binary file modified .DS_Store
Binary file not shown.
97 changes: 91 additions & 6 deletions ios/twolife.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Binary file modified res/images/profile/.DS_Store
Binary file not shown.
11 changes: 9 additions & 2 deletions src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,13 @@ export async function updateFile(obj) {

// 不用同步直接删除日记
if (obj.action === 'delete') {
diaryList = diaryList.filter(diary => diary.uuid !== obj.data.uuid)
if (obj.data instanceof Array) {
for (let i = 0; i < obj.data.length; i++) {
diaryList = diaryList.filter(diary => diary.uuid !== obj.data[i].uuid)
}
} else {
diaryList = diaryList.filter(diary => diary.uuid !== obj.data.uuid)
}
}

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

await fs.writeFile(FILE_PATH, JSON.stringify(newContent), 'utf8')

console.log(obj.action)
console.log(obj.data)
DeviceEventEmitter.emit('flush_local_note')
}

Expand Down
1 change: 0 additions & 1 deletion src/containers/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default class Index extends Component {
})
// 刷新通知、刷新日记、刷新用户
DeviceEventEmitter.emit('flush_notification', {})

const res = await HttpUtils.get(USERS.user, { user_id: this.props.user.id })
if (res.code === 0) {
store.dispatch(fetchProfileSuccess(res.data))
Expand Down
5 changes: 4 additions & 1 deletion src/containers/home/DiaryBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ export default class DiaryBanner extends Component {
width={WIDTH}
height={getResponsiveWidth(282)}
style={styles.swiper}
loop={false}
autoplay
loop={false} //true有BUG
dot={<View style={styles.swiper_dot}></View>}
activeDot={<View style={[styles.swiper_dot, styles.swiper_active_dot]}></View>}
bounces={true}
onIndexChanged={this._onImgChanged.bind(this)}
onTouchStart={this.props.onTouchStart}
onTouchEnd={this.props.onTouchEnd}
>
{this.state.imgListComponent}
</Swiper>
Expand Down
35 changes: 18 additions & 17 deletions src/containers/home/DiaryDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ export default class DiaryDetail extends Component {

setKeyboard() {
Keyboard.addListener('keyboardWillShow', event => {
this.setState({showKeyboard: true})
this.setState({ showKeyboard: true })
this.toggleInputComment(true, event)
})
Keyboard.addListener('keyboardWillHide', event => {
this.setState({showKeyboard: false})
this.setState({ showKeyboard: false })
this.toggleInputComment(false, event)
})
}
Expand Down Expand Up @@ -275,18 +275,19 @@ export default class DiaryDetail extends Component {
return (
<Container hidePadding={this.state.showBanner}>
<KeyboardAwareScrollView>
<TouchableOpacity
onPress={() => this.setState({ showImgPreview: true })}
activeOpacity={1}
>
<DiaryBanner
showNav={true}
showBanner={this.state.showBanner}
imgPathList={this.state.imgPathList}
leftButton={this.state.leftButton}
rightButton={this.state.rightButton}
/>
</TouchableOpacity>
<DiaryBanner
showNav={true}
showBanner={this.state.showBanner}
imgPathList={this.state.imgPathList}
leftButton={this.state.leftButton}
rightButton={this.state.rightButton}
onTouchStart={() => this.setState({ touchStartTs: Date.now() })}
onTouchEnd={() => {
if (Date.now() - this.state.touchStartTs < 80) {
this.setState({ showImgPreview: true })
}
}}
/>

{/* 在无图片日记下的顶部导航 */}
<CommonNav
Expand Down Expand Up @@ -418,7 +419,7 @@ export default class DiaryDetail extends Component {
>
{this.state.likeComponent}
</TouchableOpacity>

<Animated.View
style={[
styles.input_container,
Expand Down Expand Up @@ -558,8 +559,8 @@ const styles = StyleSheet.create({
...ifIphoneX({
bottom: 48
}, {
bottom: 24
})
bottom: 24
})
},
img_btn: {
width: getResponsiveWidth(64),
Expand Down
68 changes: 57 additions & 11 deletions src/containers/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class Home extends Component {

// 读取日记配置文件
this._formDiaryList(await readFile(this.props.user.id))
this.props.user.id && await this._fetchDiary()
await this._fetchDiary()

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

async _fetchDiary() {
this.setState({ isRefreshing: true })
if (!this.props.user.id) return

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

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

// 保存新日记
let newDiaryList = []
if (localDiaryList.length) {
for (let i = 0; i < diaryList.length; i++) {
Expand All @@ -129,7 +130,31 @@ export default class Home extends Component {
}
}
} else {
newDiaryList = [...diaryList]
newDiaryList = [...diaryList]
}

// 删除、更新伙伴日记,
let deleteDiaryList = [], updateDiaryList = []
if (partner.length) {
for (let i = 0; i < localPartnerDiaryList.length; i++) {
for (let j = 0; j < partner.length; j++) {
if (localPartnerDiaryList[i].id === partner[j].id) {
break
}
if (j === partner.length - 1) {
deleteDiaryList.push(localPartnerDiaryList[i])
}
}

for (let z = 0; z < partner.length; z++) {
if ((localPartnerDiaryList[i].id === partner[z].id) && (localPartnerDiaryList[i].updated_at !== partner[z].updated_at)) {
updateDiaryList.push({ ...localPartnerDiaryList[i], ...partner[z] })
break
}
}
}
} else {
deleteDiaryList = [...localPartnerDiaryList]
}

for (let newDiary of newDiaryList) {
Expand All @@ -146,19 +171,40 @@ export default class Home extends Component {
}
}

this._formDiaryList(newDiaryList)
// 更新配置文件
updateFile({
// 增加日记
newDiaryList.length &&
await updateFile({
user_id: this.props.user.id || 0,
action: 'add',
data: newDiaryList
})
}

// this.setState({ isRefreshing: false })
// 更新日记
updateDiaryList.length &&
await updateFile({
user_id: this.props.user.id || 0,
action: 'update',
data: updateDiaryList
})

// 删除日记
deleteDiaryList.length &&
await updateFile({
user_id: this.props.user.id || 0,
action: 'delete',
data: deleteDiaryList
})

this._formDiaryList(await readFile(this.props.user.id))
}
}

_formDiaryList(diaryList) {
async _formDiaryList(diaryList) {
this.setState({ isRefreshing: false })
if (!diaryList) {
diaryList = await readFile(this.props.user.id)
}

diaryList.sort((a, b) => b.date - a.date)
diaryList = diaryClassify(diaryList)

Expand Down Expand Up @@ -535,7 +581,7 @@ export default class Home extends Component {
renderItem={this._renderItem}
ListEmptyComponent={() => this._emptyDiary()}
ListFooterComponent={() => this._listFooter()}
onRefresh={async () => this._formDiaryList(await readFile(this.props.user.id))}
onRefresh={() => this._fetchDiary()}
refreshing={this.state.isRefreshing}
/>

Expand Down
8 changes: 4 additions & 4 deletions src/containers/profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export default class Profile extends Component {

// 平均情绪值和日记数量
this.setState({
myAverageMode: Math.floor(myTotalMode / myDiaryList.length),
otherAverageMode: Math.floor(otherTotalMode / otherDiaryList.length),
myDiaryCount: myDiaryList.length,
otherDiaryCount: otherDiaryList.length
myAverageMode: Math.floor(myTotalMode / myDiaryList.length) || 0,
otherAverageMode: Math.floor(otherTotalMode / otherDiaryList.length) || 0,
myDiaryCount: myDiaryList.length || 0,
otherDiaryCount: otherDiaryList.length || 0
})
}

Expand Down
8 changes: 8 additions & 0 deletions src/containers/profile/ProfileTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class ProfileReward extends Component {
<View style={styles.result_container}>
<Radar data={data} height={getResponsiveWidth(240)} />
<TextPingFang style={styles.text_result}>性格测试完成啦,但为了让结果更准确,你还需要多写几篇真情流露的日记呢</TextPingFang>
<TextPingFang style={styles.text_small}>稍后可在「个人页」→「情绪管理」查看更详细内容</TextPingFang>
</View>
)

Expand Down Expand Up @@ -183,6 +184,13 @@ const styles = StyleSheet.create({
fontWeight: '400',
textAlign: 'center'
},
text_small: {
color: '#aaa',
fontSize: 12,
fontWeight: '400',
textAlign: 'center',
marginTop: getResponsiveWidth(8)
},
question_container: {
width: WIDTH - getResponsiveWidth(48),
height: getResponsiveWidth(360),
Expand Down
1 change: 0 additions & 1 deletion src/network/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function setToken(data) {
}

// let baseUrl = 'http://localhost:3002'
// let baseUrl = 'http://172.20.10.4:3002'
let baseUrl = 'https://2life.api.ursb.me'

axios.defaults.timeout = 20000
Expand Down

0 comments on commit eaff1ff

Please sign in to comment.