From a7e8842e6664cc66b4d29c553c5d91270d022118 Mon Sep 17 00:00:00 2001 From: Soni Dhruv Date: Sat, 25 May 2024 10:32:08 +0530 Subject: [PATCH] created drop down menu for responsive devices and hide that menu in large screens --- src/components/Pages/MainPage.jsx | 160 +++++++++++++++++++----------- src/components/Pages/mainpage.css | 17 ++++ 2 files changed, 121 insertions(+), 56 deletions(-) diff --git a/src/components/Pages/MainPage.jsx b/src/components/Pages/MainPage.jsx index 7340ed26..9c4a6050 100644 --- a/src/components/Pages/MainPage.jsx +++ b/src/components/Pages/MainPage.jsx @@ -1,66 +1,114 @@ -import React, { useEffect, useState } from 'react'; -import ProjectCards from '../Cards/ProjectCards'; -import './mainpage.css'; -import Dashboard from './Dashboard'; +import React, { useEffect, useState } from "react"; +import ProjectCards from "../Cards/ProjectCards"; +import "./mainpage.css"; +import Dashboard from "./Dashboard"; const MainPage = (props) => { - const { category, routes } = props; - if (category === '') return ; + const { category, routes } = props; + if (category === "") return ; - const [projectsData, setProjectsData] = useState([]); - const [tag, setTag] = useState('All'); + const [projectsData, setProjectsData] = useState([]); + const [tag, setTag] = useState("All"); - const getName = (category) => { - let filtered = routes.filter(obj => obj.path === `/${category}`); - return filtered[0].name; - } - const getTech = (category) => { - let filtered = routes.filter(obj => obj.path === `/${category}`); - return filtered[0].tech; - } + const getName = (category) => { + let filtered = routes.filter((obj) => obj.path === `/${category}`); + return filtered[0].name; + }; - useEffect(() => { - const fetchData = async () => { - props.setProgress(10); - try { - const response = await fetch(`https://raw.githubusercontent.com/Avdhesh-Varshney/WebMasterLog/main/database/${category}.json`); - if (!response.ok) { - throw new Error('Failed to fetch projects data'); - } - props.setProgress(30); - const data = await response.json(); - props.setProgress(50); - let filteredData = data; - if (tag !== 'All') { - filteredData = data.filter(project => project.tag === tag); - } - props.setProgress(80); - setProjectsData(filteredData); - } catch (error) { - console.error('Error fetching projects data:', error); - } - props.setProgress(100); - }; - fetchData(); - }, [tag]); + const getTech = (category) => { + let filtered = routes.filter((obj) => obj.path === `/${category}`); + return filtered[0].tech; + }; - const handleTagClick = (selectedTag) => { - setTag(selectedTag); - }; + useEffect(() => { + const fetchData = async () => { + props.setProgress(10); + try { + const response = await fetch( + `https://raw.githubusercontent.com/Avdhesh-Varshney/WebMasterLog/main/database/${category}.json` + ); + if (!response.ok) { + throw new Error("Failed to fetch projects data"); + } + props.setProgress(30); + const data = await response.json(); + props.setProgress(50); + let filteredData = data; + if (tag !== "All") { + filteredData = data.filter((project) => project.tag === tag); + } + props.setProgress(80); + setProjectsData(filteredData); + } catch (error) { + console.error("Error fetching projects data:", error); + } + props.setProgress(100); + }; + fetchData(); + }, [tag, category, props]); - return ( - <> -

{`${getName(category)} Projects`}

-
- - - - -
+ const handleTagClick = (selectedTag) => { + setTag(selectedTag); + }; - - - ); -} + return ( + <> +

{`${getName(category)} Projects`}

+ +
+
+ + + + +
+ +
+ +
+
+ + + + ); +}; export default MainPage; diff --git a/src/components/Pages/mainpage.css b/src/components/Pages/mainpage.css index e69de29b..e9d7043c 100644 --- a/src/components/Pages/mainpage.css +++ b/src/components/Pages/mainpage.css @@ -0,0 +1,17 @@ +/* mainpage.css */ +.button-group { + display: flex; +} + +.dropdown { + display: none; +} + +@media (max-width: 768px) { + .button-group { + display: none; + } + .dropdown { + display: block; + } +}