Skip to content

Commit

Permalink
Merge pull request #2 from mgyucht/swipe-to-mark-done
Browse files Browse the repository at this point in the history
Use Swipeout library to mark items done
  • Loading branch information
dmrd authored Oct 11, 2016
2 parents ec58140 + 3c6bda0 commit 6e582c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ npm-debug.log

node_modules/**/*
.exponent/**/*

org/org_parser.js
38 changes: 33 additions & 5 deletions OrgView.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SideMenu, List, ListItem } from 'react-native-elements'
import React, { Component } from 'react';

import Menu, { MenuOptions, MenuOption, MenuTrigger } from 'react-native-menu';
import Swipeout from 'react-native-swipeout';


import {
Expand Down Expand Up @@ -398,7 +399,7 @@ function Children({ node }) {
</View>);
}

function TodoRender({ root, searchStr }) {
function TodoRender({ root, searchStr, setState }) {
filtered = Org.search(root, searchStr);
sorted = Org.sort(filtered, 'pl', (a, b) => {
let as = a ? a.get('SCHEDULED') : null;
Expand Down Expand Up @@ -441,7 +442,7 @@ function TodoRender({ root, searchStr }) {
for (type of ['SCHEDULED', 'DEADLINE', 'CLOSED']) {
if (planning.has(type)) {
dates.push(
<Text key={type}> {type[0]}: {dateToRelativeText(planning.get(type))} </Text>
<Text key={type}> {type[0]}: {dateToRelativeText(planning.get(type))} </Text>
);
}
}
Expand All @@ -451,26 +452,53 @@ function TodoRender({ root, searchStr }) {
</View>);
}

// TODO(mgyucht): use a real state machine defined by #+TODO_HEADINGS if provided
let getSwipeConfiguration = (node) => {
if (getKeyword(node) === 'TODO') {
return {
buttonTitle: 'Done',
nextState: 'DONE',
};
} else {
return {
buttonTitle: 'Todo',
nextState: 'TODO',
}
}
};

return (
<ListView
dataSource={cloned}
renderRow={(node) => {
const swipeConfig = getSwipeConfiguration(node);
const swipeoutButtons = [
{
text: swipeConfig.buttonTitle,
backgroundColor: 'green',
underlayColor: 'rgba(0, 0, 0, 1, 0.6)',
onPress: () => {setState(node, swipeConfig.nextState)},
},
];
if (node == null) {
return <Text>No search result</Text>
}
return <View>
return <View>
<Swipeout right={swipeoutButtons} autoClose={true}>
<View style={[styles.row]}>
<Keyword keyword={getKeyword(node)}/>
<Text> {Org.getContent(node)} </Text>
</View>
{dates(node)}
</View>}}
</Swipeout>
</View>}}
renderSeparator={(sectionID, rowID) => (<View key={`${sectionID}-${rowID}`} style={styles.separator} />)}
/>
);
}

TodoRender = connect((state) => ({ root: state.doc }))(TodoRender);
TodoRender = connect((state) => ({ root: state.doc }),
(dispatch) => ({setState: (node, newState) => dispatch(setProperty(node, ['meta', 'keyword'], newState))}))(TodoRender);

/*** Edit node view ***/

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"@exponent/ex-navigation": "^1.5.29",
"@exponent/samples": "^1.0.2",
"@exponent/vector-icons": "^1.0.4",
"babel-preset-es2015": "^6.16.0",
"babel-preset-es2015-node": "^6.1.1",
"babel-preset-react": "^6.16.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"exponent": "^9.0.2",
"lodash": "^4.13.1",
Expand Down

1 comment on commit 6e582c6

@nikki93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yayyyyyyyyy. 👍 💯

Please sign in to comment.