From d5031a968022d4ef1a9f4fff79d55ae5dee628c6 Mon Sep 17 00:00:00 2001 From: ssomnoremac Date: Mon, 15 Feb 2016 17:19:19 -0500 Subject: [PATCH 1/5] issue25 - first attempt at storage an retrieval of html couch attachment --- android/app/components/Reader.js | 39 ++++++++++++++++++- .../react-native-couchbase-lite/index.js | 23 ++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/android/app/components/Reader.js b/android/app/components/Reader.js index 3239040..0a3f6ac 100644 --- a/android/app/components/Reader.js +++ b/android/app/components/Reader.js @@ -12,11 +12,46 @@ var { var WebView = require('./WebView'); +import {manager, ReactCBLite} from 'react-native-couchbase-lite' +ReactCBLite.init(5984, 'admin', 'password', (e) => {}); + + var Reader = React.createClass({ + getInitialState() { + return { + bookURL: "", + } + }, + componentDidMount() { + var database = new manager('http://admin:password@localhost:5984/', 'books'); + + //what I did to try to create the attachment + + // var remoteBookURL = "https://rawgit.com/InfiniteLibraryLibrary/" + this.props.book.title + "/master/book.xhtml" + // database.createDatabase() + // fetch(remoteBookURL) + // .then((res) => { + // return res.blob(); + // }) + // .then((blob) => { + // database.createHTMLAttachment(this.props.book._id, blob); + // }); + + + // what I did to try to display the attachment + + database.createDatabase() + .then((res) => { + return database.getDocument(this.props.book._id) + }) + .then((res) => { + var localURI = res._attachments["book.xhtml"].data; + this.setState({bookURL: localURI}) + }) + }, render() { - var bookURL = "https://rawgit.com/InfiniteLibraryLibrary/" + this.props.book.title + "/master/book.xhtml"; return ( - + ); }, }); diff --git a/android/app/vendor/react-native-couchbase-lite/index.js b/android/app/vendor/react-native-couchbase-lite/index.js index 84274e7..92c5e04 100644 --- a/android/app/vendor/react-native-couchbase-lite/index.js +++ b/android/app/vendor/react-native-couchbase-lite/index.js @@ -173,13 +173,34 @@ manager.prototype = { settings.body = "."; } } + return fetch(url, settings).then((res) => { + if (res.status == 401) { + console.log(res); + } + return res.json(); + }).catch((err) => { throw err; }); + }, + + createHTMLAttachment: function(docName, blob) { + var settings = { + method: "PUT", + headers: { + 'Accept': 'text/html', + 'Content-Type': 'text/html', + 'If-Match': '*', + 'Authorization': this.authHeader + }, + body: blob + }; + var url = this.databaseUrl + this.databaseName + "/" + docName + "/book.xhtml" return fetch(url, settings).then((res) => { if (res.status == 401) { console.log(res); } + console.log(res) return res.json(); }).catch((err) => { throw err; }); - } + }, }; module.exports = {manager, ReactCBLite}; \ No newline at end of file From 710cba9335a4689625b15e05ad2ce62fca7f1b41 Mon Sep 17 00:00:00 2001 From: ssomnoremac Date: Tue, 16 Feb 2016 17:13:15 -0500 Subject: [PATCH 2/5] issue25 - get all the databases in place for mybooks --- android/app/components/Catalog.js | 10 ++--- android/app/components/Details.js | 44 +++++++++++++++---- android/app/components/Login.js | 16 +++++-- android/app/components/MyBooks.js | 12 ++--- android/app/components/Reader.js | 23 ++-------- .../react-native-couchbase-lite/index.js | 13 +++--- 6 files changed, 67 insertions(+), 51 deletions(-) diff --git a/android/app/components/Catalog.js b/android/app/components/Catalog.js index f32333c..8c43f91 100644 --- a/android/app/components/Catalog.js +++ b/android/app/components/Catalog.js @@ -32,13 +32,13 @@ var Catalog = React.createClass({ }, componentDidMount() { var remoteURL = 'https://infinitelibrary:mitmedialab@infinitelibrary.cloudant.com/gitburg' - var database = new manager('http://admin:password@localhost:5984/', 'demoapp'); - database.createDatabase() + var catalogDB = new manager('http://admin:password@localhost:5984/', 'catalog'); + catalogDB.createDatabase() .then((res) => { - database.replicate(remoteURL, 'demoapp') + catalogDB.replicate(remoteURL, 'catalog') }) .then((res) => { - return database.getDesignDocument('_all_docs?include_docs=true&attachments=true') + return catalogDB.getDesignDocument('_all_docs?include_docs=true&attachments=true') }) .then((res) => { this.setState({ @@ -46,7 +46,7 @@ var Catalog = React.createClass({ }); console.log(res.rows) }) - .catch((ex) => {file:///android_asset/ + .catch((ex) => { console.log(ex) }) }, diff --git a/android/app/components/Details.js b/android/app/components/Details.js index 6859253..7b1dd86 100644 --- a/android/app/components/Details.js +++ b/android/app/components/Details.js @@ -19,14 +19,40 @@ var { MKColor, } = MK; +import {manager, ReactCBLite} from 'react-native-couchbase-lite' +ReactCBLite.init(5984, 'admin', 'password', (e) => {}); + +// booksDB +var booksDB = new manager('http://admin:password@localhost:5984/', 'books'); +booksDB.createDatabase(); +// myBooksDB +var usersDB = new manager('http://admin:password@localhost:5984/', 'users'); +usersDB.createDatabase(); +// sessionDB +var currentUser = {} +var sessionDB = new manager('http://admin:password@localhost:5984/', 'session'); +sessionDB.createDatabase(); +sessionDB.getDocument('currentSession').then((res) => { currentUser = user; }); + var Details = React.createClass({ - readBook(book) { - // fix for iOS/Android dismiss keyboard needs to be added - this.props.navigator.push({ - title: book.title, - name: 'reader', - book: book, - }); + downloadBook(book) { + var remoteBookURL = "https://rawgit.com/InfiniteLibraryLibrary/" + book.title + "/master/book.xhtml" + fetch(remoteBookURL) // should be (book.url) + .then((res) => { + return res.text() + }) + .then((htmlText) => { + booksDB.createAttachment(book._id, htmlText, 'book.xhtml', 'text/html') + }) + .then((res) => { + currentUser.downloaded.push(book._id); + }) + .then((res) => { + this.props.navigator.push({ name: 'mybooks' }); + }) + .catch((ex) => { + console.log(ex) + }); }, render() { var TouchableElement = TouchableHighlight; @@ -50,10 +76,10 @@ var Details = React.createClass({ {this.readBook(book);}} > + onPress={() => {this.downloadBook(book);}} > - READ + DOWNLOAD diff --git a/android/app/components/Login.js b/android/app/components/Login.js index 9bd60aa..b362b32 100644 --- a/android/app/components/Login.js +++ b/android/app/components/Login.js @@ -68,14 +68,22 @@ var Login = React.createClass({ // if the input button is pressed addUser() { - // update session - this.setState({session: {"user": { "name": this.state.text } }}); // create user var date = new Date var dateString = date.toISOString() - var userID = this.state.text + '-' + dateString - this.userDB.createDocument(this.state.session.user, userID); + var userID = this.state.text + '-' + dateString // update session + this.setState({ + session: { + user: { + name: this.state.text, + _id: userID, + downloaded: [], + } + } + }); + this.userDB.createDocument(this.state.session.user, userID); + this.sessionDB.createDocument(this.state.session, "currentSession"); // move on this.props.navigator.push({ diff --git a/android/app/components/MyBooks.js b/android/app/components/MyBooks.js index 25c5d2c..8d36c26 100644 --- a/android/app/components/MyBooks.js +++ b/android/app/components/MyBooks.js @@ -30,14 +30,10 @@ var MyBooks = React.createClass({ }; }, componentDidMount() { - var remoteURL = 'https://infinitelibrary.cloudant.com/gitburg' - var database = new manager('http://admin:password@localhost:5984/', 'demoapp'); - database.createDatabase() - .then((res) => { - database.replicate(remoteURL, 'demoapp') - }) + var myBooksDB = new manager('http://admin:password@localhost:5984/', 'mybooks'); + myBooksDB.createDatabase() .then((res) => { - return database.getDesignDocument('_all_docs?include_docs=true&attachments=true') + return myBooksDB.getDesignDocument('_all_docs?include_docs=true&attachments=true') }) .then((res) => { this.setState({ @@ -45,7 +41,7 @@ var MyBooks = React.createClass({ }); console.log(res.rows) }) - .catch((ex) => {file:///android_asset/ + .catch((ex) => { console.log(ex) }) }, diff --git a/android/app/components/Reader.js b/android/app/components/Reader.js index 0a3f6ac..42ff7f7 100644 --- a/android/app/components/Reader.js +++ b/android/app/components/Reader.js @@ -23,26 +23,11 @@ var Reader = React.createClass({ } }, componentDidMount() { - var database = new manager('http://admin:password@localhost:5984/', 'books'); - - //what I did to try to create the attachment - - // var remoteBookURL = "https://rawgit.com/InfiniteLibraryLibrary/" + this.props.book.title + "/master/book.xhtml" - // database.createDatabase() - // fetch(remoteBookURL) - // .then((res) => { - // return res.blob(); - // }) - // .then((blob) => { - // database.createHTMLAttachment(this.props.book._id, blob); - // }); - - - // what I did to try to display the attachment - - database.createDatabase() + // booksDB + var booksDB = new manager('http://admin:password@localhost:5984/', 'books'); + booksDB.createDatabase() .then((res) => { - return database.getDocument(this.props.book._id) + return booksDB.getDocument(this.props.book._id) }) .then((res) => { var localURI = res._attachments["book.xhtml"].data; diff --git a/android/app/vendor/react-native-couchbase-lite/index.js b/android/app/vendor/react-native-couchbase-lite/index.js index 92c5e04..1b4b996 100644 --- a/android/app/vendor/react-native-couchbase-lite/index.js +++ b/android/app/vendor/react-native-couchbase-lite/index.js @@ -181,18 +181,18 @@ manager.prototype = { }).catch((err) => { throw err; }); }, - createHTMLAttachment: function(docName, blob) { + createAttachment: function(docName, data, attachmentName, contentType) { var settings = { method: "PUT", headers: { - 'Accept': 'text/html', - 'Content-Type': 'text/html', + 'Accept': contentType, + 'Content-Type': contentType, 'If-Match': '*', 'Authorization': this.authHeader }, - body: blob + body: data }; - var url = this.databaseUrl + this.databaseName + "/" + docName + "/book.xhtml" + var url = this.databaseUrl + this.databaseName + "/" + docName + "/" + attachmentName return fetch(url, settings).then((res) => { if (res.status == 401) { console.log(res); @@ -200,7 +200,8 @@ manager.prototype = { console.log(res) return res.json(); }).catch((err) => { throw err; }); - }, + } + }; module.exports = {manager, ReactCBLite}; \ No newline at end of file From 6c822222d5466f8a1a2187a081e233dda8afc1f4 Mon Sep 17 00:00:00 2001 From: ssomnoremac Date: Wed, 17 Feb 2016 15:42:11 -0500 Subject: [PATCH 3/5] issue25 - registation and mybooks sync with localDB --- android/app/components/Details.js | 32 +++++++---- android/app/components/Login.js | 91 ++++++++++++++++--------------- android/app/components/MyBooks.js | 29 ++++++++-- index.android.js | 34 ++++++++++-- 4 files changed, 120 insertions(+), 66 deletions(-) diff --git a/android/app/components/Details.js b/android/app/components/Details.js index 7b1dd86..d47630c 100644 --- a/android/app/components/Details.js +++ b/android/app/components/Details.js @@ -22,19 +22,28 @@ var { import {manager, ReactCBLite} from 'react-native-couchbase-lite' ReactCBLite.init(5984, 'admin', 'password', (e) => {}); -// booksDB var booksDB = new manager('http://admin:password@localhost:5984/', 'books'); booksDB.createDatabase(); -// myBooksDB -var usersDB = new manager('http://admin:password@localhost:5984/', 'users'); +var usersDB = new manager('http://admin:password@localhost:5984/', 'users') usersDB.createDatabase(); -// sessionDB -var currentUser = {} var sessionDB = new manager('http://admin:password@localhost:5984/', 'session'); -sessionDB.createDatabase(); -sessionDB.getDocument('currentSession').then((res) => { currentUser = user; }); + var Details = React.createClass({ + getInitialState() { + return { + user : {} + } + }, + componentDidMount() { + sessionDB.createDatabase() + .then((res) => { + return sessionDB.getDocument("current") + }) + .then((res) => { + this.setState({user, res}); + }); + }, downloadBook(book) { var remoteBookURL = "https://rawgit.com/InfiniteLibraryLibrary/" + book.title + "/master/book.xhtml" fetch(remoteBookURL) // should be (book.url) @@ -42,10 +51,13 @@ var Details = React.createClass({ return res.text() }) .then((htmlText) => { - booksDB.createAttachment(book._id, htmlText, 'book.xhtml', 'text/html') + // save book to booksDB + return booksDB.createAttachment(book._id, htmlText, 'book.xhtml', 'text/html') }) .then((res) => { - currentUser.downloaded.push(book._id); + // save book to user + this.state.user.downloaded.push(book._id); + updateDocument(this.state.user, user.rev) }) .then((res) => { this.props.navigator.push({ name: 'mybooks' }); @@ -68,7 +80,7 @@ var Details = React.createClass({ * omit a property or set it to undefined if it's inside a shape, * even if it isn't required */} - {this.props.book.title} + {book.title} diff --git a/android/app/components/Login.js b/android/app/components/Login.js index b362b32..6d2dc1f 100644 --- a/android/app/components/Login.js +++ b/android/app/components/Login.js @@ -23,6 +23,9 @@ var { import {manager, ReactCBLite} from 'react-native-couchbase-lite' ReactCBLite.init(5984, 'admin', 'password', (e) => {}); +var sessionDB = new manager('http://admin:password@localhost:5984/', 'session'); +var userDB = new manager('http://admin:password@localhost:5984/', 'users'); + var Login = React.createClass({ getInitialState() { return { @@ -30,27 +33,15 @@ var Login = React.createClass({ rowHasChanged: (row1, row2) => row1 !== row2, }), text: "", - session: { - user: { - name: "", - } - }, }; }, componentWillMount() { - this.remoteURL = 'https://infinitelibrary:mitmedialab@infinitelibrary.cloudant.com/gitburg' - this.userDB = new manager('http://admin:password@localhost:5984/', 'users'); - this.sessionDB = new manager('http://admin:password@localhost:5984/', 'session'); - - // get the full list of users - this.userDB.createDatabase() - /* - .then((res) => { - this.userDB.replicate('users', this.remoteURL) - }) */ + // lets get our users + + userDB.createDatabase() .then((res) => { - return this.userDB.getDesignDocument('_all_docs?include_docs=true') + return userDB.getDesignDocument('_all_docs?include_docs=true') }) .then((res) => { this.setState({ @@ -61,47 +52,59 @@ var Login = React.createClass({ .catch((ex) => { console.log(ex) }); - - this.sessionDB.createDatabase() }, // if the input button is pressed addUser() { + // create user + var date = new Date var dateString = date.toISOString() var userID = this.state.text + '-' + dateString - // update session - this.setState({ - session: { - user: { - name: this.state.text, - _id: userID, - downloaded: [], - } - } - }); - this.userDB.createDocument(this.state.session.user, userID); - - this.sessionDB.createDocument(this.state.session, "currentSession"); - // move on - this.props.navigator.push({ - name: 'catalog', - }); + var user = { + name: this.state.text, + _id: userID, + downloaded: [], + } + + // create the user session + + sessionDB.createDatabase + .then((res) => { + sessionDB.createDocument(user, "current") + }); + + // save the user + + userDB.createDatabase + .then((res) => { + return userDB.createDocument(user, userID) + }) + .then((res) => { + this.props.navigator.push({ + name: 'catalog', + }); + }); + }, // if a user is pressed selectUser(user) { - // object state user object - this.setState({session: {"user": user}}); - // update session - this.sessionDB.createDocument(this.state.session, "currentSession") - // move on - this.props.navigator.push({ - name: 'catalog', - }); + + // create the user session + + sessionDB.createDatabase + .then((res) => { + return sessionDB.createDocument(user, "current") + }) + .then((res) => { + this.props.navigator.push({ + name: 'catalog', + }); + }); }, @@ -114,7 +117,7 @@ var Login = React.createClass({ } var user = data.doc return ( - this.selectUser(user)} user={user} diff --git a/android/app/components/MyBooks.js b/android/app/components/MyBooks.js index 8d36c26..169118c 100644 --- a/android/app/components/MyBooks.js +++ b/android/app/components/MyBooks.js @@ -20,6 +20,8 @@ var { import {manager, ReactCBLite} from 'react-native-couchbase-lite' ReactCBLite.init(5984, 'admin', 'password', (e) => {}); +var sessionDB = new manager('http://admin:password@localhost:5984/', 'session'); +var catalogDB = new manager('http://admin:password@localhost:5984/', 'catalog'); var MyBooks = React.createClass({ getInitialState() { @@ -27,19 +29,34 @@ var MyBooks = React.createClass({ dataSource: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, }), + user: {}, }; }, componentDidMount() { - var myBooksDB = new manager('http://admin:password@localhost:5984/', 'mybooks'); - myBooksDB.createDatabase() - .then((res) => { - return myBooksDB.getDesignDocument('_all_docs?include_docs=true&attachments=true') + var books = []; + sessionDB.createDatabase() + .then((res) => { + return sessionDB.getDocument("current") + }) + .then((res) => { + this.setState({user, res}); + }); + then((res) => { + return catalogDB.createDatabase() + }) + .then((res) => { + return catalogDB.getDesignDocument('_all_docs?include_docs=true&attachments=true') }) .then((res) => { + for (let id of this.state.user.downloads) { + catalogDB.getDocument(id) + .then((res) => { + books.push(res) + }); + } this.setState({ - dataSource: this.state.dataSource.cloneWithRows(res.rows) + dataSource: this.state.dataSource.cloneWithRows(books) }); - console.log(res.rows) }) .catch((ex) => { console.log(ex) diff --git a/index.android.js b/index.android.js index d154de1..15e0fc5 100644 --- a/index.android.js +++ b/index.android.js @@ -20,7 +20,28 @@ var { View, } = React; -var _navigator; +var _navigator + +import {manager, ReactCBLite} from 'react-native-couchbase-lite' +ReactCBLite.init(5984, 'admin', 'password', (e) => {}); + +var remoteURL = 'https://infinitelibrary:mitmedialab@infinitelibrary.cloudant.com/' + +// local database connections +var catalogDB = new manager('http://admin:password@localhost:5984/', 'catalog'); +var userDB = new manager('http://admin:password@localhost:5984/', 'users'); + +// replicate down the catalog +catalogDB.createDatabase() + .then((res) => { + catalogDB.replicate(remoteURL + "gitburg", "catalog") + }); + +// replicate up the users +userDB.createDatabase() + .then((res) => { + userDB.replicate('users', remoteURL + "users") + }); StatusBarAndroid.setHexColor('#B71C1C'); @@ -34,21 +55,22 @@ BackAndroid.addEventListener('hardwareBackPress', () => { var RouteMapper = function(route, navigationOperations, onComponentRef) { _navigator = navigationOperations; + if (route.name === 'catalog') { return ( - + ); } else if (route.name === 'mybooks') { return ( - + ); } else if (route.name === 'login') { return ( - + ); } else if (route.name === 'details') { return ( - + Date: Wed, 17 Feb 2016 17:16:41 -0500 Subject: [PATCH 4/5] issue26 - used modified files from counter reduc example --- android/app/actions/actionTypes.js | 2 + android/app/actions/sessionActions.js | 13 ++ android/app/build.gradle | 2 +- android/app/containers/InfiniteApp.js | 111 +++++++++++++++ android/app/containers/app.js | 21 +++ android/app/reducers/index.js | 5 + android/app/reducers/session.js | 22 +++ android/app/src/main/AndroidManifest.xml | 2 +- .../MainActivity.java | 4 +- android/settings.gradle | 2 +- index.android.js | 130 +----------------- index.androidOLD.js | 130 ++++++++++++++++++ package.json | 5 +- 13 files changed, 316 insertions(+), 133 deletions(-) create mode 100644 android/app/actions/actionTypes.js create mode 100644 android/app/actions/sessionActions.js create mode 100644 android/app/containers/InfiniteApp.js create mode 100644 android/app/containers/app.js create mode 100644 android/app/reducers/index.js create mode 100644 android/app/reducers/session.js rename android/app/src/main/java/com/{reactnativecouchbaseliteexample => infinitelibrary}/MainActivity.java (96%) create mode 100644 index.androidOLD.js diff --git a/android/app/actions/actionTypes.js b/android/app/actions/actionTypes.js new file mode 100644 index 0000000..e7b86b2 --- /dev/null +++ b/android/app/actions/actionTypes.js @@ -0,0 +1,2 @@ +export const LOGIN = 'LOGIN'; +export const LOGOUT = 'LOGOUT'; \ No newline at end of file diff --git a/android/app/actions/sessionActions.js b/android/app/actions/sessionActions.js new file mode 100644 index 0000000..bcfb0d5 --- /dev/null +++ b/android/app/actions/sessionActions.js @@ -0,0 +1,13 @@ +import * as types from './actionTypes'; + +export function increment() { + return { + type: types.INCREMENT + }; +} + +export function decrement() { + return { + type: types.DECREMENT + }; +} \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 51b2a10..4bd065a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -54,7 +54,7 @@ android { buildToolsVersion "23.0.1" defaultConfig { - applicationId "com.reactnativecouchbaseliteexample" + applicationId "com.infinitereader" minSdkVersion 16 targetSdkVersion 22 versionCode 1 diff --git a/android/app/containers/InfiniteApp.js b/android/app/containers/InfiniteApp.js new file mode 100644 index 0000000..74199da --- /dev/null +++ b/android/app/containers/InfiniteApp.js @@ -0,0 +1,111 @@ +'use strict'; + +import React, { Component } from 'react-native'; +import {bindActionCreators} from 'redux'; +import * as sessionActions from '../actions/sessionActions'; +import { connect } from 'react-redux'; + +var React = require('react-native'); +var Catalog = require('../components/Catalog'); +var Details = require('../components/Details'); +var Reader = require('../components/Reader'); +var MyBooks = require('../components/MyBooks'); +var Login = require('../components/Login'); + +var StatusBarAndroid = require('react-native-android-statusbar'); +var { + BackAndroid, + Navigator, + StyleSheet, + ToolbarAndroid, + View, +} = React; + +var RouteMapper = function(route, navigationOperations, onComponentRef) { + _navigator = navigationOperations; + + if (route.name === 'catalog') { + return ( + + ); + } else if (route.name === 'mybooks') { + return ( + + ); + } else if (route.name === 'login') { + return ( + + ); + } else if (route.name === 'details') { + return ( + + +
+ + ); + } else if (route.name === 'reader') { + return ( + + + + + ); + } +}; + +class InfiniteApp extends Component { + constructor(props) { + super(props); + } + + render() { + const { state, actions } = this.props; + var initialRoute = {name: 'login'}; + return ( + Navigator.SceneConfigs.FadeAndroid} + renderScene={RouteMapper} + counter={state.count} + {...actions} /> + ); + } +} + +var styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'white', + }, + toolbar: { + backgroundColor: '#a9a9a9', + height: 56, + }, +}); + +export default connect(state => ({ + state: state.session + }), + (dispatch) => ({ + actions: bindActionCreators(sessionActions, dispatch) + }) +)(InfiniteApp); \ No newline at end of file diff --git a/android/app/containers/app.js b/android/app/containers/app.js new file mode 100644 index 0000000..d83ee69 --- /dev/null +++ b/android/app/containers/app.js @@ -0,0 +1,21 @@ +import React, { Component } from 'react-native'; +import { createStore, applyMiddleware, combineReducers } from 'redux'; +import { Provider } from 'react-redux'; +import thunk from 'redux-thunk'; + +import * as reducers from '../reducers'; +import InfiniteApp from './infiniteApp'; + +const createStoreWithMiddleware = applyMiddleware(thunk)(createStore); +const reducer = combineReducers(reducers); +const store = createStoreWithMiddleware(reducer); + +export default class App extends Component { + render() { + return ( + + + + ); + } +} \ No newline at end of file diff --git a/android/app/reducers/index.js b/android/app/reducers/index.js new file mode 100644 index 0000000..e020c91 --- /dev/null +++ b/android/app/reducers/index.js @@ -0,0 +1,5 @@ +import session from './session'; + +export { + session +}; \ No newline at end of file diff --git a/android/app/reducers/session.js b/android/app/reducers/session.js new file mode 100644 index 0000000..a2e3aef --- /dev/null +++ b/android/app/reducers/session.js @@ -0,0 +1,22 @@ +import * as types from '../actions/actionTypes'; + +const initialState = { + count: 0 +}; + +export default function session(state = initialState, action = {}) { + switch (action.type) { + case types.LOGIN: + return { + ...state, + session: true + }; + case types.LOGOUT: + return { + ...state, + session: false + }; + default: + return state; + } +} \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b55355f..5d74549 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.infinitereader"> diff --git a/android/app/src/main/java/com/reactnativecouchbaseliteexample/MainActivity.java b/android/app/src/main/java/com/infinitelibrary/MainActivity.java similarity index 96% rename from android/app/src/main/java/com/reactnativecouchbaseliteexample/MainActivity.java rename to android/app/src/main/java/com/infinitelibrary/MainActivity.java index 389ca6a..e28b769 100644 --- a/android/app/src/main/java/com/reactnativecouchbaseliteexample/MainActivity.java +++ b/android/app/src/main/java/com/infinitelibrary/MainActivity.java @@ -1,4 +1,4 @@ -package com.reactnativecouchbaseliteexample; +package com.infinitereader; import android.app.Activity; import android.os.Bundle; @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { .setInitialLifecycleState(LifecycleState.RESUMED) .build(); - mReactRootView.startReactApplication(mReactInstanceManager, "ReactNativeCouchbaseLiteExample", null); + mReactRootView.startReactApplication(mReactInstanceManager, "InifiteReader", null); setContentView(mReactRootView); } diff --git a/android/settings.gradle b/android/settings.gradle index 59a9aa9..c346767 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,4 @@ -rootProject.name = 'ReactNativeCouchbaseLiteExample' +rootProject.name = 'InfiniteReader' include ':app' include ':react-native-couchbase-lite' diff --git a/index.android.js b/index.android.js index 15e0fc5..b896993 100644 --- a/index.android.js +++ b/index.android.js @@ -1,130 +1,6 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - */ 'use strict'; -var React = require('react-native'); -var Catalog = require('./android/app/components/Catalog'); -var Details = require('./android/app/components/Details'); -var Reader = require('./android/app/components/Reader'); -var MyBooks = require('./android/app/components/MyBooks'); -var Login = require('./android/app/components/Login'); -var StatusBarAndroid = require('react-native-android-statusbar'); -var { - AppRegistry, - BackAndroid, - Navigator, - StyleSheet, - ToolbarAndroid, - View, -} = React; +import React, { AppRegistry } from 'react-native'; +import App from './android/app/containers/app'; -var _navigator - -import {manager, ReactCBLite} from 'react-native-couchbase-lite' -ReactCBLite.init(5984, 'admin', 'password', (e) => {}); - -var remoteURL = 'https://infinitelibrary:mitmedialab@infinitelibrary.cloudant.com/' - -// local database connections -var catalogDB = new manager('http://admin:password@localhost:5984/', 'catalog'); -var userDB = new manager('http://admin:password@localhost:5984/', 'users'); - -// replicate down the catalog -catalogDB.createDatabase() - .then((res) => { - catalogDB.replicate(remoteURL + "gitburg", "catalog") - }); - -// replicate up the users -userDB.createDatabase() - .then((res) => { - userDB.replicate('users', remoteURL + "users") - }); - -StatusBarAndroid.setHexColor('#B71C1C'); - -BackAndroid.addEventListener('hardwareBackPress', () => { - if (_navigator && _navigator.getCurrentRoutes().length > 1) { - _navigator.pop(); - return true; - } - return false; -}); - -var RouteMapper = function(route, navigationOperations, onComponentRef) { - _navigator = navigationOperations; - - if (route.name === 'catalog') { - return ( - - ); - } else if (route.name === 'mybooks') { - return ( - - ); - } else if (route.name === 'login') { - return ( - - ); - } else if (route.name === 'details') { - return ( - - -
- - ); - } else if (route.name === 'reader') { - return ( - - - - - ); - } -}; - -var ReactNativeCouchbaseLiteExample = React.createClass({ - render () { - var initialRoute = {name: 'login'}; - return ( - Navigator.SceneConfigs.FadeAndroid} - renderScene={RouteMapper} /> - ); - } -}); - -var styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: 'white', - }, - toolbar: { - backgroundColor: '#a9a9a9', - height: 56, - }, -}); - -AppRegistry.registerComponent('ReactNativeCouchbaseLiteExample', () => ReactNativeCouchbaseLiteExample); +AppRegistry.registerComponent('InfiniteReader', () => App); \ No newline at end of file diff --git a/index.androidOLD.js b/index.androidOLD.js new file mode 100644 index 0000000..15e0fc5 --- /dev/null +++ b/index.androidOLD.js @@ -0,0 +1,130 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + */ +'use strict'; + +var React = require('react-native'); +var Catalog = require('./android/app/components/Catalog'); +var Details = require('./android/app/components/Details'); +var Reader = require('./android/app/components/Reader'); +var MyBooks = require('./android/app/components/MyBooks'); +var Login = require('./android/app/components/Login'); +var StatusBarAndroid = require('react-native-android-statusbar'); +var { + AppRegistry, + BackAndroid, + Navigator, + StyleSheet, + ToolbarAndroid, + View, +} = React; + +var _navigator + +import {manager, ReactCBLite} from 'react-native-couchbase-lite' +ReactCBLite.init(5984, 'admin', 'password', (e) => {}); + +var remoteURL = 'https://infinitelibrary:mitmedialab@infinitelibrary.cloudant.com/' + +// local database connections +var catalogDB = new manager('http://admin:password@localhost:5984/', 'catalog'); +var userDB = new manager('http://admin:password@localhost:5984/', 'users'); + +// replicate down the catalog +catalogDB.createDatabase() + .then((res) => { + catalogDB.replicate(remoteURL + "gitburg", "catalog") + }); + +// replicate up the users +userDB.createDatabase() + .then((res) => { + userDB.replicate('users', remoteURL + "users") + }); + +StatusBarAndroid.setHexColor('#B71C1C'); + +BackAndroid.addEventListener('hardwareBackPress', () => { + if (_navigator && _navigator.getCurrentRoutes().length > 1) { + _navigator.pop(); + return true; + } + return false; +}); + +var RouteMapper = function(route, navigationOperations, onComponentRef) { + _navigator = navigationOperations; + + if (route.name === 'catalog') { + return ( + + ); + } else if (route.name === 'mybooks') { + return ( + + ); + } else if (route.name === 'login') { + return ( + + ); + } else if (route.name === 'details') { + return ( + + +
+ + ); + } else if (route.name === 'reader') { + return ( + + + + + ); + } +}; + +var ReactNativeCouchbaseLiteExample = React.createClass({ + render () { + var initialRoute = {name: 'login'}; + return ( + Navigator.SceneConfigs.FadeAndroid} + renderScene={RouteMapper} /> + ); + } +}); + +var styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'white', + }, + toolbar: { + backgroundColor: '#a9a9a9', + height: 56, + }, +}); + +AppRegistry.registerComponent('ReactNativeCouchbaseLiteExample', () => ReactNativeCouchbaseLiteExample); diff --git a/package.json b/package.json index b0debe7..c807cd5 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "react-native-android-statusbar": "^0.1.2", "react-native-fs": "^1.1.0", "react-native-material-design": "^0.3.1", - "react-native-material-kit": "^0.2.5" + "react-native-material-kit": "^0.2.5", + "react-redux": "^4.4.0", + "redux": "^3.3.1", + "redux-thunk": "^1.0.3" } } From 07fcc28e709c3b3a01178f78e04262def784fa42 Mon Sep 17 00:00:00 2001 From: ssomnoremac Date: Fri, 19 Feb 2016 16:54:25 -0500 Subject: [PATCH 5/5] issue26 - fix action names --- android/app/actions/sessionActions.js | 8 ++++---- android/app/containers/InfiniteApp.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/android/app/actions/sessionActions.js b/android/app/actions/sessionActions.js index bcfb0d5..a8a3135 100644 --- a/android/app/actions/sessionActions.js +++ b/android/app/actions/sessionActions.js @@ -1,13 +1,13 @@ import * as types from './actionTypes'; -export function increment() { +export function login() { return { - type: types.INCREMENT + type: types.LOGIN }; } -export function decrement() { +export function logout() { return { - type: types.DECREMENT + type: types.LOGOUT }; } \ No newline at end of file diff --git a/android/app/containers/InfiniteApp.js b/android/app/containers/InfiniteApp.js index 74199da..f6c5b85 100644 --- a/android/app/containers/InfiniteApp.js +++ b/android/app/containers/InfiniteApp.js @@ -1,7 +1,7 @@ 'use strict'; import React, { Component } from 'react-native'; -import {bindActionCreators} from 'redux'; +import { bindActionCreators } from 'redux'; import * as sessionActions from '../actions/sessionActions'; import { connect } from 'react-redux';