Skip to content

Commit

Permalink
Merge pull request #26 from GSG-G8/25-Refactor-Dom
Browse files Browse the repository at this point in the history
Refactor the dom function
  • Loading branch information
Rawan96 authored Feb 27, 2020
2 parents e12c144 + db66bbf commit aff77d5
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 32 deletions.
2 changes: 1 addition & 1 deletion public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<main class="main">
<section class="error">
<p class="error__desc">404. <span class="error__msg">Page not found</span></p>
<img class="error__image" src="./img/error.png" alt="error">
<img class="error__image" src="/images/404.svg" alt="error" />
</section>
</main>

Expand Down
4 changes: 4 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* {
margin: 0;
padding: 0
}
409 changes: 409 additions & 0 deletions public/img/404.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ <h1>
<h2>
Our App aims to help people to explore locations using huge database and allows people to post data to the database in order to help other people
</h2>
<div class="map__container">

</div>
</header>
<section class="section">
<input type="text" name="location" id="searchInput" value="" placeholder="location">
Expand Down
68 changes: 37 additions & 31 deletions public/script/dom.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
const viewDetails = document.querySelector('#viewDetails');
const searchInput = document.querySelector('#searchInput');
const mapContainer = document.querySelector('.map__container');
const header = document.querySelector('.header');

// Extra coordinates for testing (41.40338, 2.17403)
let mapSrc = '31.5129811,34.4464425';
const src = `https://www.google.com/maps/embed/v1/place?q=${mapSrc.split(',')[0]}%2C%20${mapSrc.split(',')[1]}&key=AIzaSyDDOHAK66Eu_kt42uNaSrmXoWZv8r3d_X8`;

const iframe = document.createElement('iframe');
iframe.setAttribute('width', `${window.innerWidth}`);
iframe.setAttribute('height', '300px');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('style', 'border:0');
iframe.setAttribute('allowfullscreen', '');
iframe.setAttribute('src', `${src}`);

document.querySelector('.header').appendChild(iframe);
const deleteNodeChilds = (node) => {
while (node.firstChild) node.removeChild(node.firstChild);
};

// Extra coordinates for testing (41.40338,2.17403)

let mapSrc = '31.5129811,34.4464425'; // Here the default coordinates are Gaza Sky Geeks coordinates

const createIframe = () => {
deleteNodeChilds(mapContainer);
const src = `https://www.google.com/maps/embed/v1/place?q=${mapSrc.split(',')[0]}%2C%20${mapSrc.split(',')[1]}&key=AIzaSyDDOHAK66Eu_kt42uNaSrmXoWZv8r3d_X8`;
const iframe = document.createElement('iframe');
iframe.setAttribute('width', `${window.innerWidth}`);
iframe.setAttribute('height', '300px');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('style', 'border:0');
iframe.setAttribute('allowfullscreen', '');
iframe.setAttribute('src', `${src}`);
mapContainer.appendChild(iframe);
};
(createIframe());

const renderTheData = (location) => {
console.log(location);
const section = document.querySelector('.results__container');
const resultsContainer = document.querySelector('.results__container');
const div = document.createElement('div');
const resultsName = document.createElement('h3');
resultsName.textContent = `Name: ${location[0].name}`;
div.appendChild(resultsName);

const resultCategory = document.createElement('h3');
resultCategory.textContent = `Category: ${location[0].category}`;
div.appendChild(resultCategory);

const resultDescription = document.createElement('h3');
resultDescription.textContent = `Description: ${location[0].description}`;
div.appendChild(resultDescription);

const resultCoordinates = document.createElement('h3');
resultCoordinates.textContent = `Coordinates: ${location[0].coordinates}`;
div.appendChild(resultCoordinates);

section.appendChild(div);
deleteNodeChilds(resultsContainer);
const createElements = (description, param2) => {
const resultsName = document.createElement('h4');
resultsName.textContent = `${description}: ${location[0][param2]}`;
div.appendChild(resultsName);
};

createElements('Name', 'name');
createElements('Category', 'category');
createElements('Description', 'description');
createElements('Coordinates', 'coordinates');

resultsContainer.appendChild(div);
};

viewDetails.addEventListener('click', () => {
fetch(`/locations?location=${searchInput.value}`).then((res) => res.json()).then((result) => {
mapSrc = result[0].coordinates;
renderTheData(result);
createIframe();
});
});
Empty file removed public/script/fetch.js
Empty file.
1 change: 1 addition & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config();
const express = require('express');
const path = require('path');
const router = require('./controllers');
Expand Down
Empty file removed server/router/index.js
Empty file.

0 comments on commit aff77d5

Please sign in to comment.