Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created drop down menu for responsive devices and hide that menu in l… #186

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 104 additions & 56 deletions src/components/Pages/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -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 <Dashboard />;
const { category, routes } = props;
if (category === "") return <Dashboard />;

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 (
<>
<h1 className='text-end my-2 mx-3'>{`${getName(category)} Projects`}</h1>
<div className="d-flex justify-content-end my-2 mx-3">
<button type="button" className={`btn btn${tag !== 'Basic'? '-outline': ''}-success mx-1`} onClick={() => handleTagClick('Basic')}>Easy</button>
<button type="button" className={`btn btn${tag !== 'Intermediate'? '-outline': ''}-warning mx-1`} onClick={() => handleTagClick('Intermediate')}>Medium</button>
<button type="button" className={`btn btn${tag !== 'Advanced'? '-outline': ''}-danger mx-1`} onClick={() => handleTagClick('Advanced')}>Hard</button>
<button type="button" className={`btn btn${tag !== 'All'? '-outline': ''}-info mx-1`} onClick={() => handleTagClick('All')}>All</button>
</div>
const handleTagClick = (selectedTag) => {
setTag(selectedTag);
};

<ProjectCards projectsData={projectsData} tech={getTech(category)} />
</>
);
}
return (
<>
<h1 className="text-end my-2 mx-3">{`${getName(category)} Projects`}</h1>

<div className="d-flex justify-content-end my-2 mx-3">
<div className="button-group">
<button
type="button"
className={`btn btn${
tag !== "Basic" ? "-outline" : ""
}-success mx-1`}
onClick={() => handleTagClick("Basic")}
>
Easy
</button>
<button
type="button"
className={`btn btn${
tag !== "Intermediate" ? "-outline" : ""
}-warning mx-1`}
onClick={() => handleTagClick("Intermediate")}
>
Medium
</button>
<button
type="button"
className={`btn btn${
tag !== "Advanced" ? "-outline" : ""
}-danger mx-1`}
onClick={() => handleTagClick("Advanced")}
>
Hard
</button>
<button
type="button"
className={`btn btn${tag !== "All" ? "-outline" : ""}-info mx-1`}
onClick={() => handleTagClick("All")}
>
All
</button>
</div>

<div className="dropdown">
<select
className="dropdown form-select "
onChange={(e) => handleTagClick(e.target.value)}
>
<option value="Basic">Easy</option>
<option value="Intermediate">Medium</option>
<option value="Advanced">Hard</option>
<option value="All">All</option>
</select>
</div>
</div>

<ProjectCards projectsData={projectsData} tech={getTech(category)} />
</>
);
};

export default MainPage;
17 changes: 17 additions & 0 deletions src/components/Pages/mainpage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* mainpage.css */
.button-group {
display: flex;
}

.dropdown {
display: none;
}

@media (max-width: 768px) {
.button-group {
display: none;
}
.dropdown {
display: block;
}
}