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..b724316 100644 --- a/src/components/NearbyComplaints.jsx +++ b/src/components/NearbyComplaints.jsx @@ -49,8 +49,13 @@ const NearbyComplaints = () => { } }; + const hasCoordinate = (value) => { + if (typeof value === 'number') return Number.isFinite(value); + return typeof value === 'string' && value.trim() !== '' && 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 (