-
Notifications
You must be signed in to change notification settings - Fork 0
/
blogTemplate.jsx
126 lines (115 loc) · 4.18 KB
/
blogTemplate.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { useEffect, useState } from "react";
import Navbar from "../../../../../components/Navbar/Navbar";
import BlogsFooter from "../../../../../components/BlogsFooter/BlogsFooter";
import Footer from "../../../../../components/Footer/Footer";
import { blogPost } from "../../../../../data/BlogsData";
import LeftSidebar from "../../../../../components/LeftSideBar/LeftSidebar";
import { Link } from "react-router-dom";
import "../../Blogs.scss";
import { animated, useSpring } from "react-spring";
const NEWBLOG = ({
openCMDCenter,
controlMusic,
isMusicPlaying,
theme,
toggleTheme,
}) => {
const [currBlog, setCurrBlog] = useState(null);
const [activeSection, setActiveSection] = useState(null);
const [scrollPercentage, setScrollPercentage] = useState(0);
const [isSidebarVisible, setIsSidebarVisible] = useState(true);
useEffect(() => {
window.scrollTo(0, 0);
setCurrBlog(
blogPost.find((blog) => {
/* ==========================================================
! Change this to the blog number of the new blog
========================================================== */
return blog.blogNo === 3;
})
);
}, [currBlog]);
const sidebarAnimation = useSpring({
opacity: isSidebarVisible ? 1 : 0,
config: { tension: 100, friction: 50 },
});
const handleScroll = (e) => {
const { scrollHeight, scrollTop, clientHeight } = document.documentElement;
const fullHeight = scrollHeight - clientHeight;
const scrolled = (scrollTop / fullHeight) * 100;
setScrollPercentage(scrolled);
// Determine the active section based on scroll position
const sections = document.querySelectorAll(".blog-section");
sections.forEach((section, index) => {
const { offsetTop, offsetHeight } = section;
if (
scrollTop >= offsetTop - 300 &&
scrollTop < offsetTop + offsetHeight - 300
) {
setActiveSection(index);
}
});
// Determine if the sidebar should be visible
setIsSidebarVisible(scrolled < 100);
};
useEffect(() => {
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
});
/* ==========================================================
! Please make sure you have at max 8 sections in the array
========================================================== */
const sections = [];
return (
<>
<Navbar
openCMDCenter={openCMDCenter}
controlMusic={controlMusic}
isMusicPlaying={isMusicPlaying}
theme={theme}
pageTitle={currBlog?.blogTitle}
/>
<div className="page blog-series-page">
<animated.div className="left-sidebar" style={sidebarAnimation}>
{isSidebarVisible && (
<LeftSidebar
scrollPercentage={scrollPercentage}
activeSection={activeSection}
sections={sections}
setActiveSection={setActiveSection}
/>
)}
</animated.div>
<div className="section-top">
<Link to={currBlog?.seriesUrl}>
<i className="fa-solid fa-arrow-left-long back-link"></i>
Journey
</Link>
<div className="container">
<div className="blog-series-header">
<h1>{currBlog?.blogTitle}</h1>
<div className="div-flex-row">
<p className="blog-date">
📆 Published on: {currBlog?.blogDate}
</p>
<p className="blog-date">
🤓 Readtime (Approx): {currBlog?.readtime}
</p>
</div>
</div>
</div>
{/* Blog series poster */}
<div className="main-blog-content" onScroll={handleScroll}>
{/* ==========================================================
! Change the content of the new blog here
========================================================== */}
<p className="open-txt">THIS IS NEW BLOG</p>
</div>
</div>
</div>
<BlogsFooter theme={theme} />
<Footer toggleTheme={toggleTheme} />
</>
);
};
export default NEWBLOG;