mirror of
https://github.com/timepill/timepill-app.git
synced 2025-04-30 09:59:31 +08:00
增加合并日记本功能
This commit is contained in:
parent
d1ebc9e9b9
commit
afaee92fff
5 changed files with 190 additions and 21 deletions
|
@ -13,6 +13,7 @@ import {Navigation} from 'react-native-navigation';
|
||||||
import Api from '../../util/api';
|
import Api from '../../util/api';
|
||||||
import Notebook from './notebook'
|
import Notebook from './notebook'
|
||||||
import NotebookAdd from './notebookAdd'
|
import NotebookAdd from './notebookAdd'
|
||||||
|
import {Icon} from "../../style/icon";
|
||||||
|
|
||||||
|
|
||||||
export default class NotebookList extends Component {
|
export default class NotebookList extends Component {
|
||||||
|
@ -72,6 +73,11 @@ export default class NotebookList extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onNotebookPress(notebook) {
|
_onNotebookPress(notebook) {
|
||||||
|
if(this.props.onPress) {
|
||||||
|
this.props.onPress(notebook);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Navigation.push(this.props.componentId, {
|
Navigation.push(this.props.componentId, {
|
||||||
component: {
|
component: {
|
||||||
name: 'NotebookDetail',
|
name: 'NotebookDetail',
|
||||||
|
@ -102,6 +108,10 @@ export default class NotebookList extends Component {
|
||||||
notebooks.unshift({id: 'new'});
|
notebooks.unshift({id: 'new'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.props.filter) {
|
||||||
|
notebooks = notebooks.filter(this.props.filter);
|
||||||
|
}
|
||||||
|
|
||||||
let groups = this.createGroup(notebooks, this.itemsPerRow);
|
let groups = this.createGroup(notebooks, this.itemsPerRow);
|
||||||
this.setState({
|
this.setState({
|
||||||
notebooks: groups
|
notebooks: groups
|
||||||
|
|
|
@ -172,6 +172,26 @@ export default class NotebookEditPage extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openMargePage() {
|
||||||
|
Navigation.push(this.props.componentId, {
|
||||||
|
component: {
|
||||||
|
name: 'NotebookMerge',
|
||||||
|
passProps: {
|
||||||
|
notebook: this.props.notebook
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
bottomTabs: {
|
||||||
|
visible: false,
|
||||||
|
|
||||||
|
// hide bottom tab for android
|
||||||
|
drawBehind: true,
|
||||||
|
animate: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const tip = this.props.notebook ? (
|
const tip = this.props.notebook ? (
|
||||||
<View style={{padding: 15}}>
|
<View style={{padding: 15}}>
|
||||||
|
@ -241,7 +261,16 @@ export default class NotebookEditPage extends Component {
|
||||||
onPress={this._onEditCover.bind(this)}>
|
onPress={this._onEditCover.bind(this)}>
|
||||||
<Text style={localStyle.editCover}>设置封面</Text>
|
<Text style={localStyle.editCover}>设置封面</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
{(this.state.notebook.isExpired) && (
|
||||||
|
<>
|
||||||
|
<View style={localStyle.line} />
|
||||||
|
<TouchableOpacity style={localStyle.item} onPress={this.openMargePage.bind(this)}>
|
||||||
|
<Text style={localStyle.editCover}>合并日记本</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={localStyle.group}>
|
<View style={localStyle.group}>
|
||||||
<TouchableOpacity style={localStyle.item}
|
<TouchableOpacity style={localStyle.item}
|
||||||
onPress={this._onDelete.bind(this)}>
|
onPress={this._onDelete.bind(this)}>
|
||||||
|
|
125
src/page/NotebookMergePage.js
Normal file
125
src/page/NotebookMergePage.js
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
import {Component} from "react";
|
||||||
|
import UserBooks from "../component/notebook/notebookList";
|
||||||
|
import {ActivityIndicator, Alert, Animated, DeviceEventEmitter, Easing, Modal, Platform, View} from "react-native";
|
||||||
|
import React from "react";
|
||||||
|
import Api from '../util/api';
|
||||||
|
import colors from '../style/color';
|
||||||
|
import Toast from "react-native-root-toast";
|
||||||
|
import Event from "../util/event";
|
||||||
|
import {Navigation} from "react-native-navigation";
|
||||||
|
|
||||||
|
export default class NotebookMergePage extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
loading: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static options(passProps) {
|
||||||
|
return {
|
||||||
|
topBar: {
|
||||||
|
title: {
|
||||||
|
text: '合并日记本'
|
||||||
|
},
|
||||||
|
backButton: {
|
||||||
|
title: passProps.backTitle ? passProps.backTitle : '返回'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bottomTabs: {
|
||||||
|
visible: false,
|
||||||
|
|
||||||
|
// hide bottom tab for android
|
||||||
|
drawBehind: true,
|
||||||
|
animate: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
(async() => {
|
||||||
|
let user = await Api.getSelfInfoByStore();
|
||||||
|
this.setState({user: user});
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
|
||||||
|
onPress = (book) => {
|
||||||
|
Alert.alert('提示', '确认将《' + book.subject + '》合并到当前日记本?',[
|
||||||
|
{text: '确认合并', style: 'destructive', onPress: () => this.margeBooks(book)},
|
||||||
|
{text: '取消', onPress: () => console.log('OK Pressed!')},
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
margeBooks = async (book) => {
|
||||||
|
this.setState({loading: true});
|
||||||
|
let err = null;
|
||||||
|
try {
|
||||||
|
await Api.margeNotebook(book.id, this.props.notebook.id);
|
||||||
|
} catch (e) {
|
||||||
|
err = e.message;
|
||||||
|
}
|
||||||
|
this.setState({loading: false});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
let msg = "合并失败" + "\n" + err;
|
||||||
|
Toast.show(msg, {
|
||||||
|
duration: 2000,
|
||||||
|
position: 250,
|
||||||
|
shadow: false,
|
||||||
|
hideOnPress: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
DeviceEventEmitter.emit(Event.updateNotebooks);
|
||||||
|
Toast.show("合并完成", {
|
||||||
|
duration: 2000,
|
||||||
|
position: 250,
|
||||||
|
shadow: false,
|
||||||
|
hideOnPress: true,
|
||||||
|
});
|
||||||
|
Navigation.popToRoot(this.props.componentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
closeModal() {
|
||||||
|
Animated.parallel([
|
||||||
|
Animated.timing(
|
||||||
|
this.state.fadeAnimOpacity,
|
||||||
|
{toValue: 0, duration: 350, easing: Easing.out(Easing.cubic)}
|
||||||
|
),
|
||||||
|
Animated.timing(
|
||||||
|
this.state.fadeAnimHeight,
|
||||||
|
{toValue: 0, duration: 350, easing: Easing.out(Easing.cubic)}
|
||||||
|
)
|
||||||
|
]).start(() => {
|
||||||
|
this.setState({modalVisible: false});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if(!this.state.user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<View style={{flex: 1, backgroundColor: "white"}}>
|
||||||
|
<Modal
|
||||||
|
visible={this.state.loading}
|
||||||
|
transparent={true}
|
||||||
|
onRequestClose={() => {}}>
|
||||||
|
<View style={{ flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "rgba(255, 255, 255, 0.8)" }}>
|
||||||
|
<ActivityIndicator animating={true} color={colors.light} size={Platform.OS === 'android' ? 'large' : 'small'}/>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
|
<UserBooks
|
||||||
|
user={this.state.user}
|
||||||
|
// userId={this.props.notebook.user_id}
|
||||||
|
// mySelf={true}
|
||||||
|
// showAdd={false}
|
||||||
|
filter={(book) => book.isExpired && book.id !== this.props.notebook.id}
|
||||||
|
onPress={this.onPress}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ FollowUser: require("./FollowUserPage.js").default,
|
||||||
Home: require("./HomePage.js").default,
|
Home: require("./HomePage.js").default,
|
||||||
NotebookDetail: require("./NotebookDetailPage.js").default,
|
NotebookDetail: require("./NotebookDetailPage.js").default,
|
||||||
NotebookEdit: require("./NotebookEditPage.js").default,
|
NotebookEdit: require("./NotebookEditPage.js").default,
|
||||||
|
NotebookMerge: require("./NotebookMergePage.js").default,
|
||||||
NotificationHistory: require("./NotificationHistoryPage.js").default,
|
NotificationHistory: require("./NotificationHistoryPage.js").default,
|
||||||
Notification: require("./NotificationPage.js").default,
|
Notification: require("./NotificationPage.js").default,
|
||||||
Password: require("./PasswordPage.js").default,
|
Password: require("./PasswordPage.js").default,
|
||||||
|
|
|
@ -349,6 +349,9 @@ async function deleteNotebook(id) {
|
||||||
return call('DELETE', '/notebooks/' + id)
|
return call('DELETE', '/notebooks/' + id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function margeNotebook(from, to) {
|
||||||
|
return callV2('POST', `/notebooks/${from}/marge_to/${to}`);
|
||||||
|
}
|
||||||
|
|
||||||
async function report(user_id, diary_id) {
|
async function report(user_id, diary_id) {
|
||||||
return call('POST', '/reports/', {
|
return call('POST', '/reports/', {
|
||||||
|
@ -567,6 +570,7 @@ export default {
|
||||||
createNotebook,
|
createNotebook,
|
||||||
updateNotebook,
|
updateNotebook,
|
||||||
deleteNotebook,
|
deleteNotebook,
|
||||||
|
margeNotebook,
|
||||||
|
|
||||||
report,
|
report,
|
||||||
feedback,
|
feedback,
|
||||||
|
|
Loading…
Reference in a new issue