You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-09-16 08:56:40 +02:00
Change list mode
This commit is contained in:
@@ -8,8 +8,7 @@ import { _ } from 'src/locale.js';
|
|||||||
|
|
||||||
class FolderListComponent extends ItemListComponent {
|
class FolderListComponent extends ItemListComponent {
|
||||||
|
|
||||||
listView_itemClick = (folderId) => {
|
listView_itemPress = (folderId) => {
|
||||||
|
|
||||||
Note.previews(folderId).then((notes) => {
|
Note.previews(folderId).then((notes) => {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'NOTES_UPDATE_ALL',
|
type: 'NOTES_UPDATE_ALL',
|
||||||
@@ -30,7 +29,10 @@ class FolderListComponent extends ItemListComponent {
|
|||||||
|
|
||||||
const FolderList = connect(
|
const FolderList = connect(
|
||||||
(state) => {
|
(state) => {
|
||||||
return { items: state.folders };
|
return {
|
||||||
|
items: state.folders,
|
||||||
|
listMode: state.listMode,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
)(FolderListComponent)
|
)(FolderListComponent)
|
||||||
|
|
||||||
|
@@ -8,33 +8,63 @@ class ItemListComponent extends Component {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
|
this.previousListMode = 'view';
|
||||||
this.state = { dataSource: ds };
|
const ds = new ListView.DataSource({
|
||||||
}
|
rowHasChanged: (r1, r2) => { return r1 !== r2; }
|
||||||
|
});
|
||||||
componentWillMount() {
|
this.state = {
|
||||||
const newDataSource = this.state.dataSource.cloneWithRows(this.props.items);
|
dataSource: ds,
|
||||||
this.state = { dataSource: newDataSource };
|
items: [],
|
||||||
|
selectedItemIds: [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(newProps) {
|
componentWillReceiveProps(newProps) {
|
||||||
|
// When the items have changed, we just pass this to the data source. However,
|
||||||
|
// when the list mode change, we need to clone the items to make sure the whole
|
||||||
|
// list is updated (so that the checkbox can be added or removed).
|
||||||
|
|
||||||
|
let items = newProps.items;
|
||||||
|
|
||||||
|
if (newProps.listMode != this.previousListMode) {
|
||||||
|
items = newProps.items.slice();
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
items[i] = Object.assign({}, items[i]);
|
||||||
|
}
|
||||||
|
this.previousListMode = newProps.listMode;
|
||||||
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/38186114/react-native-redux-and-listview
|
// https://stackoverflow.com/questions/38186114/react-native-redux-and-listview
|
||||||
this.setState({ dataSource: this.state.dataSource.cloneWithRows(newProps.items) });
|
this.setState({
|
||||||
|
dataSource: this.state.dataSource.cloneWithRows(items),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
listView_itemClick = (itemId) => {
|
setListMode = (mode) => {
|
||||||
|
this.props.dispatch({
|
||||||
|
type: 'SET_LIST_MODE',
|
||||||
|
listMode: mode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
listView_itemPress = (itemId) => {}
|
||||||
|
|
||||||
|
listView_itemLongPress = (itemId) => {
|
||||||
|
this.setListMode('edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let renderRow = (rowData) => {
|
let renderRow = (item) => {
|
||||||
let onPress = () => {
|
let onPress = () => {
|
||||||
this.listView_itemClick(rowData.id);
|
this.listView_itemPress(item.id);
|
||||||
//this.props.onItemClick(rowData.id)
|
|
||||||
}
|
}
|
||||||
|
let onLongPress = () => {
|
||||||
|
this.listView_itemLongPress(item.id);
|
||||||
|
}
|
||||||
|
let editable = this.props.listMode == 'edit' ? ' [X] ' : '';
|
||||||
return (
|
return (
|
||||||
<TouchableHighlight onPress={onPress}>
|
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
|
||||||
<Text>{rowData.title}</Text>
|
<Text>{item.title}<Text>{editable}</Text></Text>
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ import { _ } from 'src/locale.js';
|
|||||||
|
|
||||||
class NoteListComponent extends ItemListComponent {
|
class NoteListComponent extends ItemListComponent {
|
||||||
|
|
||||||
listView_itemClick = (noteId) => {
|
listView_itemPress = (noteId) => {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'Navigation/NAVIGATE',
|
type: 'Navigation/NAVIGATE',
|
||||||
routeName: 'Note',
|
routeName: 'Note',
|
||||||
|
@@ -1,24 +1,28 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { View, Button, Picker } from 'react-native';
|
import { View, Button, Picker, Text } from 'react-native';
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Log } from 'src/log.js'
|
import { Log } from 'src/log.js'
|
||||||
import { FolderList } from 'src/components/folder-list.js'
|
import { FolderList } from 'src/components/folder-list.js'
|
||||||
|
|
||||||
class FoldersScreenComponent extends React.Component {
|
class FoldersScreenComponent extends React.Component {
|
||||||
|
|
||||||
static navigationOptions = {
|
static navigationOptions = (options) => {
|
||||||
title: 'Folders',
|
return { title: 'Folders' };
|
||||||
};
|
// const nav = options.navigation;
|
||||||
|
// Log.info('ici', nav);
|
||||||
|
// //return { title: "Folders: " + nav.state.params.listMode };
|
||||||
|
// return { title: <Text>Folders: {nav.state.params.listMode}</Text> };
|
||||||
|
}
|
||||||
|
|
||||||
createFolderButton_press = () => {
|
createFolderButton_press = () => {
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: 'Navigation/NAVIGATE',
|
type: 'Navigation/NAVIGATE',
|
||||||
routeName: 'Folder',
|
routeName: 'Folder',
|
||||||
|
folderId: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { navigate } = this.props.navigation;
|
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1}}>
|
<View style={{flex: 1}}>
|
||||||
<FolderList style={{flex: 1}}/>
|
<FolderList style={{flex: 1}}/>
|
||||||
@@ -31,7 +35,7 @@ class FoldersScreenComponent extends React.Component {
|
|||||||
const FoldersScreen = connect(
|
const FoldersScreen = connect(
|
||||||
(state) => {
|
(state) => {
|
||||||
return {
|
return {
|
||||||
folders: state.folders
|
folders: state.folders,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)(FoldersScreenComponent)
|
)(FoldersScreenComponent)
|
||||||
|
@@ -20,16 +20,11 @@ import { LoginScreen } from 'src/components/screens/login.js'
|
|||||||
import { Setting } from 'src/models/setting.js'
|
import { Setting } from 'src/models/setting.js'
|
||||||
|
|
||||||
let defaultState = {
|
let defaultState = {
|
||||||
defaultText: 'bla',
|
|
||||||
notes: [],
|
notes: [],
|
||||||
folders: [
|
folders: [],
|
||||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab01', title: "un" },
|
|
||||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab02', title: "deux" },
|
|
||||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab03', title: "trois" },
|
|
||||||
// { id: 'abcdabcdabcdabcdabcdabcdabcdab04', title: "quatre" },
|
|
||||||
],
|
|
||||||
selectedNoteId: null,
|
selectedNoteId: null,
|
||||||
selectedFolderId: null,
|
selectedFolderId: null,
|
||||||
|
listMode: 'view',
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer = (state = defaultState, action) => {
|
const reducer = (state = defaultState, action) => {
|
||||||
@@ -48,17 +43,20 @@ const reducer = (state = defaultState, action) => {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
action.params = { listMode: 'view' };
|
||||||
|
|
||||||
const nextStateNav = AppNavigator.router.getStateForAction(action, state.nav);
|
const nextStateNav = AppNavigator.router.getStateForAction(action, state.nav);
|
||||||
|
//Log.info('nextStateNavnextStateNavnextStateNavnextStateNavnextStateNav', nextStateNav);
|
||||||
newState = Object.assign({}, state);
|
newState = Object.assign({}, state);
|
||||||
if (nextStateNav) {
|
if (nextStateNav) {
|
||||||
newState.nav = nextStateNav;
|
newState.nav = nextStateNav;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.noteId) {
|
if ('noteId' in action) {
|
||||||
newState.selectedNoteId = action.noteId;
|
newState.selectedNoteId = action.noteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.folderId) {
|
if ('folderId' in action) {
|
||||||
newState.selectedFolderId = action.folderId;
|
newState.selectedFolderId = action.folderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +115,14 @@ const reducer = (state = defaultState, action) => {
|
|||||||
newState.folders = newFolders;
|
newState.folders = newFolders;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'SET_LIST_MODE':
|
||||||
|
|
||||||
|
newState = Object.assign({}, state);
|
||||||
|
newState.listMode = action.listMode;
|
||||||
|
newState.nav = Object.assign({}, state.nav);
|
||||||
|
//newState.nav
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
@@ -156,16 +162,6 @@ class AppComponent extends React.Component {
|
|||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
Log.warn('Cannot load folders', error);
|
Log.warn('Cannot load folders', error);
|
||||||
});
|
});
|
||||||
// }).then(() => {
|
|
||||||
// Log.info('Loading notes...');
|
|
||||||
// Note.previews().then((notes) => {
|
|
||||||
// this.props.dispatch({
|
|
||||||
// type: 'NOTES_UPDATE_ALL',
|
|
||||||
// notes: notes,
|
|
||||||
// });
|
|
||||||
// }).catch((error) => {
|
|
||||||
// Log.warn('Cannot load notes', error);
|
|
||||||
// });
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
Log.error('Cannot initialize database:', error);
|
Log.error('Cannot initialize database:', error);
|
||||||
});
|
});
|
||||||
@@ -181,7 +177,11 @@ class AppComponent extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultState.nav = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('Folders'));
|
defaultState.nav = AppNavigator.router.getStateForAction({
|
||||||
|
type: 'Navigation/NAVIGATE',
|
||||||
|
routeName: 'Folders',
|
||||||
|
params: {listMode: 'view'}
|
||||||
|
});
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
return {
|
return {
|
||||||
@@ -193,6 +193,8 @@ const App = connect(mapStateToProps)(AppComponent);
|
|||||||
|
|
||||||
class Root extends React.Component {
|
class Root extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
|
Log.info('TTTTTTTTTTTTTTTTTTT', defaultState.nav);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<App />
|
<App />
|
||||||
|
Reference in New Issue
Block a user