forked from codeharborhub/codeharborhub.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourcesSection.tsx
More file actions
197 lines (183 loc) · 5.84 KB
/
ResourcesSection.tsx
File metadata and controls
197 lines (183 loc) · 5.84 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import React, { useState } from "react";
import Link from "@docusaurus/Link";
import {
ArrowRightFilled,
ChevronLeftRegular,
ChevronRightRegular,
} from "@fluentui/react-icons";
import "./style.css";
// Interface defining the structure of a resource
interface Resource {
url: string;
type: string;
title: string;
description: string;
image: string;
duration: string;
}
// Array containing all available resources
const ALL_RESOURCES: Resource[] = [
{
url: "https://codeharborhub.github.io/docs/",
type: "tutorial",
title: "Tutorial: For Beginners",
description:
"Get started with CodeHarborHub and learn how to use it to manage your codebases. This tutorial is for beginners.",
image: "/img/resources/tutorials.jpg",
duration: "10 min",
},
{
url: "https://codeharborhub.github.io/courses/",
type: "courses",
title: "Courses: For Advanced Users",
description:
"Learn advanced topics in CodeHarborHub and become a pro. This course is for advanced users.",
image: "/img/resources/courses.jpg",
duration: "3 min",
},
{
url: "https://codeharborhub.github.io/blog/",
type: "blog",
title: "Blog: For All Users",
description:
"Read our blog to get the latest updates, news, and articles on CodeHarborHub.",
image: "/img/resources/blogs.jpg",
duration: "7 min",
},
{
url: "https://codeharborhub.github.io/dsa/",
type: "dsa",
title: "DSA: For Competitive Programmers",
description:
"Prepare for your next coding interview with our Data Structures and Algorithms course.",
image: "/img/resources/dsa.jpg",
duration: "5 min",
},
];
// Component to render each individual resource
function Resource({
type,
url,
image,
title,
description,
duration,
}: Resource) {
return (
<Link className='resource fade-in' key={title} href={url}>
<div>
<div className='resource-image-container'>
<img
src={image}
alt={title}
loading='lazy'
className='resource-image'
/>
</div>
<h3 className='resource-title'>{title}</h3>
<p className='resource-description'>{description}</p>
</div>
<div className='resource-footer'>
<div className='resource-duration'>
{`${duration} ${type === "video" ? "watch" : "read"}`}
</div>
</div>
</Link>
);
}
// Main component for displaying resources and managing pagination
export default function ResourcesSection() {
const [page, setPage] = useState(1); // State to track current page number
const [activeType, setActiveType] = useState<
"all" | "blog" | "tutorial" | "courses" | "dsa"
>("all"); // State to track currently active resource type filter
// Filter resources based on activeType
const resources =
activeType === "all"
? ALL_RESOURCES
: ALL_RESOURCES.filter((r) => r.type === activeType);
// Determine the current set of resources to display based on pagination
const currentResources = resources.slice((page - 1) * 3, page * 3);
// Calculate total number of pages based on the number of resources
const pages = Math.ceil(resources.length / 3);
// Function to navigate to the next page of resources
const nextPage = () => {
if (page < pages) {
setPage(page + 1);
}
};
// Function to navigate to the previous page of resources
const prevPage = () => {
if (page > 1) {
setPage(page - 1);
}
};
return (
<section className='resources-section'>
<div className='resources-container'>
{/* Section header */}
<div className='resources-header'>
<div>
<span className='codeharborhub-badge'>RESOURCES</span>
<h2 className='resources-title'>Want to know more?</h2>
</div>
{/* Link to view all blogs */}
<Link
to='https://codeharborhub.github.io/blog/'
className='resources-all-blogs'>
All Blogs <ArrowRightFilled className='arrow-icon' />
</Link>
</div>
{/* Filter buttons for resource types */}
<div className='resources-filters'>
<button
className={`filter-button ${activeType === "all" ? "active" : ""}`}
onClick={() => setActiveType("all")}>
All
</button>
<button
className={`filter-button ${activeType === "blog" ? "active" : ""}`}
onClick={() => setActiveType("blog")}>
Blogs
</button>
<button
className={`filter-button ${
activeType === "tutorial" ? "active" : ""
}`}
onClick={() => setActiveType("tutorial")}>
Tutorials
</button>
<button
className={`filter-button ${
activeType === "courses" ? "active" : ""
}`}
onClick={() => setActiveType("courses")}>
Courses
</button>
<button
className={`filter-button ${activeType === "dsa" ? "active" : ""}`}
onClick={() => setActiveType("dsa")}>
DSA
</button>
</div>
{/* Displaying the current set of resources */}
<div className='resources-content'>
<div className='resources-grid'>
{currentResources.map((resource, idx) => {
return <Resource {...resource} key={idx} />;
})}
</div>
{/* Pagination controls */}
<div className='pagination'>
<button onClick={prevPage} className='pagination-button'>
<ChevronLeftRegular className='chevron-icon' />
</button>
<button onClick={nextPage} className='pagination-button'>
<ChevronRightRegular className='chevron-icon' />
</button>
</div>
</div>
</div>
</section>
);
}