Skip to content

Commit

Permalink
- [x] [首页进度、条目] 章节按钮长按切换看过/撤销
Browse files Browse the repository at this point in the history
- [x] [条目] 优化章节点击 ‘看到’ 之后反馈,  不再需要重复刷新才会更新状态
  • Loading branch information
czy0729 committed Sep 5, 2019
1 parent db5fc63 commit 530c61a
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 71 deletions.
6 changes: 4 additions & 2 deletions components/@/ant-design/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export default class Popover extends React.PureComponent {
disabled,
triggerStyle,
styles,
placement
placement,
onLongPress // @add
} = this.props
return (
<WithTheme themeStyles={PopoverStyles} styles={styles}>
Expand All @@ -98,6 +99,7 @@ export default class Popover extends React.PureComponent {
<TouchableOpacity
ref={setPopoverAnchor}
onPress={openPopover}
onLongPress={onLongPress} // @add
style={triggerStyle}
disabled={disabled}
activeOpacity={0.75}
Expand All @@ -106,7 +108,7 @@ export default class Popover extends React.PureComponent {
</TouchableOpacity>
<Pop
popoverStyle={s.popover}
contentStyle={[s.content, contentStyle]}
contentStyle={[s.content, contentStyle]} // @add
arrowStyle={Platform.OS === 'ios' ? s.arrow : s.arrowAndroid}
backgroundStyle={s.background}
visible={popoverVisible}
Expand Down
3 changes: 2 additions & 1 deletion components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: czy0729
* @Date: 2019-03-15 02:32:29
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-30 18:09:04
* @Last Modified time: 2019-09-05 12:10:10
*/
import React from 'react'
import { StyleSheet, View } from 'react-native'
Expand Down Expand Up @@ -64,6 +64,7 @@ function Button({
_text
]}
align='center'
selectable={false}
>
{children}
</Text>
Expand Down
13 changes: 9 additions & 4 deletions components/popover/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: czy0729
* @Date: 2019-05-05 02:45:46
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-14 10:32:36
* @Last Modified time: 2019-09-05 12:14:16
*/
import React from 'react'
import { StyleSheet, UIManager, findNodeHandle, View } from 'react-native'
Expand All @@ -12,7 +12,8 @@ import Touchable from '../touchable'
export default class Popover extends React.Component {
static defaultProps = {
data: [],
onSelect: Function.prototype
onSelect: Function.prototype,
onLongPress: Function.prototype
}

ref
Expand All @@ -35,11 +36,15 @@ export default class Popover extends React.Component {
}

render() {
const { style, children } = this.props
const { style, onLongPress, children } = this.props
return (
<View>
<View ref={ref => (this.ref = ref)} style={styles.overflowView} />
<Touchable style={style} onPress={this.showPopupAndroid}>
<Touchable
style={style}
onPress={this.showPopupAndroid}
onLongPress={onLongPress}
>
{children}
</Touchable>
</View>
Expand Down
4 changes: 2 additions & 2 deletions navigations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @Author: czy0729
* @Date: 2019-06-02 14:42:28
* @Last Modified by: czy0729
* @Last Modified time: 2019-09-04 22:27:16
* @Last Modified time: 2019-09-05 14:22:32
*/
export default {
initialRouteName: 'HomeTab', // HomeTab TinygrailOverview TinygrailTrade
initialRouteParams: {
// subjectId: 238923 // 238923 100444 204135
// subjectId: 100444 // 238923 100444 204135
// topicId: 'group/352146' // ep/768491
// userId: '421853' // '419012'
// monoId: 'character/11396' // character/70323 person/5745
Expand Down
12 changes: 7 additions & 5 deletions screens/_/base/eps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-15 02:19:02
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-31 00:23:36
* @Last Modified time: 2019-09-05 12:17:54
*/
import React from 'react'
import { StyleSheet, View } from 'react-native'
Expand All @@ -27,7 +27,8 @@ class Eps extends React.Component {
canPlay: false, // 有播放源
eps: [], // 章节数据
userProgress: {}, // 用户收藏记录
onSelect: Function.prototype // 操作选择
onSelect: Function.prototype, // 操作选择
onLongPress: Function.prototype // 按钮长按
}

static pageLimit = 32 // 1页32个
Expand Down Expand Up @@ -109,7 +110,7 @@ class Eps extends React.Component {
return (
<Menu
title={[
`ep.${item.sort} ${item.name || item.name_cn}`,
`ep.${item.sort} ${item.name_cn || item.name}`,
`${item.airdate} 讨论数:${item.comment}`
]}
data={this.getPopoverData(item)}
Expand All @@ -123,7 +124,7 @@ class Eps extends React.Component {
* @param {*} num 当前第几个
*/
renderButton(item, num) {
const { numbersOfLine, userProgress } = this.props
const { numbersOfLine, userProgress, onLongPress } = this.props
const { width, margin } = this.style
const isSide = num % numbersOfLine === 0
const popoverProps = IOS
Expand All @@ -141,6 +142,7 @@ class Eps extends React.Component {
marginRight: isSide ? 0 : margin,
marginBottom: margin
}}
onLongPress={() => onLongPress(item)}
{...popoverProps}
>
<Button
Expand Down Expand Up @@ -333,7 +335,7 @@ const styles = StyleSheet.create({
}
})

const getType = (progress, status) => {
function getType(progress, status) {
switch (progress) {
case '想看':
return 'main'
Expand Down
3 changes: 2 additions & 1 deletion screens/home/index/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-14 15:20:53
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-31 00:40:18
* @Last Modified time: 2019-09-05 13:54:48
*/
import React from 'react'
import { StyleSheet, View } from 'react-native'
Expand Down Expand Up @@ -260,6 +260,7 @@ class Item extends React.Component {
onSelect={(value, item, subjectId) =>
$.doEpsSelect(value, item, subjectId, navigation)
}
onLongPress={item => $.doEpsLongPress(item, subjectId)}
/>
)}
{top && (
Expand Down
33 changes: 28 additions & 5 deletions screens/home/index/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: czy0729
* @Date: 2019-03-21 16:49:03
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-31 00:48:21
* @Last Modified time: 2019-09-05 14:22:14
*/
import { observable, computed } from 'mobx'
import { userStore, subjectStore, collectionStore } from '@stores'
Expand Down Expand Up @@ -430,8 +430,8 @@ export default class ScreenHome extends store {
id: item.id,
status
})
userStore.fetchUserCollection()
userStore.fetchUserProgress()
userStore.fetchUserCollection(subjectId)
userStore.fetchUserProgress(subjectId)
}

if (value === '看到') {
Expand All @@ -440,13 +440,36 @@ export default class ScreenHome extends store {
subjectId,
sort: item.sort
})
userStore.fetchUserCollection()
userStore.fetchUserProgress()
userStore.fetchUserCollection(subjectId)
userStore.fetchUserProgress(subjectId)
}

// iOS是本集讨论, 安卓是(+N)...
if (value.includes('本集讨论') || value.includes('(+')) {
appNavigate(item.url, navigation)
}
}

/**
* 章节按钮长按
*/
doEpsLongPress = async ({ id }, subjectId) => {
const userProgress = this.userProgress(subjectId)

let status
if (userProgress[id]) {
// 已观看 -> 撤销
status = MODEL_EP_STATUS.getValue('撤销')
} else {
// 未观看 -> 看过
status = MODEL_EP_STATUS.getValue('看过')
}

await userStore.doUpdateEpStatus({
id,
status
})
userStore.fetchUserCollection(subjectId)
userStore.fetchUserProgress(subjectId)
}
}
3 changes: 2 additions & 1 deletion screens/home/subject/ep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-24 04:39:13
* @Last Modified by: czy0729
* @Last Modified time: 2019-08-23 00:33:35
* @Last Modified time: 2019-09-05 14:04:13
*/
import React from 'react'
import { StyleSheet, View } from 'react-native'
Expand Down Expand Up @@ -59,6 +59,7 @@ function Ep({ style }, { $, navigation }) {
userProgress={$.userProgress}
canPlay={canPlay}
onSelect={(value, item) => $.doEpsSelect(value, item, navigation)}
onLongPress={item => $.doEpsLongPress(item)}
/>
</View>
)
Expand Down
Loading

0 comments on commit 530c61a

Please sign in to comment.