|
| 1 | +import Link from "@docusaurus/Link"; |
| 2 | +import React, { useState } from "react"; |
| 3 | +import "./style.css"; |
| 4 | +import { |
| 5 | + ArrowRightFilled, |
| 6 | + ChevronLeftRegular, |
| 7 | + ChevronRightRegular, |
| 8 | +} from "@fluentui/react-icons"; |
| 9 | + |
| 10 | +interface Resource { |
| 11 | + url: string; |
| 12 | + type: string; |
| 13 | + title: string; |
| 14 | + description: string; |
| 15 | + image: string; |
| 16 | + duration: string; |
| 17 | +} |
| 18 | + |
| 19 | +const ALL_RESOURCES: Resource[] = [ |
| 20 | + { |
| 21 | + url: "https://www.codeharborhub.live/docs/", |
| 22 | + type: "tutorial", |
| 23 | + title: "Tutorial: For Beginners", |
| 24 | + description: |
| 25 | + "Get started with CodeHarborHub and learn how to use it to manage your codebases. This tutorial is for beginners.", |
| 26 | + image: "/img/resources/tutorials.jpg", |
| 27 | + duration: "10 min", |
| 28 | + }, |
| 29 | + { |
| 30 | + url: "https://www.codeharborhub.live/courses/", |
| 31 | + type: "courses", |
| 32 | + title: "Courses: For Advanced Users", |
| 33 | + description: |
| 34 | + "Learn advanced topics in CodeHarborHub and become a pro. This course is for advanced users.", |
| 35 | + image: "/img/resources/courses.jpg", |
| 36 | + duration: "3 min", |
| 37 | + }, |
| 38 | + { |
| 39 | + url: "https://www.codeharborhub.live/blog/", |
| 40 | + type: "blog", |
| 41 | + title: "Blog: For All Users", |
| 42 | + description: |
| 43 | + "Read our blog to get the latest updates, news, and articles on CodeHarborHub.", |
| 44 | + image: "/img/resources/blogs.jpg", |
| 45 | + duration: "7 min", |
| 46 | + }, |
| 47 | + { |
| 48 | + url: "https://www.codeharborhub.live/dsa/", |
| 49 | + type: "dsa", |
| 50 | + title: "DSA: For Competitive Programmers", |
| 51 | + description: |
| 52 | + "Prepare for your next coding interview with our Data Structures and Algorithms course.", |
| 53 | + image: "/img/resources/dsa.jpg", |
| 54 | + duration: "5 min", |
| 55 | + }, |
| 56 | +]; |
| 57 | + |
| 58 | +function Resource({ |
| 59 | + type, |
| 60 | + url, |
| 61 | + image, |
| 62 | + title, |
| 63 | + description, |
| 64 | + duration, |
| 65 | +}: Resource) { |
| 66 | + return ( |
| 67 | + <Link className="resource fade-in" key={title} href={url}> |
| 68 | + <div> |
| 69 | + <div className="resource-image-container"> |
| 70 | + <img |
| 71 | + src={image} |
| 72 | + alt={title} |
| 73 | + loading="lazy" |
| 74 | + className="resource-image" |
| 75 | + /> |
| 76 | + </div> |
| 77 | + <h3 className="resource-title">{title}</h3> |
| 78 | + <p className="resource-description">{description}</p> |
| 79 | + </div> |
| 80 | + <div className="resource-footer"> |
| 81 | + <div className="resource-duration"> |
| 82 | + {`${duration} ${type === "video" ? "watch" : "read"}`} |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </Link> |
| 86 | + ); |
| 87 | +} |
| 88 | + |
| 89 | +export default function ResourcesSection() { |
| 90 | + const [page, setPage] = useState(1); |
| 91 | + const [activeType, setActiveType] = useState< |
| 92 | + "all" | "blog" | "tutorial" | "courses" | "dsa" |
| 93 | + >("all"); |
| 94 | + |
| 95 | + const resources = |
| 96 | + activeType === "all" |
| 97 | + ? ALL_RESOURCES |
| 98 | + : ALL_RESOURCES.filter((r) => r.type === activeType); |
| 99 | + |
| 100 | + const currentResources = resources.slice((page - 1) * 3, page * 3); |
| 101 | + |
| 102 | + const pages = Math.ceil(resources.length / 3); |
| 103 | + |
| 104 | + const nextPage = () => { |
| 105 | + if (page < pages) { |
| 106 | + setPage(page + 1); |
| 107 | + } |
| 108 | + }; |
| 109 | + |
| 110 | + const prevPage = () => { |
| 111 | + if (page > 1) { |
| 112 | + setPage(page - 1); |
| 113 | + } |
| 114 | + }; |
| 115 | + |
| 116 | + return ( |
| 117 | + <section className="resources-section"> |
| 118 | + <div className="resources-container"> |
| 119 | + <div className="resources-header"> |
| 120 | + <div> |
| 121 | + <span className="codeharborhub-badge">RESOURCES</span> |
| 122 | + <h2 className="resources-title">Want to know more?</h2> |
| 123 | + </div> |
| 124 | + <Link to="/blog" className="resources-all-blogs"> |
| 125 | + All Blogs <ArrowRightFilled className="arrow-icon" /> |
| 126 | + </Link> |
| 127 | + </div> |
| 128 | + |
| 129 | + <div className="resources-filters bg-secondary-700"> |
| 130 | + <button |
| 131 | + className={`filter-button ${activeType === "all" ? "active" : ""}`} |
| 132 | + onClick={() => setActiveType("all")} |
| 133 | + > |
| 134 | + All |
| 135 | + </button> |
| 136 | + <button |
| 137 | + className={`filter-button ${activeType === "blog" ? "active" : ""}`} |
| 138 | + onClick={() => setActiveType("blog")} |
| 139 | + > |
| 140 | + Blogs |
| 141 | + </button> |
| 142 | + <button |
| 143 | + className={`filter-button ${ |
| 144 | + activeType === "tutorial" ? "active" : "" |
| 145 | + }`} |
| 146 | + onClick={() => setActiveType("tutorial")} |
| 147 | + > |
| 148 | + Tutorials |
| 149 | + </button> |
| 150 | + <button |
| 151 | + className={`filter-button ${ |
| 152 | + activeType === "courses" ? "active" : "" |
| 153 | + }`} |
| 154 | + onClick={() => setActiveType("courses")} |
| 155 | + > |
| 156 | + Courses |
| 157 | + </button> |
| 158 | + <button |
| 159 | + className={`filter-button ${activeType === "dsa" ? "active" : ""}`} |
| 160 | + onClick={() => setActiveType("dsa")} |
| 161 | + > |
| 162 | + DSA |
| 163 | + </button> |
| 164 | + </div> |
| 165 | + |
| 166 | + <div className="resources-content"> |
| 167 | + <div className="resources-grid"> |
| 168 | + {currentResources.map((resource, idx) => { |
| 169 | + return <Resource {...resource} key={idx} />; |
| 170 | + })} |
| 171 | + </div> |
| 172 | + |
| 173 | + <div className="pagination"> |
| 174 | + <button onClick={prevPage} className="pagination-button"> |
| 175 | + <ChevronLeftRegular className="chevron-icon" /> |
| 176 | + </button> |
| 177 | + |
| 178 | + <button onClick={nextPage} className="pagination-button"> |
| 179 | + <ChevronRightRegular className="chevron-icon" /> |
| 180 | + </button> |
| 181 | + </div> |
| 182 | + </div> |
| 183 | + </div> |
| 184 | + </section> |
| 185 | + ); |
| 186 | +} |
0 commit comments