1. 日记列表点出日记详情页

2. 用户头像点出用户详情页
This commit is contained in:
xuwenyang 2019-05-22 00:21:34 +08:00
parent a593225741
commit 3d44a3aaf5
10 changed files with 137 additions and 104 deletions

View file

@ -39,7 +39,7 @@ export default class DiaryBrief extends Component {
return ( return (
<View style={[localStyle.box, this.props.style]}> <View style={[localStyle.box, this.props.style]}>
{(user && user.iconUrl && this.show('icon')) {(user && user.iconUrl && this.show('icon'))
? <UserIcon iconUrl={user.iconUrl}></UserIcon> : null} ? <UserIcon iconUrl={user.iconUrl} onPress={this.props.onUserIconPress}></UserIcon> : null}
<View style={localStyle.body}> <View style={localStyle.body}>
<View style={localStyle.title}> <View style={localStyle.title}>

View file

@ -42,6 +42,46 @@ export default class DiaryList extends Component {
}); });
} }
_onUserIconPress(diary) {
Navigation.push(this.props.componentId, {
component: {
name: 'User',
options: {
bottomTabs: {
visible: false,
// hide bottom tab for android
drawBehind: true,
animate: true
}
},
passProps: {
user: diary.user
}
}
});
}
_onDiaryPress(diary) {
Navigation.push(this.props.componentId, {
component: {
name: 'DiaryDetail',
options: {
bottomTabs: {
visible: false,
// hide bottom tab for android
drawBehind: true,
animate: true
}
},
passProps: {
diary: diary
}
}
});
}
async refresh() { async refresh() {
if (this.state.refreshing) { if (this.state.refreshing) {
return; return;
@ -130,9 +170,10 @@ export default class DiaryList extends Component {
renderItem={({item}) => { renderItem={({item}) => {
return ( return (
<Touchable onPress={() => this.props.onDiaryPress(item)}> <Touchable onPress={() => this._onDiaryPress(item)}>
<DiaryBrief diary={item} <DiaryBrief diary={item}
showField={this.props.showField}> showField={this.props.showField}
onUserIconPress={() => this._onUserIconPress(item)}>
</DiaryBrief> </DiaryBrief>
</Touchable> </Touchable>
) )

View file

@ -8,6 +8,7 @@ import {
TouchableOpacity, TouchableOpacity,
ActivityIndicator ActivityIndicator
} from 'react-native'; } from 'react-native';
import {Navigation} from 'react-native-navigation';
import moment from 'moment' import moment from 'moment'
import Api from '../../util/api'; import Api from '../../util/api';
@ -149,6 +150,26 @@ export default class NotebookDiaryList extends Component {
}); });
} }
_onDiaryPress(diary) {
Navigation.push(this.props.componentId, {
component: {
name: 'DiaryDetail',
options: {
bottomTabs: {
visible: false,
// hide bottom tab for android
drawBehind: true,
animate: true
}
},
passProps: {
diary: diary
}
}
});
}
render() { render() {
return this.notebook ? ( return this.notebook ? (
<View style={localStyle.container}> <View style={localStyle.container}>
@ -159,7 +180,7 @@ export default class NotebookDiaryList extends Component {
sections={this.state.diaries} sections={this.state.diaries}
renderItem={(rowData) => { renderItem={(rowData) => {
return (<Touchable onPress={() => {}}> return (<Touchable onPress={() => this._onDiaryPress(rowData.item)}>
<DiaryBrief diary={rowData.item} <DiaryBrief diary={rowData.item}
showField={['createdTime']}> showField={['createdTime']}>
</DiaryBrief> </DiaryBrief>

View file

@ -8,6 +8,7 @@ import {
RefreshControl, RefreshControl,
TouchableOpacity TouchableOpacity
} from 'react-native'; } from 'react-native';
import {Navigation} from 'react-native-navigation';
import Api from '../../util/api'; import Api from '../../util/api';
import Notebook from './notebook' import Notebook from './notebook'
@ -20,6 +21,8 @@ export default class NotebookList extends Component {
this.itemsPerRow = 2; this.itemsPerRow = 2;
this.state = { this.state = {
user: props.user,
notebooks: [], notebooks: [],
refreshing: false refreshing: false
}; };
@ -56,9 +59,31 @@ export default class NotebookList extends Component {
return groups; return groups;
} }
_onNotebookPress(notebook) {
Navigation.push(this.props.componentId, {
component: {
name: 'NotebookDetail',
options: {
bottomTabs: {
visible: false,
// hide bottom tab for android
drawBehind: true,
animate: true
}
},
passProps: {
notebook: notebook
}
}
});
}
refresh() { refresh() {
this.setState({refreshing: true}); this.setState({refreshing: true});
Api.getSelfNotebooks()
let user = this.state.user;
(user ? Api.getUserNotebooks(user.id) : Api.getSelfNotebooks())
.then(notebooks => { .then(notebooks => {
let groups = this.createGroup(notebooks, this.itemsPerRow); let groups = this.createGroup(notebooks, this.itemsPerRow);
this.setState({ this.setState({
@ -73,7 +98,7 @@ export default class NotebookList extends Component {
_renderItem(notebook) { _renderItem(notebook) {
return notebook ? ( return notebook ? (
<TouchableOpacity key={notebook.id} activeOpacity={0.7} <TouchableOpacity key={notebook.id} activeOpacity={0.7}
onPress={() => this.props.onNotebookPress(notebook)}> onPress={() => this._onNotebookPress(notebook)}>
<Notebook key={notebook.id} notebook={notebook} /> <Notebook key={notebook.id} notebook={notebook} />

View file

@ -29,7 +29,8 @@ export default class UserIntro extends Component {
} }
loadUser() { loadUser() {
Api.getSelfInfoByStore() let user = this.state.user;
(user ? Api.getUserInfo(user.id) : Api.getSelfInfoByStore())
.then(user => { .then(user => {
this.setState({ this.setState({
user: user user: user

View file

@ -35,20 +35,6 @@ export default class FollowPage extends Component {
} }
navigationButtonPressed({buttonId}) { navigationButtonPressed({buttonId}) {
/*
Navigation.setRoot({
root: {
stack: {
children: [{
component: {
name: 'FollowUser'
}
}]
}
}
});
*/
Navigation.push(this.props.componentId, { Navigation.push(this.props.componentId, {
component: { component: {
name: 'FollowUser', name: 'FollowUser',
@ -66,34 +52,12 @@ export default class FollowPage extends Component {
} }
_onDiaryPress(diary) {
Navigation.push(this.props.componentId, {
component: {
name: 'DiaryDetail',
passProps: {
diary: diary
}
}
});
}
renderHeader() {
return (
<View style={localStyle.header}>
<Text style={localStyle.title}>关注</Text>
</View>
);
}
render() { render() {
return ( return (
<View style={localStyle.wrap}> <View style={localStyle.wrap}>
<DiaryList ref={(r) => this.list = r} <DiaryList ref={(r) => this.list = r}
dataSource={this.dataSource} dataSource={this.dataSource}
/* header={this.renderHeader.bind(this)} */ {...this.props}
onDiaryPress={this._onDiaryPress.bind(this)}
navigator={this.props.navigator}
></DiaryList> ></DiaryList>
</View> </View>

View file

@ -15,35 +15,12 @@ export default class HomePage extends Component {
this.dataSource = new HomeDiaryData(); this.dataSource = new HomeDiaryData();
} }
_onDiaryPress(diary) {
console.log('componentId:', this.props.componentId, diary);
Navigation.push(this.props.componentId, {
component: {
name: 'DiaryDetail',
options: {
bottomTabs: {
visible: false,
// hide bottom tab for android
drawBehind: true,
animate: true
}
},
passProps: {
diary: diary
}
}
});
}
render() { render() {
return ( return (
<View style={localStyle.wrap}> <View style={localStyle.wrap}>
<DiaryList ref={(r) => this.list = r} <DiaryList ref={(r) => this.list = r}
dataSource={this.dataSource} dataSource={this.dataSource}
onDiaryPress={this._onDiaryPress.bind(this)} {...this.props}
navigator={this.props.navigator}
></DiaryList> ></DiaryList>
</View> </View>

View file

@ -10,7 +10,9 @@ export default class NotebookDetailPage extends Component {
render() { render() {
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<NotebookDiaryList notebook={this.props.notebook}></NotebookDiaryList> <NotebookDiaryList notebook={this.props.notebook}
{...this.props}>
</NotebookDiaryList>
</View> </View>
); );
} }

View file

@ -22,7 +22,9 @@ export default class UserPage extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.dataSource = new UserDiaryData(); this.user = props.user;
this.userId = this.user ? this.user.id : (props.userId || 0);
this.dataSource = new UserDiaryData(this.userId);
this.state = { this.state = {
index: 0, index: 0,
@ -34,17 +36,7 @@ export default class UserPage extends Component {
}; };
} }
_onNotebookPress(notebook) {
Navigation.push(this.props.componentId, {
component: {
name: 'NotebookDetail',
passProps: {
notebook: notebook
}
}
});
}
_renderLabel = props => ({route}) => { _renderLabel = props => ({route}) => {
let routes = props.navigationState.routes; let routes = props.navigationState.routes;
@ -75,16 +67,15 @@ export default class UserPage extends Component {
_renderScene = SceneMap({ _renderScene = SceneMap({
userIntro: () => <UserIntro userIntro: () => <UserIntro
user={this.user}
/>, />,
diary: () => <DiaryList diary: () => <DiaryList
dataSource={this.dataSource} dataSource={this.dataSource}
onDiaryPress={() => {}} {...this.props}
navigator={this.props.navigator}
/>, />,
notebook: () => <NotebookList notebook: () => <NotebookList
onNotebookPress={this._onNotebookPress.bind(this)} user={this.user}
navigator={this.props.navigator} {...this.props}
/> />
}); });

View file

@ -65,22 +65,6 @@ async function getFollowDiaries(page = 1, page_size = 20, first_id = '') {
}); });
} }
async function getDiaryComments(diaryId) {
return call('GET', '/diaries/' + diaryId + '/comments')
}
async function getSelfNotebooks() {
return call('GET', '/notebooks/my')
}
async function getRelationUsers(page, page_size) {
return call('GET', `/relation?page=${page}&page_size=${page_size}`);
}
async function getRelationReverseUsers(page, page_size) {
return call('GET', `/relation/reverse?page=${page}&page_size=${page_size}`);
}
async function getNotebookDiaries(id, page, page_size) { async function getNotebookDiaries(id, page, page_size) {
return call('GET', '/notebooks/' + id + '/diaries?page=' + page + '&page_size=' + page_size, null, 30000) return call('GET', '/notebooks/' + id + '/diaries?page=' + page + '&page_size=' + page_size, null, 30000)
.then((json) => { .then((json) => {
@ -91,12 +75,36 @@ async function getNotebookDiaries(id, page, page_size) {
}); });
} }
async function getUserTodayDiaries(userId) {
return call('GET', '/users/' + userId + '/diaries/');
}
async function getDiaryComments(diaryId) {
return call('GET', '/diaries/' + diaryId + '/comments')
}
async function getSelfNotebooks() {
return call('GET', '/notebooks/my')
}
async function getUserNotebooks(id) {
return call('GET', '/users/' + id + '/notebooks')
}
async function getRelationUsers(page, page_size) {
return call('GET', `/relation?page=${page}&page_size=${page_size}`);
}
async function getRelationReverseUsers(page, page_size) {
return call('GET', `/relation/reverse?page=${page}&page_size=${page_size}`);
}
async function getSelfInfoByStore() { async function getSelfInfoByStore() {
return await TokenManager.getUserInfo(); return await TokenManager.getUserInfo();
} }
async function getUserTodayDiaries(userId) { async function getUserInfo(id) {
return call('GET', '/users/' + userId + '/diaries/'); return call('GET', '/users/' + id)
} }
async function getMessagesHistory() { async function getMessagesHistory() {
@ -192,6 +200,7 @@ export default {
login, login,
getSelfInfoByStore, getSelfInfoByStore,
getUserInfo,
getTodayDiaries, getTodayDiaries,
getFollowDiaries, getFollowDiaries,
@ -199,7 +208,9 @@ export default {
getUserTodayDiaries, getUserTodayDiaries,
getDiaryComments, getDiaryComments,
getSelfNotebooks, getSelfNotebooks,
getUserNotebooks,
getRelationUsers, getRelationUsers,
getRelationReverseUsers, getRelationReverseUsers,