mirror of
https://github.com/timepill/timepill-app.git
synced 2025-04-30 09:59:31 +08:00
1. 日记列表点出日记详情页
2. 用户头像点出用户详情页
This commit is contained in:
parent
a593225741
commit
3d44a3aaf5
10 changed files with 137 additions and 104 deletions
|
@ -39,7 +39,7 @@ export default class DiaryBrief extends Component {
|
|||
return (
|
||||
<View style={[localStyle.box, this.props.style]}>
|
||||
{(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.title}>
|
||||
|
|
|
@ -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() {
|
||||
if (this.state.refreshing) {
|
||||
return;
|
||||
|
@ -130,9 +170,10 @@ export default class DiaryList extends Component {
|
|||
|
||||
renderItem={({item}) => {
|
||||
return (
|
||||
<Touchable onPress={() => this.props.onDiaryPress(item)}>
|
||||
<Touchable onPress={() => this._onDiaryPress(item)}>
|
||||
<DiaryBrief diary={item}
|
||||
showField={this.props.showField}>
|
||||
showField={this.props.showField}
|
||||
onUserIconPress={() => this._onUserIconPress(item)}>
|
||||
</DiaryBrief>
|
||||
</Touchable>
|
||||
)
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
TouchableOpacity,
|
||||
ActivityIndicator
|
||||
} from 'react-native';
|
||||
import {Navigation} from 'react-native-navigation';
|
||||
import moment from 'moment'
|
||||
|
||||
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() {
|
||||
return this.notebook ? (
|
||||
<View style={localStyle.container}>
|
||||
|
@ -159,7 +180,7 @@ export default class NotebookDiaryList extends Component {
|
|||
sections={this.state.diaries}
|
||||
|
||||
renderItem={(rowData) => {
|
||||
return (<Touchable onPress={() => {}}>
|
||||
return (<Touchable onPress={() => this._onDiaryPress(rowData.item)}>
|
||||
<DiaryBrief diary={rowData.item}
|
||||
showField={['createdTime']}>
|
||||
</DiaryBrief>
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
RefreshControl,
|
||||
TouchableOpacity
|
||||
} from 'react-native';
|
||||
import {Navigation} from 'react-native-navigation';
|
||||
|
||||
import Api from '../../util/api';
|
||||
import Notebook from './notebook'
|
||||
|
@ -20,6 +21,8 @@ export default class NotebookList extends Component {
|
|||
|
||||
this.itemsPerRow = 2;
|
||||
this.state = {
|
||||
user: props.user,
|
||||
|
||||
notebooks: [],
|
||||
refreshing: false
|
||||
};
|
||||
|
@ -56,9 +59,31 @@ export default class NotebookList extends Component {
|
|||
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() {
|
||||
this.setState({refreshing: true});
|
||||
Api.getSelfNotebooks()
|
||||
|
||||
let user = this.state.user;
|
||||
(user ? Api.getUserNotebooks(user.id) : Api.getSelfNotebooks())
|
||||
.then(notebooks => {
|
||||
let groups = this.createGroup(notebooks, this.itemsPerRow);
|
||||
this.setState({
|
||||
|
@ -73,7 +98,7 @@ export default class NotebookList extends Component {
|
|||
_renderItem(notebook) {
|
||||
return notebook ? (
|
||||
<TouchableOpacity key={notebook.id} activeOpacity={0.7}
|
||||
onPress={() => this.props.onNotebookPress(notebook)}>
|
||||
onPress={() => this._onNotebookPress(notebook)}>
|
||||
|
||||
<Notebook key={notebook.id} notebook={notebook} />
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ export default class UserIntro extends Component {
|
|||
}
|
||||
|
||||
loadUser() {
|
||||
Api.getSelfInfoByStore()
|
||||
let user = this.state.user;
|
||||
(user ? Api.getUserInfo(user.id) : Api.getSelfInfoByStore())
|
||||
.then(user => {
|
||||
this.setState({
|
||||
user: user
|
||||
|
|
|
@ -35,20 +35,6 @@ export default class FollowPage extends Component {
|
|||
}
|
||||
|
||||
navigationButtonPressed({buttonId}) {
|
||||
/*
|
||||
Navigation.setRoot({
|
||||
root: {
|
||||
stack: {
|
||||
children: [{
|
||||
component: {
|
||||
name: 'FollowUser'
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Navigation.push(this.props.componentId, {
|
||||
component: {
|
||||
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() {
|
||||
return (
|
||||
<View style={localStyle.wrap}>
|
||||
<DiaryList ref={(r) => this.list = r}
|
||||
dataSource={this.dataSource}
|
||||
/* header={this.renderHeader.bind(this)} */
|
||||
onDiaryPress={this._onDiaryPress.bind(this)}
|
||||
|
||||
navigator={this.props.navigator}
|
||||
{...this.props}
|
||||
|
||||
></DiaryList>
|
||||
</View>
|
||||
|
|
|
@ -15,35 +15,12 @@ export default class HomePage extends Component {
|
|||
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() {
|
||||
return (
|
||||
<View style={localStyle.wrap}>
|
||||
<DiaryList ref={(r) => this.list = r}
|
||||
dataSource={this.dataSource}
|
||||
onDiaryPress={this._onDiaryPress.bind(this)}
|
||||
|
||||
navigator={this.props.navigator}
|
||||
{...this.props}
|
||||
|
||||
></DiaryList>
|
||||
</View>
|
||||
|
|
|
@ -10,7 +10,9 @@ export default class NotebookDetailPage extends Component {
|
|||
render() {
|
||||
return (
|
||||
<View style={{flex: 1}}>
|
||||
<NotebookDiaryList notebook={this.props.notebook}></NotebookDiaryList>
|
||||
<NotebookDiaryList notebook={this.props.notebook}
|
||||
{...this.props}>
|
||||
</NotebookDiaryList>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ export default class UserPage extends Component {
|
|||
constructor(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 = {
|
||||
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}) => {
|
||||
let routes = props.navigationState.routes;
|
||||
|
@ -75,16 +67,15 @@ export default class UserPage extends Component {
|
|||
|
||||
_renderScene = SceneMap({
|
||||
userIntro: () => <UserIntro
|
||||
user={this.user}
|
||||
/>,
|
||||
diary: () => <DiaryList
|
||||
dataSource={this.dataSource}
|
||||
onDiaryPress={() => {}}
|
||||
|
||||
navigator={this.props.navigator}
|
||||
{...this.props}
|
||||
/>,
|
||||
notebook: () => <NotebookList
|
||||
onNotebookPress={this._onNotebookPress.bind(this)}
|
||||
navigator={this.props.navigator}
|
||||
user={this.user}
|
||||
{...this.props}
|
||||
/>
|
||||
});
|
||||
|
||||
|
|
|
@ -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) {
|
||||
return call('GET', '/notebooks/' + id + '/diaries?page=' + page + '&page_size=' + page_size, null, 30000)
|
||||
.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() {
|
||||
return await TokenManager.getUserInfo();
|
||||
}
|
||||
|
||||
async function getUserTodayDiaries(userId) {
|
||||
return call('GET', '/users/' + userId + '/diaries/');
|
||||
async function getUserInfo(id) {
|
||||
return call('GET', '/users/' + id)
|
||||
}
|
||||
|
||||
async function getMessagesHistory() {
|
||||
|
@ -192,6 +200,7 @@ export default {
|
|||
|
||||
login,
|
||||
getSelfInfoByStore,
|
||||
getUserInfo,
|
||||
|
||||
getTodayDiaries,
|
||||
getFollowDiaries,
|
||||
|
@ -199,7 +208,9 @@ export default {
|
|||
getUserTodayDiaries,
|
||||
|
||||
getDiaryComments,
|
||||
|
||||
getSelfNotebooks,
|
||||
getUserNotebooks,
|
||||
|
||||
getRelationUsers,
|
||||
getRelationReverseUsers,
|
||||
|
|
Loading…
Reference in a new issue