Skip to content

Commit

Permalink
trying with json files
Browse files Browse the repository at this point in the history
  • Loading branch information
ginniecodes committed Feb 22, 2017
1 parent 3e73229 commit eb80fad
Show file tree
Hide file tree
Showing 14 changed files with 549 additions and 6,771 deletions.
48 changes: 45 additions & 3 deletions javascripts/actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { SHOW, HIDE, ADD_BOOK, EDIT_BOOK, REMOVE_BOOK, INSTRUCTIONS } from './consts';
import initializeURL from '../lib/init';
const Epub = require('epub');
import config from './config';
import Promise from 'promise';
import config from './config';
import DB from '../lib/database';

export function addBook(name, author, data) {
return {
Expand Down Expand Up @@ -79,6 +80,7 @@ export function getImage(book, imgId) {
});
}

/*
function initEbook(bookPath, i) {
return new Promise((resolve, reject) => {
read(bookPath, i).then(book => {
Expand All @@ -92,8 +94,41 @@ function initEbook(bookPath, i) {
}).catch(reject);
}).catch(reject);
});
}*/

function initEbook(book, i) {
return new Promise((resolve, reject) => {
let metadata = createBook(book);
getImage(book, metadata.cover)
.then(img => {
metadata.cover = img;
metadata.chapters = book.flow;
resolve(metadata);
}).catch(reject);
});
}

export function initializeStore() {
return function(dispatch) {
const dir = (config.directory === 'default') ? process.env.HOME : config.directory;
dispatch(updateLoader(SHOW));

initializeURL(dir, config.extensions).then(books => {

Promise.all(books.map(initEbook)).then((reduxedBooks) => {

dispatch(updateStore('NEW', books));
dispatch(updateForm('', books.map((_, i) => i)));
dispatch(updateLoader(HIDE));
dispatch(changeWelcomeMessage(0));
return dispatch(showWelcome());

}).catch(e => { dispatch(showError('LOG', e)) });;
}).catch(e => { dispatch(showError('LOG', e)) });;
}
}

/*
export function initializeStore() {
return function (dispatch) {
const dir = (config.directory === 'default') ? process.env.HOME : config.directory;
Expand All @@ -109,7 +144,7 @@ export function initializeStore() {
}).catch(e => { dispatch(showError('LOG', e)) });
};
}

*/

export function setFormValues(values) {
return {
Expand Down Expand Up @@ -200,6 +235,13 @@ export function changeWelcomeMessage(i=0) {
return {
type: 'UPDATE_MESSAGE',
i,
message: INSTRUCTIONS[i]
data: INSTRUCTIONS[i]
}
}

export function removeInstrucions(key) {
return {
type: 'REMOVE_INSTRUCTION',
key
}
}
19 changes: 17 additions & 2 deletions javascripts/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as actionCreators from '../actions';
import Loader from './Loader';
import { hashHistory } from 'react-router';
import { InstructionOwl } from './Owl';
import { INSTRUCTIONS } from '../consts';

//Passing the state through components via props
function mapStateToProps(state) {
return {
Expand All @@ -29,6 +31,7 @@ class Layout extends Component {
super(props);
this.welcome = this.welcome.bind(this);
this.handleMessage = this.handleMessage.bind(this);
this.changeDir = this.changeDir.bind(this);
}

componentWillMount() {
Expand All @@ -37,9 +40,14 @@ class Layout extends Component {
return 0;
}

componentDidUpdate(prevProps) {
if(this.props.loader.welcome && this.props.loader.push && this.props.loader.push !== prevProps.loader.push) {
this.changeDir(this.props.loader.push);
}
}

handleMessage() {
if(this.props.loader.i === (INSTRUCTIONS.length - 1)) {
console.log('what happened here?');
this.props.updateMessage(0);
this.props.toggleWelcome();
} else {
Expand All @@ -51,7 +59,7 @@ class Layout extends Component {
return (
<div style={{ position: 'fixed', top: '0', left: '0', width: '100vw', height: '100vh', overflow: 'hidden', backgroundColor: 'rgba(10, 10, 10, 0.6)', zIndex: '500'}}>
<button onClick={this.props.toggleWelcome} style={{ position: 'absolute', bottom: '5%', left: '50%', width: '110px', marginLeft: '-55px', background: 'none', border: 'none', textTransform: 'uppercase', color: '#FEFEFE'}}>Ignorar</button>
<InstructionOwl className="open-eye"
<InstructionOwl className="open-eye" {...this.props.loader}
message={this.props.loader.message}
x={this.props.loader.x}
y={this.props.loader.y}
Expand All @@ -62,6 +70,13 @@ class Layout extends Component {
)
}

changeDir(push) {
console.log('funciono con ');
console.log(push);
if(push) {
this.context.router.push(push);
}
}

render() {
return (
Expand Down
10 changes: 5 additions & 5 deletions javascripts/components/Owl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export class ReadingOwl extends Component {

export class InstructionOwl extends Component {
render() {
const { message, styles, leftHand, rightHand } = this.props;
const { message, leftHand, rightHand, x, y } = this.props;
return (
<div onClick={this.props.handleMessage.bind(this)}>
<Owl className={`teaching ${this.props.className}`} styles={styles}>
<div className="arm arm-left" style={(leftHand || leftHand === 0) ? {transform: 'rotate('+leftHand +'deg)'} : {}}></div>
<div className="arm arm-right" style={(rightHand || rightHand === 0) ? {transform: `rotate(${rightHand}deg)`} : {}}></div>
<Owl className={`teaching ${this.props.className}`} styles={{top: y, left: x}}>
<div className="arm arm-left" style={(leftHand || leftHand === 0) ? {transform: `rotate(${leftHand}deg)`} : {}}></div>
<div className="arm arm-right" style={(rightHand || rightHand === 0) ? {transform: `rotate(-${rightHand}deg)`} : {}}></div>
</Owl>
<div id="message">
<div id="message" className={(this.props.messageBottom) ? 'bottom' : 'top' }>
{message}
</div>
</div>
Expand Down
Loading

0 comments on commit eb80fad

Please sign in to comment.