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

feat: CheatSheet/HackBook | Add Responsive Design #583

Merged
merged 4 commits into from
Feb 5, 2024
Merged
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
112 changes: 74 additions & 38 deletions src/components/CheatSheets/CheatSheet.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { Wrapper } from "../Dashboard/Profile/ProfileElements";
import {
LeftSection,
Expand All @@ -13,9 +13,11 @@ import {
MarkdownPreview,
MarkdownContainer,
ToggleButton,
ResponsiveToggleButton,
HackBookTitleContainer,
} from "./CheatSheetElements";

import { LuPanelRightOpen } from "react-icons/lu";
import { LuPanelBottomOpen, LuPanelBottomClose, LuPanelTopOpen, LuPanelTopClose } from "react-icons/lu";

const CheatSheet = ({ data, heading }) => {
const hackBookData = data;
Expand All @@ -37,6 +39,26 @@ const CheatSheet = ({ data, heading }) => {
setToggle(!toggle);
};

const [isContentNavVisible, setIsContentNavVisible] = useState(true);
useEffect(() => {
const handleResize = () => {
// Set isContentNavVisible to true when window width is greater than or equal to 600px
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the comment "to 800px"

setIsContentNavVisible(window.innerWidth >= 800);
setToggle(true);
};

// Attach the event listener
window.addEventListener("resize", handleResize);

// Initial check for the window width
handleResize();

// Cleanup the event listener on component unmount
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);

const handleFileClick = (title, fileName) => {
const fileContent = hackBookData[title].find((file) => Object.keys(file)[0] === fileName);
setSelectedFile({
Expand All @@ -51,48 +73,62 @@ const CheatSheet = ({ data, heading }) => {
{toggle && (
<LeftSection>
<ContentNav>
<HackBookTitle> {heading} </HackBookTitle>
<ContentNavData>
{Object.keys(hackBookData).map(
(title, id) =>
hackBookData[title].length > 0 && (
<RoadmapDetails key={id}>
<HackBookHeading>
{title.replace(/[^a-zA-Z0-9]+/g, " ")}
</HackBookHeading>
{hackBookData[title].map(
(file, fileId) =>
Object.keys(file)[0].endsWith(".md") && (
<RoadmapDetailsCard
key={fileId}
isSelected={
selectedFile &&
selectedFile.name === Object.keys(file)[0]
}
onClick={() =>
handleFileClick(title, Object.keys(file)[0])
}
>
{
Object.keys(file)[0]
.replace(/.md/g, "")
.replace(/[^a-zA-Z0-9]+/g, " ")
// .toLowerCase()
}
</RoadmapDetailsCard>
),
)}
</RoadmapDetails>
),
)}
</ContentNavData>
<HackBookTitleContainer>
<HackBookTitle> {heading} </HackBookTitle>
<ResponsiveToggleButton onClick={() => setIsContentNavVisible(!isContentNavVisible)}>
{isContentNavVisible ? (
<LuPanelTopClose fontSize={"24px"} />
) : (
<LuPanelTopOpen fontSize={"24px"} />
)}
</ResponsiveToggleButton>
</HackBookTitleContainer>
{isContentNavVisible && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you find the reason that on default this section is closing right away without clicking on the button?

Recording.2024-02-02.170855.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this, was that initially the code was setIsContentNavVisible(window.innerWidth >= 800); so whenever the screen becomes small it defaults to false, so it can be changed to
if (window.innerWidth >= 800) { setIsContentNavVisible(true); setToggle(true);} , so the first thing we see on mobile screens is the index.

<ContentNavData>
{Object.keys(hackBookData).map(
(title, id) =>
hackBookData[title].length > 0 && (
<RoadmapDetails key={id}>
<HackBookHeading>
{title.replace(/[^a-zA-Z0-9]+/g, " ")}
</HackBookHeading>
{hackBookData[title].map(
(file, fileId) =>
Object.keys(file)[0].endsWith(".md") && (
<RoadmapDetailsCard
key={fileId}
isSelected={
selectedFile &&
selectedFile.name === Object.keys(file)[0]
}
onClick={() => {
handleFileClick(title, Object.keys(file)[0]);
if (window.innerWidth < 800) {
setIsContentNavVisible(false);
}
}}
>
{
Object.keys(file)[0]
.replace(/.md/g, "")
.replace(/[^a-zA-Z0-9]+/g, " ")
// .toLowerCase()
}
</RoadmapDetailsCard>
),
)}
</RoadmapDetails>
),
)}
</ContentNavData>
)}
</ContentNav>
</LeftSection>
)}

<ContentData>
<ToggleButton onClick={handleToggle} size={20}>
<LuPanelRightOpen />
{toggle ? <LuPanelBottomOpen fontSize={"20px"} /> : <LuPanelBottomClose fontSize={"20px"} />}
</ToggleButton>
{selectedFile && (
<MarkdownContainer>
Expand Down
39 changes: 33 additions & 6 deletions src/components/CheatSheets/CheatSheetElements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const LeftSection = styled.div`
width: 100%;
flex: 1;

@media (max-width: 600px) {
@media (max-width: 800px) {
max-width: 100%;
}
`;
Expand All @@ -22,21 +22,26 @@ export const HackBookContainer = styled.div`
height: 100%;
max-width: 1500px;

@media (max-width: 600px) {
@media (max-width: 800px) {
/* Adjust styles for smaller screens */
flex-direction: column;
max-width: 100%;
}
`;

export const HackBookTitle = styled.h1`
display: flex;
width: 100%;
font-size: 24px;
padding: 15px 25px;
text-align: center;
margin-top: 7.5px;

align-content: center;
justify-content: center;
background: #2f2f2f;
font-family: "Poppins", sans-serif;
@media (max-width: 800px) {
width: 95%;
}
`;

export const HackBookHeading = styled.p`
Expand Down Expand Up @@ -120,14 +125,15 @@ export const ContentData = styled.div`
flex-direction: column;
align-content: center;
width: 100%;
min-width: 200px;
max-width: 1200px;
border: #2f2f2f 1px solid;
border-radius: 0 10px 10px 0;
margin: 0 auto;
height: 100%;

@media (max-width: 600px) {
max-width: 100%;
@media (max-width: 800px) {
max-width: 98%;
border-radius: 0;
}
`;
Expand Down Expand Up @@ -190,3 +196,24 @@ export const ToggleButton = styled.button`
display: block;
}
`;
export const ResponsiveToggleButton = styled.button`
display: none;
width: 10%;
@media (max-width: 800px) {
display: flex;
justify-content: flex-end;
align-items: center;
cursor: pointer;
color: #f5f5f5;
cursor: pointer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cursor: pointer;

you accidentally wrote it twice

z-index: 1;
text-align: center;
padding-right: 10px;
}
`;

export const HackBookTitleContainer = styled.div`
display: flex;
background: #2f2f2f;
height: 50px;
`;
2 changes: 1 addition & 1 deletion src/components/Dashboard/Profile/ProfileElements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Wrapper = styled.div`
justify-content: center;
align-items: center;
padding: 0 25px;

overflow-x: hidden;
@media screen and (max-width: 760px) {
}
`;
Expand Down