Skip to content

Commit

Permalink
Verses showing
Browse files Browse the repository at this point in the history
  • Loading branch information
rossoskull committed Oct 11, 2018
1 parent 635faf6 commit 6881002
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"main.css": "static/css/main.5ebcd27d.css",
"main.css.map": "static/css/main.5ebcd27d.css.map",
"main.js": "static/js/main.a390ee5c.js",
"main.js.map": "static/js/main.a390ee5c.js.map"
"main.js": "static/js/main.46f245bc.js",
"main.js.map": "static/js/main.46f245bc.js.map"
}
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/gita/manifest.json"><link rel="shortcut icon" href="/gita/favicon.ico"><title>Bhagavada Gita - Rossoskull</title><link href="/gita/static/css/main.5ebcd27d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root" onload='console.log("Helo helo")'></div><script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script><script src="script.js"></script><script type="text/javascript" src="/gita/static/js/main.a390ee5c.js"></script></body></html>
<!doctype html><html lang="en"><head><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/gita/manifest.json"><link rel="shortcut icon" href="/gita/favicon.ico"><title>Bhagavada Gita - Rossoskull</title><link href="/gita/static/css/main.5ebcd27d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root" onload='console.log("Helo helo")'></div><script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script><script src="script.js"></script><script type="text/javascript" src="/gita/static/js/main.46f245bc.js"></script></body></html>
2 changes: 1 addition & 1 deletion docs/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/static/js/main.46f245bc.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/static/js/main.46f245bc.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/static/js/main.a390ee5c.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/static/js/main.a390ee5c.js.map

This file was deleted.

40 changes: 38 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"homepage": "http://rossoskull.me/gita",
"dependencies": {
"@material-ui/core": "^3.2.0",
"@material-ui/icons": "^3.0.1",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
Expand Down
16 changes: 5 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,20 @@ class App extends Component {

// Get chapters And verses
getChapters = (token) => {
const url = `https://bhagavadgita.io/api/v1/chapters?access_token=${token}`;
const baseUrl = 'https://bhagavadgita.io/api/v1/';
let url = `${baseUrl}chapters?access_token=${token}`;
const options = {
'mode': 'cors',
}

// Fetch Chapters
fetch(url, options)
.then((res) => {
if(res.ok) {
res.json().then((data) => {
this.setState({
chapters: data,
});
const script = document.createElement('script');
script.innerHTML = `
$('.modal').modal();
`;
document.body.appendChild(script);
return;
});
} else {
Expand All @@ -72,10 +70,6 @@ class App extends Component {
});
}

updateVerses = () => {
console.log('Hello');
}

render() {
return (
<BrowserRouter>
Expand All @@ -85,7 +79,7 @@ class App extends Component {
<Route exact path='/gita/' render={(props) => <Home {...props} updatePage={this.updatePage} chapters={this.state.chapters} currentPage={this.state.currentPage}/>} />
<Route exact path='/gita/about' render={(props) => <h2>about</h2>} />
<Route exact path='/gita/source' render={(props) => <h2>Sources</h2>} />
<Route exact path='/gita/verses/:ch' render={(props) => <Verses updateVerses={this.updateVerses} {...props} verses={this.state.verses} />} />
<Route exact path='/gita/verses/:ch' render={(props) => <Verses {...props} chapters={this.state.chapters} ch={props.match.params.ch} acc_token={this.state.acc_token}/>} />
</main>
<Loader nChapters={this.state.chapters.length} />
</div>
Expand Down
104 changes: 101 additions & 3 deletions src/Components/Verses/Verses.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,111 @@
import React, { Component } from 'react';
import { Divider, ExpansionPanel, ExpansionPanelSummary, ExpansionPanelDetails, Typography } from '@material-ui/core';
import { ExpandMore } from '@material-ui/icons';

class Verses extends Component {

state = {
verses: null,
chapter: null,
expanded: ''
}

render() {

const styles = {
hr: {
backgroundColor: 'rgba(255,255,255,0.5)',
width: '85%',
margin: '0 auto',
marginBottom: '8px'
},

expansionPanel: {
marginBottom: '5px',
backgroundColor: '#2196f3',
color: 'white'
}
}

const { ch, acc_token} = this.props;

if ( this.state.chapter !== this.props.chapters[ch] ) {
this.setState({
chapter: this.props.chapters[ch]
})
}

if ( this.state.verses == null ) {
const baseUrl = 'https://bhagavadgita.io/api/v1/';
const url = `${baseUrl}chapters/${ch}/verses?access_token=${acc_token}`;
const options = {
'mode': 'cors',
}

// Fetch Verses from the desired chapter
fetch(url, options)
.then((res) => {
if(res.ok) {
res.json().then((data) => {
const versesData = data.map((verse) => {
return(
<ExpansionPanel style={styles.expansionPanel}>
<ExpansionPanelSummary
expandIcon={
<ExpandMore style={{color: 'white'}} />
}
>
<Typography variant='h5' color='inherit'>
{verse.text}
</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails style={{display: 'block'}} >
<Typography gutterBottom style={{width: '100%'}} variant='subtitle2' color='inherit'>
&raquo; Transliteration
</Typography>

<Typography gutterBottom color='inherit' variant='h6' >
{verse.transliteration}
</Typography>
<Divider style={styles.hr}/>

<Typography gutterBottom variant='subtitle2' color='inherit'>
&raquo; Meaning
</Typography>

<Typography gutterBottom color='inherit' variant='h6' >
{verse.meaning}
</Typography>
<Divider style={styles.hr}/>

<Typography gutterBottom variant='subtitle2' color='inherit'>
&raquo; Word Meanings
</Typography>

<Typography gutterBottom color='inherit' variant='h6' >
{verse.word_meanings}
</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
);
});
this.setState({ verses: versesData });
});
} else {
console.log('Error in retrieving verses');
}
})
.catch((err) => {
console.log('verses error', err);
});
}

return(
<div>
<h3>Verses : {this.props.match.params.ch}</h3>
</div>
{this.state.verses}
</div>
);
}
}

export default Verses;
export default Verses;

0 comments on commit 6881002

Please sign in to comment.