add previous and next buttons to navigate channel pages
This commit is contained in:
parent
6991b99ea9
commit
6b184c49ad
6 changed files with 70 additions and 16 deletions
4
app/package-lock.json
generated
4
app/package-lock.json
generated
|
@ -4060,8 +4060,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lbry-redux": {
|
"lbry-redux": {
|
||||||
"version": "github:lbryio/lbry-redux#1ed2ea8b2de99bbcba652aa7b00478d02df4a290",
|
"version": "github:lbryio/lbry-redux#18fec9f1f0f5ad366ebe12279e5dd0d67a37b2d5",
|
||||||
"from": "github:lbryio/lbry-redux",
|
"from": "github:lbryio/lbry-redux#mobile-channel-pagination",
|
||||||
"requires": {
|
"requires": {
|
||||||
"proxy-polyfill": "0.1.6",
|
"proxy-polyfill": "0.1.6",
|
||||||
"reselect": "^3.0.0",
|
"reselect": "^3.0.0",
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"base-64": "^0.1.0",
|
"base-64": "^0.1.0",
|
||||||
"@expo/vector-icons": "^8.1.0",
|
"@expo/vector-icons": "^8.1.0",
|
||||||
"lbry-redux": "lbryio/lbry-redux",
|
"lbry-redux": "lbryio/lbry-redux#mobile-channel-pagination",
|
||||||
"lbryinc": "lbryio/lbryinc#subscriptions",
|
"lbryinc": "lbryio/lbryinc#subscriptions",
|
||||||
"moment": "^2.22.1",
|
"moment": "^2.22.1",
|
||||||
"react": "16.2.0",
|
"react": "16.2.0",
|
||||||
|
|
|
@ -3,15 +3,17 @@ import {
|
||||||
doFetchClaimsByChannel,
|
doFetchClaimsByChannel,
|
||||||
doFetchClaimCountByChannel,
|
doFetchClaimCountByChannel,
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
makeSelectClaimsInChannelForPage,
|
makeSelectClaimsInChannelForCurrentPageState,
|
||||||
makeSelectFetchingChannelClaims,
|
makeSelectFetchingChannelClaims,
|
||||||
|
makeSelectTotalPagesForChannel
|
||||||
} from 'lbry-redux';
|
} from 'lbry-redux';
|
||||||
import ChannelPage from './view';
|
import ChannelPage from './view';
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
claim: makeSelectClaimForUri(props.uri)(state),
|
claim: makeSelectClaimForUri(props.uri)(state),
|
||||||
claimsInChannel: makeSelectClaimsInChannelForPage(props.uri, props.page || 1)(state),
|
claimsInChannel: makeSelectClaimsInChannelForCurrentPageState(props.uri)(state),
|
||||||
fetching: makeSelectFetchingChannelClaims(props.uri)(state),
|
fetching: makeSelectFetchingChannelClaims(props.uri)(state),
|
||||||
|
totalPages: makeSelectTotalPagesForChannel(props.uri, 10)(state), // Update to use a default PAGE_SIZE constant
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
|
|
@ -1,24 +1,47 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ActivityIndicator, Text, View } from 'react-native';
|
import { ActivityIndicator, Text, View } from 'react-native';
|
||||||
import Colors from '../../styles/colors';
|
import Colors from 'styles/colors';
|
||||||
import FileList from '../../component/fileList';
|
import Button from 'component/button';
|
||||||
import PageHeader from '../../component/pageHeader';
|
import FileList from 'component/fileList';
|
||||||
import UriBar from '../../component/uriBar';
|
import PageHeader from 'component/pageHeader';
|
||||||
import channelPageStyle from '../../styles/channelPage';
|
import UriBar from 'component/uriBar';
|
||||||
|
import channelPageStyle from 'styles/channelPage';
|
||||||
|
|
||||||
class ChannelPage extends React.PureComponent {
|
class ChannelPage extends React.PureComponent {
|
||||||
|
state = {
|
||||||
|
page: 1
|
||||||
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { uri, page, claimsInChannel, fetchClaims, fetchClaimCount } = this.props;
|
const { uri, page, claimsInChannel, fetchClaims, fetchClaimCount } = this.props;
|
||||||
|
|
||||||
if (!claimsInChannel || !claimsInChannel.length) {
|
if (!claimsInChannel || !claimsInChannel.length) {
|
||||||
fetchClaims(uri, page || 1);
|
fetchClaims(uri, page || this.state.page);
|
||||||
fetchClaimCount(uri);
|
fetchClaimCount(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePreviousPage = () => {
|
||||||
|
const { uri, fetchClaims } = this.props;
|
||||||
|
if (this.state.page > 1) {
|
||||||
|
this.setState({ page: this.state.page - 1 }, () => {
|
||||||
|
fetchClaims(uri, this.state.page);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleNextPage = () => {
|
||||||
|
const { uri, fetchClaims, totalPages } = this.props;
|
||||||
|
if (this.state.page < totalPages) {
|
||||||
|
this.setState({ page: this.state.page + 1 }, () => {
|
||||||
|
fetchClaims(uri, this.state.page);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { fetching, claimsInChannel, claim, navigation, uri } = this.props;
|
const { fetching, claimsInChannel, claim, navigation, totalPages, uri } = this.props;
|
||||||
const { name, permanent_url: permanentUrl } = claim;
|
const { name, permanent_url: permanentUrl } = claim;
|
||||||
|
|
||||||
let contentList;
|
let contentList;
|
||||||
|
@ -44,11 +67,25 @@ class ChannelPage extends React.PureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={channelPageStyle.container}>
|
<View style={channelPageStyle.container}>
|
||||||
<PageHeader title={name} onBackPressed={() => navigation.goBack(navigation.state.key)} />
|
<PageHeader title={name} onBackPressed={() => navigation.goBack(navigation.state.key)} />
|
||||||
{contentList}
|
{contentList}
|
||||||
|
{(totalPages > 1) &&
|
||||||
|
<View style={channelPageStyle.pageButtons}>
|
||||||
|
<View>
|
||||||
|
{(this.state.page > 1) && <Button
|
||||||
|
style={channelPageStyle.button}
|
||||||
|
text={"Previous"}
|
||||||
|
disabled={!!fetching}
|
||||||
|
onPress={this.handlePreviousPage} />}
|
||||||
|
</View>
|
||||||
|
{(this.state.page < totalPages) && <Button
|
||||||
|
style={[channelPageStyle.button, channelPageStyle.nextButton]}
|
||||||
|
text={"Next"}
|
||||||
|
disabled={!!fetching}
|
||||||
|
onPress={this.handleNextPage} />}
|
||||||
|
</View>}
|
||||||
<UriBar value={uri} navigation={navigation} />
|
<UriBar value={uri} navigation={navigation} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@ const channelPageStyle = StyleSheet.create({
|
||||||
fileList: {
|
fileList: {
|
||||||
paddingTop: 30,
|
paddingTop: 30,
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginBottom: 60
|
marginBottom: 16
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
color: Colors.LbryGreen,
|
color: Colors.LbryGreen,
|
||||||
|
@ -31,6 +31,21 @@ const channelPageStyle = StyleSheet.create({
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
marginLeft: 10
|
marginLeft: 10
|
||||||
|
},
|
||||||
|
pageButtons: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
paddingLeft: 16,
|
||||||
|
paddingRight: 16,
|
||||||
|
marginBottom: 76
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
backgroundColor: Colors.LbryGreen,
|
||||||
|
paddingLeft: 16,
|
||||||
|
paddingRight: 16
|
||||||
|
},
|
||||||
|
nextButton: {
|
||||||
|
alignSelf: 'flex-end'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue