Initial commit 🚀

This commit is contained in:
Jonas Schmedtmann
2019-06-13 15:43:15 +01:00
commit 7f81af0ddf
1052 changed files with 2123177 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/* eslint-disable */
export const hideAlert = () => {
const el = document.querySelector('.alert');
if (el) el.parentElement.removeChild(el);
};
// type is 'success' or 'error'
export const showAlert = (type, msg) => {
hideAlert();
const markup = `<div class="alert alert--${type}">${msg}</div>`;
document.querySelector('body').insertAdjacentHTML('afterbegin', markup);
window.setTimeout(hideAlert, 5000);
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,55 @@
/* eslint-disable */
import '@babel/polyfill';
import { displayMap } from './mapbox';
import { login, logout } from './login';
import { updateSettings } from './updateSettings';
// DOM ELEMENTS
const mapBox = document.getElementById('map');
const loginForm = document.querySelector('.form--login');
const logOutBtn = document.querySelector('.nav__el--logout');
const userDataForm = document.querySelector('.form-user-data');
const userPasswordForm = document.querySelector('.form-user-password');
// DELEGATION
if (mapBox) {
const locations = JSON.parse(mapBox.dataset.locations);
displayMap(locations);
}
if (loginForm)
loginForm.addEventListener('submit', e => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
login(email, password);
});
if (logOutBtn) logOutBtn.addEventListener('click', logout);
if (userDataForm)
userDataForm.addEventListener('submit', e => {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
updateSettings({ name, email }, 'data');
});
if (userPasswordForm)
userPasswordForm.addEventListener('submit', async e => {
e.preventDefault();
document.querySelector('.btn--save-password').textContent = 'Updating...';
const passwordCurrent = document.getElementById('password-current').value;
const password = document.getElementById('password').value;
const passwordConfirm = document.getElementById('password-confirm').value;
await updateSettings(
{ passwordCurrent, password, passwordConfirm },
'password'
);
document.querySelector('.btn--save-password').textContent = 'Save password';
document.getElementById('password-current').value = '';
document.getElementById('password').value = '';
document.getElementById('password-confirm').value = '';
});

View File

@@ -0,0 +1,38 @@
/* eslint-disable */
import axios from 'axios';
import { showAlert } from './alerts';
export const login = async (email, password) => {
try {
const res = await axios({
method: 'POST',
url: 'http://127.0.0.1:3000/api/v1/users/login',
data: {
email,
password
}
});
if (res.data.status === 'success') {
showAlert('success', 'Logged in successfully!');
window.setTimeout(() => {
location.assign('/');
}, 1500);
}
} catch (err) {
showAlert('error', err.response.data.message);
}
};
export const logout = async () => {
try {
const res = await axios({
method: 'GET',
url: 'http://127.0.0.1:3000/api/v1/users/logout'
});
if ((res.data.status = 'success')) location.reload(true);
} catch (err) {
console.log(err.response);
showAlert('error', 'Error logging out! Try again.');
}
};

View File

@@ -0,0 +1,50 @@
/* eslint-disable */
export const displayMap = locations => {
mapboxgl.accessToken =
'pk.eyJ1Ijoiam9uYXNzY2htZWR0bWFubiIsImEiOiJjam54ZmM5N3gwNjAzM3dtZDNxYTVlMnd2In0.ytpI7V7w7cyT1Kq5rT9Z1A';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/jonasschmedtmann/cjvi9q8jd04mi1cpgmg7ev3dy',
scrollZoom: false
// center: [-118.113491, 34.111745],
// zoom: 10,
// interactive: false
});
const bounds = new mapboxgl.LngLatBounds();
locations.forEach(loc => {
// Create marker
const el = document.createElement('div');
el.className = 'marker';
// Add marker
new mapboxgl.Marker({
element: el,
anchor: 'bottom'
})
.setLngLat(loc.coordinates)
.addTo(map);
// Add popup
new mapboxgl.Popup({
offset: 30
})
.setLngLat(loc.coordinates)
.setHTML(`<p>Day ${loc.day}: ${loc.description}</p>`)
.addTo(map);
// Extend map bounds to include current location
bounds.extend(loc.coordinates);
});
map.fitBounds(bounds, {
padding: {
top: 200,
bottom: 150,
left: 100,
right: 100
}
});
};

View File

@@ -0,0 +1,25 @@
/* eslint-disable */
import axios from 'axios';
import { showAlert } from './alerts';
// type is either 'password' or 'data'
export const updateSettings = async (data, type) => {
try {
const url =
type === 'password'
? 'http://127.0.0.1:3000/api/v1/users/updateMyPassword'
: 'http://127.0.0.1:3000/api/v1/users/updateMe';
const res = await axios({
method: 'PATCH',
url,
data
});
if (res.data.status === 'success') {
showAlert('success', `${type.toUpperCase()} updated successfully!`);
}
} catch (err) {
showAlert('error', err.response.data.message);
}
};