Skip to content

Commit

Permalink
Fix function remove
Browse files Browse the repository at this point in the history
  • Loading branch information
natia-cohen committed Apr 18, 2024
1 parent 5e9608d commit b05d78e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 71 deletions.
28 changes: 25 additions & 3 deletions js/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ window.app = {
onShareLoc,
onSetSortBy,
onSetFilterBy,
openAddLocDialog,
closeAddLocDialog
}

function onInit() {
Expand All @@ -39,12 +41,12 @@ function renderLocs(locs) {

var strHTML = locs.map(loc => {
const className = (loc.id === selectedLocId) ? 'active' : ''
loc.distance = utilService.getDistance(loc.geo, window.gUserPos, 'K')
const distance = utilService.getDistance(loc.geo, window.gUserPos, 'K')
return `
<li class="loc ${className}" data-id="${loc.id}">
<h4>
<span>${loc.name}</span>
<span> Distance: ${loc.distance} KM.</span>
<span> Distance: ${distance} KM.</span>
<span title="${loc.rate} stars">${'★'.repeat(loc.rate)}</span>
</h4>
<p class="muted">
Expand Down Expand Up @@ -73,7 +75,8 @@ function renderLocs(locs) {
}

function onRemoveLoc(locId) {
locService.remove(locId)
const removeLoc = confirm('Are you sure you want to delete the location?')
if (removeLoc) locService.remove(locId)
.then(() => {
flashMsg('Location removed')
unDisplayLoc()
Expand Down Expand Up @@ -341,3 +344,22 @@ function closeAddLocDialog() {
}


// function onUpdateLoc(locId) {
// locService.getById(locId)
// .then(loc => {
// const rate = prompt('New rate?', loc.rate)
// if (rate !== loc.rate) {
// loc.rate = rate
// locService.save(loc)
// .then(savedLoc => {
// flashMsg(`Rate was set to: ${savedLoc.rate}`)
// loadAndRenderLocs()
// })
// .catch(err => {
// console.error('OOPs:', err)
// flashMsg('Cannot update location')
// })

// }
// })
// }
69 changes: 1 addition & 68 deletions js/services/loc.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ function getById(locId) {
}

function remove(locId) {
const removeLoc = confirm('Are you sure you want to delete the location?')
if (removeLoc) return storageService.remove(DB_KEY, locId)
return
return storageService.remove(DB_KEY, locId)
}

function save(loc) {
Expand Down Expand Up @@ -166,7 +164,6 @@ function _createLoc(name = '', rate = 3, geoData, updatedAt = Date.now()) {
name,
rate,
updatedAt,
distance: 0,
createdAt: updatedAt = utilService.randomPastTime(),
geo: {
lat: geoData.lat || 0,
Expand All @@ -177,67 +174,3 @@ function _createLoc(name = '', rate = 3, geoData, updatedAt = Date.now()) {
}
}


// function getEmptyLoc(name = '') {
// return {
// id: '',
// name,
// rate: 1,
// createdAt: Date.now(),
// updatedAt: Date.now(),
// geo: {
// lat: 0,
// lng: 0,
// zoom: 10,
// address: ''
// }
// }
// }

// function _createDemoLocs() {
// var locs =
// [
// {
// name: "Ben Gurion Airport",
// rate: 2,
// geo: {
// address: "Ben Gurion Airport, 7015001, Israel",
// lat: 32.0004465,
// lng: 34.8706095,
// zoom: 12
// },
// },
// {
// name: "Dekel Beach",
// rate: 4,
// geo: {
// address: "Derekh Mitsrayim 1, Eilat, 88000, Israel",
// lat: 29.5393848,
// lng: 34.9457792,
// zoom: 15
// },
// },
// {
// name: "Dahab, Egypt",
// rate: 5,
// geo: {
// address: "Dahab, South Sinai, Egypt",
// lat: 28.5096676,
// lng: 34.5165187,
// zoom: 11
// }
// }
// ]

// locs = locs.map(_createLoc)
// console.log('locs1', locs)
// utilService.saveToStorage(DB_KEY, locs)
// }

// function _createLoc(loc) {

// loc.id = utilService.makeId()
// loc.createdAt = loc.updatedAt = utilService.randomPastTime()
// loc.distance = utilService.getDistance(loc. window.app.gUserPos )
// return loc
// }

0 comments on commit b05d78e

Please sign in to comment.