Skip to content

feat: persist last searched city using localStorage #115#144

Open
SHUBHAM2775 wants to merge 2 commits into
aditya-ai00:mainfrom
SHUBHAM2775:feat/persist-searched-city
Open

feat: persist last searched city using localStorage #115#144
SHUBHAM2775 wants to merge 2 commits into
aditya-ai00:mainfrom
SHUBHAM2775:feat/persist-searched-city

Conversation

@SHUBHAM2775

Copy link
Copy Markdown

What this PR does / why we need it:
Resolves the issue where the weather application resets to a blank/geolocation state every time the user refreshes the page. By utilizing localStorage, the app now automatically remembers and fetches the last successfully searched city on page reload.

Acceptance Criteria Met:

  • Last searched city is restored automatically after a page reload.
  • localStorage is safely updated only after a successful API fetch.
  • Cleanly handles the "first visit" state (empty localStorage) by safely falling back to the default geolocation logic without console errors.
  • Invalid or failed searches are ignored and not saved.
  • No interference with the existing styling, Dark Mode, or user-triggered geolocation functionality.

Changes Made:

  • Updated script.js to initialize the app by reading lastSearchedCity from localStorage.
  • Added localStorage.setItem inside getWeather(), specifically placed after error-handling checks to guarantee data validity.

Closes #115

@vercel

vercel Bot commented May 12, 2026

Copy link
Copy Markdown

@SHUBHAM2775 is attempting to deploy a commit to the aditya-ai00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@aditya-ai00

Copy link
Copy Markdown
Owner

Hi @SHUBHAM2775,

Thanks for the contribution.

The localStorage persistence feature is a useful improvement for user experience and the implementation approach looks good overall. However, the PR is still showing a merge conflict in script.js, so I’m unable to proceed with the review yet.

Please:

  • pull the latest changes from the main branch
  • resolve the remaining conflict completely
  • ensure a fresh preview deployment is available
  • verify that last searched city restoration, geolocation fallback, and existing features continue working correctly after refresh

Also, please keep the scope focused only on the localStorage persistence enhancement for Issue #115.

Once the PR becomes conflict-free and stable, I’ll review it again.

Thanks!

@SHUBHAM2775

Copy link
Copy Markdown
Author

Hi @SHUBHAM2775,

Thanks for the contribution.

The localStorage persistence feature is a useful improvement for user experience and the implementation approach looks good overall. However, the PR is still showing a merge conflict in script.js, so I’m unable to proceed with the review yet.

Please:

  • pull the latest changes from the main branch
  • resolve the remaining conflict completely
  • ensure a fresh preview deployment is available
  • verify that last searched city restoration, geolocation fallback, and existing features continue working correctly after refresh

Also, please keep the scope focused only on the localStorage persistence enhancement for Issue #115.

Once the PR becomes conflict-free and stable, I’ll review it again.

Thanks!

Fixed it @aditya-ai00 . Do check it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist last searched city using localStorage

2 participants