From 52d8dd316a0fa620a267b0e5697eefd2dce9f837 Mon Sep 17 00:00:00 2001 From: Ayush Date: Wed, 9 Oct 2024 10:04:15 +0530 Subject: [PATCH] Added back button on station page --- frontend/src/Pages/Register.jsx | 2 +- frontend/src/Pages/stations.jsx | 217 ++++++++++++++++++-------------- 2 files changed, 124 insertions(+), 95 deletions(-) diff --git a/frontend/src/Pages/Register.jsx b/frontend/src/Pages/Register.jsx index d1f19c6..c22ca2c 100644 --- a/frontend/src/Pages/Register.jsx +++ b/frontend/src/Pages/Register.jsx @@ -19,7 +19,7 @@ const Register = () => { const handleRegister = (e) => { e.preventDefault(); - // Handle registration logic here + // Handle registration logic here }; return ( diff --git a/frontend/src/Pages/stations.jsx b/frontend/src/Pages/stations.jsx index dabd7cc..7536fbb 100644 --- a/frontend/src/Pages/stations.jsx +++ b/frontend/src/Pages/stations.jsx @@ -1,13 +1,14 @@ // src/components/RailwayStations.jsx -import React, { useState } from 'react'; -import { FaTrain } from 'react-icons/fa'; // Using FontAwesome train icon -import { AiFillStar, AiOutlineStar } from 'react-icons/ai'; // Star icons for favorites - +import React, { useState } from "react"; +import { FaTrain } from "react-icons/fa"; // Using FontAwesome train icon +import { AiFillStar, AiOutlineStar } from "react-icons/ai"; // Star icons for favorites +import backicon from "../assets/svg/backicon.svg"; +import { useNavigate } from "react-router-dom"; const RailwayStations = () => { - // Comprehensive list of railway stations - const stations = [ - // A + // Comprehensive list of railway stations + const stations = [ + // A "Agartala Railway Station", "Agra Cantonment", "Ahmedabad Junction", @@ -155,103 +156,131 @@ const RailwayStations = () => { // Z "Ziyadpur Junction", - // Add more stations as needed - ]; - - const [searchTerm, setSearchTerm] = useState(''); - const [favorites, setFavorites] = useState([]); + // Add more stations as needed + ]; - // Function to toggle favorite stations - const toggleFavorite = (station) => { - if (favorites.includes(station)) { - setFavorites(favorites.filter((fav) => fav !== station)); - } else { - setFavorites([...favorites, station]); - } - }; + const [searchTerm, setSearchTerm] = useState(""); + const [favorites, setFavorites] = useState([]); + const navigate = useNavigate(); + + // Function to toggle favorite stations + const toggleFavorite = (station) => { + if (favorites.includes(station)) { + setFavorites(favorites.filter((fav) => fav !== station)); + } else { + setFavorites([...favorites, station]); + } + }; + const HomeClick = () => { + navigate("/"); // Navigates to the home page + }; - // Filter stations based on search term - const filteredStations = stations.filter((station) => - station.toLowerCase().includes(searchTerm.toLowerCase()) - ); + // Filter stations based on search term + const filteredStations = stations.filter((station) => + station.toLowerCase().includes(searchTerm.toLowerCase()) + ); - return ( -
- {/* Header Section */} -
-

Railway Stations

-

Find and explore railway stations across India

-
+ return ( +
+
+ +
+ {/* Header Section */} +
+

Railway Stations

+

+ Find and explore railway stations across India +

+
- {/* Search Bar */} -
- setSearchTerm(e.target.value)} - className="w-full max-w-md px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300" - /> -
+ {/* Search Bar */} +
+ setSearchTerm(e.target.value)} + className="w-full max-w-md px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300" + /> +
- {/* Stations Grid */} -
-
- {filteredStations.length > 0 ? ( - filteredStations.map((station, index) => ( -
-
- - {station} -
- -
- )) - ) : ( -
No stations found.
- )} + {/* Stations Grid */} +
+
+ {filteredStations.length > 0 ? ( + filteredStations.map((station, index) => ( +
+
+ + {station}
+ +
+ )) + ) : ( +
+ No stations found.
+ )} +
+
- {/* Favorites Section (Optional) */} - {favorites.length > 0 && ( -
-

Your Favorite Stations

-
-
- {favorites.map((station, index) => ( -
-
- - {station} -
- -
- ))} -
-
+ {/* Favorites Section (Optional) */} + {favorites.length > 0 && ( +
+

+ Your Favorite Stations +

+
+
+ {favorites.map((station, index) => ( +
+
+ + {station} +
+
- )} + ))} +
+
- ); + )} +
+ ); }; export default RailwayStations;