From b606b7cfe3d18bb9dfb8cecedd8d0795f2032daa Mon Sep 17 00:00:00 2001 From: tharunreddy08 Date: Mon, 28 Sep 2026 19:22:58 +0530 Subject: [PATCH 1/2] Fix saved location and add frontend CI --- .github/workflows/frontend-ci.yml | 57 +++++++++++++++++++++++++++++ src/components/NearbyComplaints.jsx | 9 ++++- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/frontend-ci.yml diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml new file mode 100644 index 0000000..4075fe3 --- /dev/null +++ b/.github/workflows/frontend-ci.yml @@ -0,0 +1,57 @@ +name: Frontend CI + +on: + pull_request: + branches: [main] + paths: + - "src/**" + - "public/**" + - "index.html" + - "package.json" + - "package-lock.json" + - "vite.config.js" + - "eslint.config.js" + - ".github/workflows/frontend-ci.yml" + push: + branches: [main] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Run lint + run: npm run lint + + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build diff --git a/src/components/NearbyComplaints.jsx b/src/components/NearbyComplaints.jsx index c1ec8f3..9151a1a 100644 --- a/src/components/NearbyComplaints.jsx +++ b/src/components/NearbyComplaints.jsx @@ -49,8 +49,13 @@ const NearbyComplaints = () => { } }; + const hasCoordinate = (value) => { + if (value === null || value === undefined || value === '') return false; + return Number.isFinite(Number(value)); + }; + const handleUseSavedLocation = async () => { - if (!user?.latitude || !user?.longitude) return; + if (!hasCoordinate(user?.latitude) || !hasCoordinate(user?.longitude)) return; await fetchNearby(user.latitude, user.longitude); }; @@ -94,7 +99,7 @@ const NearbyComplaints = () => { ); }; - const savedAvailable = Boolean(user?.latitude && user?.longitude); + const savedAvailable = hasCoordinate(user?.latitude) && hasCoordinate(user?.longitude); return (
From e3ef46ffdbdec7c4be8f927fe9a6152d0079ea4c Mon Sep 17 00:00:00 2001 From: Janani Date: Tue, 29 Sep 2026 08:40:22 +0530 Subject: [PATCH 2/2] Refactor hasCoordinate function for better checks Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/components/NearbyComplaints.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/NearbyComplaints.jsx b/src/components/NearbyComplaints.jsx index 9151a1a..b724316 100644 --- a/src/components/NearbyComplaints.jsx +++ b/src/components/NearbyComplaints.jsx @@ -50,8 +50,8 @@ const NearbyComplaints = () => { }; const hasCoordinate = (value) => { - if (value === null || value === undefined || value === '') return false; - return Number.isFinite(Number(value)); + if (typeof value === 'number') return Number.isFinite(value); + return typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)); }; const handleUseSavedLocation = async () => {