Skip to content

Commit

Permalink
empty content handle
Browse files Browse the repository at this point in the history
  • Loading branch information
anikweb committed Jun 22, 2023
1 parent 12b9334 commit b7b770c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const getCurrentCityWeather = () => {
.then(result => {
if (!getCookie('getWeather.country')) {
const {city} = result
setAllDataToCookie(city)
setAllDataToCookie(city)

} else {
return 0;
}
Expand Down Expand Up @@ -72,7 +73,9 @@ const htmlData = {
loader: document.querySelector("#loader"),
body : document.querySelector("body"),
loaderText : document.querySelector(".waiting-text"),
darkOverlay : document.querySelector("#dark-overlay")
darkOverlay : document.querySelector("#dark-overlay"),
bottomItems : document.querySelector(".bottom-items"),
locationWrapper : document.querySelector(".location-wrapper"),
};

const getWeatherData = (cityName, units = "metric") => {
Expand Down Expand Up @@ -113,6 +116,7 @@ const setAllDataToCookie = (data) => {
setCookie('getWeather.icon', `https://openweathermap.org/img/wn/${weather[0].icon}.png`, 30);
setCookie('getWeather.wind', wind.speed, 30);
updateWebsiteDatas();

} else if (result.cod == 404) {
setTimeout(() => {
preloader('false');
Expand Down Expand Up @@ -142,8 +146,10 @@ htmlData.button.addEventListener('click', () => {

const updateWebsiteDatas = (websiteload = "no") => {
const update = () => {
if (getCookie('getWeather.temp')) {
htmlData.tempData.innerText = Math.round(getCookie('getWeather.temp'))


if (getCookie('getWeather.temp')) {
htmlData.tempData.innerText = Math.round(getCookie('getWeather.temp'))
}
if (getCookie('getWeather.humadity')) {
htmlData.humadityData.innerText = Math.round(getCookie('getWeather.humadity'))
Expand Down Expand Up @@ -179,6 +185,11 @@ const updateWebsiteDatas = (websiteload = "no") => {
htmlData.body.style.backgroundPosition = "center center"
htmlData.body.style.backgroundAttachment = "fixed"
}

if (getCookie('getWeather.city')) {
htmlData.bottomItems.classList.remove('d-none')
htmlData.locationWrapper.classList.remove('d-none')
}
}
if (websiteload == "no") {
setTimeout(() => {
Expand All @@ -203,7 +214,12 @@ const preloader = (isTrue) => {

if (!getCookie('getWeather.city')) {
preloader('true');
htmlData.bottomItems.classList.add('d-none')
htmlData.locationWrapper.classList.add('d-none')
htmlData.loaderText.innerHTML = `<span><h4 class='m-0 p-0'>Fetching Your Current City Weather,</h4>it's taken much time? search manually</span>`
getCurrentCityWeather()
} else {
htmlData.bottomItems.classList.remove('d-none')
htmlData.locationWrapper.classList.remove('d-none')
}
updateWebsiteDatas("yes")
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div id="dark-overlay" class="d-none"></div>
<div class="container-fluid">
<div class="row mt-5 ">
<div class="col-md-12 d-flex justify-content-start location-wrapper">
<div class="col-md-12 d-flex justify-content-start location-wrapper d-none">
<i class="fa-solid fa-location-dot location-primary-icon me-2"></i>
<h3 class="location-data"></h3>
</div>
Expand Down Expand Up @@ -163,7 +163,7 @@ <h1 class="text-white text-center page-title">Search weather for your city or co
</div>

</div>
<div class="container-fluid bottom-items">
<div class="container-fluid bottom-items d-none">
<div class="container">
<div class="row ">
<div class="col-12 col-lg-3 d-flex align-items-center justify-content-center">
Expand Down

0 comments on commit b7b770c

Please sign in to comment.