diff --git a/src/App.js b/src/App.js index 0d360fe..7e67b8a 100644 --- a/src/App.js +++ b/src/App.js @@ -15,7 +15,7 @@ class App extends Component { selectDisabled: false } - state = { tagFilters: [], selectedBook: null } + handleItemClick = (e, { name }) => this.setState({ activeItem: name }) constructor(props) { @@ -154,6 +154,25 @@ class App extends Component { }); } + const popularActive = (news) => { + var results = {}; + for (var i = 0; i < news.length; i++) { + const everyTagsOnNews = news[i].tags || []; + for (var j = 0; j < everyTagsOnNews.length; j++) { + if(results[everyTagsOnNews[j]]){ + results[everyTagsOnNews[j]]++ ; + }else{ + results[everyTagsOnNews[j]] = 1; + } + } + } + console.log("result", results); + const tempResult = Object.keys(results).map((key) => ({count: results[key], value: key})) || []; + console.log("tempResult", tempResult); + + return tempResult; + } + return (
@@ -182,14 +201,20 @@ class App extends Component { options={books} /> - + + {/* {popularActive(this.props.data.news).map((x, tempIndex)=> + + )} */} { const results = this.props.options.filter(y => y.fullName === x); if(results.length > 0){ @@ -134,7 +131,7 @@ class BookTags extends Component { if (availTags.length > 0) { let newTags = currentTags.concat(availTags[Math.floor(Math.random()*availTags.length)]); alert(`Brefing book suggestions: ${newTags}`); - } + } } @@ -163,12 +160,12 @@ class BookTags extends Component { value={this.state.value} {...this.props} />} -
} /> + + } /> ) class Tags extends Component { @@ -46,7 +48,6 @@ class Tags extends Component { return null; } }) - const newNews = Object.assign({}, this.props.item, {userBooks: newUserbooks}); this.props.updateTags(this.props.item._id, newNews ); } diff --git a/src/index.js b/src/index.js index 3e306b5..a3f24c1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,69 +1,35 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import App from './App'; import registerServiceWorker from './registerServiceWorker'; -import './index.css'; -import * as firebase from 'firebase'; - +import { BrowserRouter as Router, Route, Link } from 'react-router-dom' +import { database, newsActions, userActions} from './FirebaseService'; import Home from './Home'; import MainPage from './MainPage'; +import App from './App'; +import './index.css'; -import { - BrowserRouter as Router, - Route, - Link -} from 'react-router-dom' -const config = { - apiKey: "AIzaSyA5Fh7tb7DREA5fgAKwJjh_llXfIKs9iMs", - authDomain: "my-test-website-c0fcc.firebaseapp.com", - databaseURL: "https://my-test-website-c0fcc.firebaseio.com", - projectId: "my-test-website-c0fcc", - storageBucket: "my-test-website-c0fcc.appspot.com", - messagingSenderId: "575661525828" - }; - -const fb = firebase - .initializeApp(config) - .database() - .ref(); - - //News API - const getNewsbyId = id => fb.child('news').child(id); - const addNews = data => fb.child('news').push(data, response => response); - const adduserArticle = data => fb.child("userArticle").push(data, response => response); - // this.bindAsArray(fb.child("userArticle"), "userArticle"); - const removeUserArticle = (id) => fb.child("userArticle").child(id).remove(); - - const updateNews = (id, data) => fb.child(`news/${id}`).update(data, response => response); - export const newsActions = { - addNews, - updateNews, - getNewsbyId, - adduserArticle, - removeUserArticle - }; - //User API - const getUsersbyId = id => fb.child('users').child(id); - const updateUserbyID = (id, data) => fb.child(`users/${id}`).update(data, response => response); - export const userActions = { - getUsersbyId, - updateUserbyID, - }; - - fb.on('value', snapshot => { - const store = snapshot.val(); - console.log("index.js", store) - ReactDOM.render( - -
- } /> - - } /> -
-
, - document.getElementById('root') - ); + database.ref('news').on('value', snapshot => { + const newsStore = snapshot.val(); + database.ref('users').on('value', snapshot => { + const usersStore = snapshot.val(); + database.ref('userBooks').on('value', snapshot => { + const userBooksStore = snapshot.val(); + const store = Object.assign({}, {news:newsStore}, {users: usersStore}, {userBooks: userBooksStore}); + console.log("index.js", store) + ReactDOM.render( + +
+ } /> + + } /> +
+
, + document.getElementById('root') + ); + }); + }); }); + registerServiceWorker(); diff --git a/src/routes.js b/src/routes.js index cbea1fb..d20dde6 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,24 +1,8 @@ import React from 'react'; -import {Route, IndexRoute} from 'react-router'; +import { Route, IndexRoute } from 'react-router'; import App from './App'; import Home from './Home'; import MainPage from './MainPage'; -// import * as firebase from 'firebase'; -// -// -// const config = { -// apiKey: "AIzaSyA5Fh7tb7DREA5fgAKwJjh_llXfIKs9iMs", -// authDomain: "my-test-website-c0fcc.firebaseapp.com", -// databaseURL: "https://my-test-website-c0fcc.firebaseio.com", -// projectId: "my-test-website-c0fcc", -// storageBucket: "my-test-website-c0fcc.appspot.com", -// messagingSenderId: "575661525828" -// }; -// -// const fb = firebase -// .initializeApp(config) -// .database() -// .ref(); export default (