React + Vite client for RideOn. Uses Socket.IO client for realtime notifications and Google Maps for geolocation.
- Copy
.envin/Frontend/.envand set:- VITE_BASE_URL (API base) — currently
http://localhost:9000/api/v1 - VITE_GOOGLE_MAPS_API_KEY
- VITE_BASE_URL (API base) — currently
- Install & run:
cd Frontend npm install npm run dev - App entry:
src/main.jsx. Routes defined insrc/App.jsx.
- Socket provider:
src/context/SocketContext.jsx— exposesSocketContextand the socket instance created withio(...). - User state:
src/context/UserContext.jsx— providesUserDataContext. - Captain state:
src/context/CaptainContext.jsx. - Main pages:
- Home:
src/pages/Home.jsx— emitsjoinand listens toride-confirmed/ride-started. - CaptainHome:
src/pages/CaptainHome.jsx— emitsjoinfor captain, listens fornew-ride. - Riding / CaptainRiding:
src/pages/Riding.jsx,src/pages/CaptainRiding.jsx
- Home:
- Map & tracking:
- Map component:
src/components/LiveTracking.jsx— usesnavigator.geolocation+@react-google-maps/api.
- Map component:
- UI components with placeholders (please replace hardcoded assets/strings):
- Vite config:
vite.config.js— proxy configured for/api. - Tailwind + CSS:
src/index.css
- On authenticated pages (
Home,CaptainHome) the client must emit:See emission insocket.emit('join', { userId: <id>, userType: 'user'|'captain' });
src/pages/Home.jsxandsrc/pages/CaptainHome.jsx. - The frontend listens for events:
new-ride→src/pages/CaptainHome.jsxride-confirmed,ride-started→src/pages/Home.jsxEnsureUserDataContexthas the correct user_idbefore emitting join.
- Replace hardcoded images / text placeholders in:
- Ensure
UserContextdefault value isnullnot an empty object to avoid race conditions: seesrc/context/UserContext.jsx. - Validate join flow: socket must be connected and
user._idmust be available before emittingjoin(seesrc/pages/Home.jsx).
- User
socketIdnot saved in DB:- Confirm client emits
joinafter login and after socket connects (seesrc/context/SocketContext.jsxandsrc/pages/Home.jsx). - Check backend logs from
Backend/socket.jsto verify server receivedjoin.
- Confirm client emits
- 500 error on ride confirm:
- Inspect network console where frontend calls
/rides/confirm(seeFrontend/src/pages/CaptainHome.jsx) and backend logs inBackend/src/controllers/ride.controller.js.
- Inspect network console where frontend calls
- Frontend entry:
Frontend/src/main.jsx - App routing:
Frontend/src/App.jsx - API calls example: see
axioscalls inFrontend/src/pages/Home.jsxandFrontend/src/pages/CaptainHome.jsx - Vite environment:
Frontend/.env
- This README assumes active development. Add tests, TypeScript conversion and CI when stabilizing. Contributions: open PRs, follow component separation and add unit tests for services.
# RideOn — Frontend
React + Vite client for RideOn. Uses Socket.IO client for realtime notifications and Google Maps for geolocation.
## Quick start
1. Copy `.env` in `/Frontend/.env` and set:
- VITE_BASE_URL (API base) — currently `http://localhost:9000/api/v1`
- VITE_GOOGLE_MAPS_API_KEY
2. Install & run:
```sh
cd Frontend
npm install
npm run dev
- App entry:
src/main.jsx. Routes defined insrc/App.jsx.
- Socket provider:
src/context/SocketContext.jsx— exposesSocketContextand the socket instance created withio(...). - User state:
src/context/UserContext.jsx— providesUserDataContext. - Captain state:
src/context/CaptainContext.jsx. - Main pages:
- Home:
src/pages/Home.jsx— emitsjoinand listens toride-confirmed/ride-started. - CaptainHome:
src/pages/CaptainHome.jsx— emitsjoinfor captain, listens fornew-ride. - Riding / CaptainRiding:
src/pages/Riding.jsx,src/pages/CaptainRiding.jsx
- Home:
- Map & tracking:
- Map component:
src/components/LiveTracking.jsx— usesnavigator.geolocation+@react-google-maps/api.
- Map component:
- UI components with placeholders (please replace hardcoded assets/strings):
- Vite config:
vite.config.js— proxy configured for/api. - Tailwind + CSS:
src/index.css
- On authenticated pages (
Home,CaptainHome) the client must emit:See emission insocket.emit('join', { userId: <id>, userType: 'user'|'captain' });
src/pages/Home.jsxandsrc/pages/CaptainHome.jsx. - The frontend listens for events:
new-ride→src/pages/CaptainHome.jsxride-confirmed,ride-started→src/pages/Home.jsxEnsureUserDataContexthas the correct user_idbefore emitting join.
- Replace hardcoded images / text placeholders in:
- Ensure
UserContextdefault value isnullnot an empty object to avoid race conditions: seesrc/context/UserContext.jsx. - Validate join flow: socket must be connected and
user._idmust be available before emittingjoin(seesrc/pages/Home.jsx).
- User
socketIdnot saved in DB:- Confirm client emits
joinafter login and after socket connects (seesrc/context/SocketContext.jsxandsrc/pages/Home.jsx). - Check backend logs from
Backend/socket.jsto verify server receivedjoin.
- Confirm client emits
- 500 error on ride confirm:
- Inspect network console where frontend calls
/rides/confirm(seeFrontend/src/pages/CaptainHome.jsx) and backend logs inBackend/src/controllers/ride.controller.js.
- Inspect network console where frontend calls
- Frontend entry:
Frontend/src/main.jsx - App routing:
Frontend/src/App.jsx - API calls example: see
axioscalls inFrontend/src/pages/Home.jsxandFrontend/src/pages/CaptainHome.jsx - Vite environment:
Frontend/.env
- This README assumes active development. Add tests, TypeScript conversion and CI when stabilizing. Contributions: open PRs, follow component separation and add unit tests for services.