From c9b0104b3e103d44d7fc6f5faabca2b63e6bc25e Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 31 May 2017 16:17:48 +0300 Subject: [PATCH 1/9] modify the table schema --- database/db_build.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/database/db_build.js b/database/db_build.js index 611a590..33da535 100644 --- a/database/db_build.js +++ b/database/db_build.js @@ -16,8 +16,9 @@ MongoClient.connect(DB_URL, (err, db) => { }); // inserts data to the collection guestHouse.insert({ - GuestHouses: { - Daher: { + GuestHouses: [ + { + id: 0, name: 'Daher', address: '6098 St 8, Nazareth', phone: '052-535-0691', @@ -32,7 +33,8 @@ MongoClient.connect(DB_URL, (err, db) => { longitude: 35.298813, }, }, - SimSim: { + { + id: 1, name: 'SimSim', address: '632 St 3, Nazareth', phone: '077-551-7275', @@ -47,7 +49,8 @@ MongoClient.connect(DB_URL, (err, db) => { longitude: 35.298813, }, }, - Vitrage: { + { + id: 2, name: 'Vitrage', address: '6083 St 4, Nazareth', phone: '04-601-2130', @@ -62,7 +65,7 @@ MongoClient.connect(DB_URL, (err, db) => { longitude: 35.298813, }, }, - }, + ], }, (insertErr) => { if (insertErr) throw insertErr; // searches through the collection to make sure that the data that we inserted is there From 512cbbf4319bb65f11055d15e243607916c8b863 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 31 May 2017 16:18:20 +0300 Subject: [PATCH 2/9] delete unused code --- server.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/server.js b/server.js index a8a3fac..75083ae 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,3 @@ -import { matchPath } from 'react-router-dom'; - const express = require('express'); const webpackDevMiddleware = require('webpack-dev-middleware'); const webpack = require('webpack'); @@ -8,7 +6,6 @@ const path = require('path'); const webpackConfig = require('./webpack.config.js'); const DB_URL = require('./database/url.js'); const db = require('./database/db.js'); -const Routes = require('./src/routes.jsx'); const app = express(); // initiates webapck using your config rules @@ -27,13 +24,6 @@ app.use(webpackDevMiddleware(compiler, { historyApiFallback: true, })); -// have express parse url and send it to react react-router -app.get('*', (request, response, next) => { - matchPath({ Routes, location: request.url }, () => { - response.sendFile(path.resolve(__dirname, 'public', 'index.html')); - }); - next(); -}); app.get('/api', (request, response) => { const data = db.get(); From bc0323c8c27a188c1c2d813c8cd37e7ebdd50d62 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 31 May 2017 16:18:56 +0300 Subject: [PATCH 3/9] render from the databse #31 --- src/components/search_bar.jsx | 12 ---------- src/components/search_list.jsx | 34 ++++++++++++++++++++++++++++ src/containers/select_guesthouse.jsx | 8 +++---- 3 files changed, 38 insertions(+), 16 deletions(-) delete mode 100644 src/components/search_bar.jsx create mode 100644 src/components/search_list.jsx diff --git a/src/components/search_bar.jsx b/src/components/search_bar.jsx deleted file mode 100644 index cc5bd61..0000000 --- a/src/components/search_bar.jsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { Link } from 'react-router-dom'; - -const SearchBar = () => - ( -
- - -
- ); - -export default SearchBar; diff --git a/src/components/search_list.jsx b/src/components/search_list.jsx new file mode 100644 index 0000000..17a2341 --- /dev/null +++ b/src/components/search_list.jsx @@ -0,0 +1,34 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +class SearchList extends Component { + constructor(props) { + super(props); + this.renderList = this.renderList.bind(this); + + this.state = {}; + } + + renderList() { + return this.props.guesthouses.map(ghouse => + ( + +
  • + {ghouse.name} +
  • + + ), + ); + } + + render() { + // console.log(this.props.guesthouses); + return ( +
      + {this.renderList()} +
    + ); + } +} + +export default SearchList; diff --git a/src/containers/select_guesthouse.jsx b/src/containers/select_guesthouse.jsx index e782c28..019d633 100644 --- a/src/containers/select_guesthouse.jsx +++ b/src/containers/select_guesthouse.jsx @@ -3,18 +3,18 @@ import axios from 'axios'; import Header from '../components/header.jsx'; import TextBox from '../components/text_box.jsx'; -import SearchBar from '../components/search_bar.jsx'; +import SearchList from '../components/search_list.jsx'; class SelectGuesthouse extends Component { constructor(props) { super(props); this.state = { - db: {}, + db: [], }; } - componentDidMount() { + componentWillMount() { axios.get('/api') .then((res) => { this.setState({ db: res.data }); @@ -26,7 +26,7 @@ class SelectGuesthouse extends Component {
    - +
    ); } From f019fa1d550ede83b7d078919ba0ee1d5fbe3ae5 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Jun 2017 15:54:32 +0300 Subject: [PATCH 4/9] make mock data because we currently dont need it #31 --- mockData.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 mockData.js diff --git a/mockData.js b/mockData.js new file mode 100644 index 0000000..2256190 --- /dev/null +++ b/mockData.js @@ -0,0 +1,51 @@ +module.exports = +[ + { + id: 0, + name: 'Daher', + address: '6098 St 8, Nazareth', + phone: '052-535-0691', + coordinates: { + latitude: 32.704783, + longitude: 35.298489, + }, + parkingLotName: 'Al Mutran Parking', + parkingLotAddress: '6100 St, Nazareth', + parkingLotCoordinates: { + latitude: 32.705329, + longitude: 35.298813, + }, + }, + { + id: 1, + name: 'SimSim', + address: '632 St 3, Nazareth', + phone: '077-551-7275', + coordinates: { + latitude: 32.704375, + longitude: 35.298083, + }, + parkingLotName: 'Al Mutran Parking', + parkingLotAddress: '6100 St, Nazareth', + parkingLotCoordinates: { + latitude: 32.705329, + longitude: 35.298813, + }, + }, + { + id: 2, + name: 'Vitrage', + address: '6083 St 4, Nazareth', + phone: '04-601-2130', + coordinates: { + latitude: 32.705086, + longitude: 35.298032, + }, + parkingLotName: 'Al Mutran Parking', + parkingLotAddress: '6100 St, Nazareth', + parkingLotCoordinates: { + latitude: 32.705329, + longitude: 35.298813, + }, + }, +]; From 709786b97386efacad362de07d419be049879598 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Jun 2017 15:54:59 +0300 Subject: [PATCH 5/9] adds some viable tests that passes #31 --- tests/components.jsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/components.jsx b/tests/components.jsx index 07b7ddf..fcd391b 100644 --- a/tests/components.jsx +++ b/tests/components.jsx @@ -1,19 +1,20 @@ /* eslint-disable import/no-extraneous-dependencies */ -// Commented out text is for future reference - -// import React from 'react'; +import React from 'react'; import tape from 'tape'; -// import { shallow } from 'enzyme'; +import { shallow } from 'enzyme'; + +import SelectGuesthouse from '../src/containers/select_guesthouse.jsx'; +import SearchList from '../src/components/search_list.jsx'; tape('Check tape is working', (t) => { t.pass('a message'); t.end(); }); -// tape('Check that a button is rendered', (t) => { -// const wrapper = shallow(); -// -// t.equal(wrapper.exists(