Skip to content

Commit

Permalink
fix title bug
Browse files Browse the repository at this point in the history
  • Loading branch information
armanabkar committed Jan 31, 2022
1 parent 250557d commit cc38457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asteroids-neows-vue",
"version": "1.0.0",
"version": "1.0.2",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
13 changes: 8 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ export default {
let plusDay = ref(0)
onMounted(() => {
fetchData("imperial")
fetchData(system.value)
})
const fetchData = (type) => {
system.value = type
isLoading.value = true
system.value = type
fetch(
`https://api.nasa.gov/neo/rest/v1/feed?end_date=${getDate()}&&api_key=DEMO_KEY`
)
.then((res) => res.json())
.then((res) => {
isLoading.value = false
let fetchedData = res.near_earth_objects[getDate()]
.sort(
(a, b) =>
Expand All @@ -58,15 +57,19 @@ export default {
asteroid.close_approach_data[0].epoch_date_close_approach >
new Date()
)
const hazards = fetchedData.reduce((acc, curr) => {
if (curr.is_potentially_hazardous_asteroid) {
return acc + 1
}
return acc
}, 0)
hazards &&
(document.title = `${hazards} Potential Hazards ⚠️ - Near Earth Asteroids`)
hazards
? (document.title = `${hazards} Potential Hazards ⚠️ - Near Earth Asteroids`)
: (document.title = "Near Earth Asteroids")
data.value = fetchedData
isLoading.value = false
})
}
Expand Down

0 comments on commit cc38457

Please sign in to comment.