-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/hero la liga #106
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
Merged
Merged
Feat/hero la liga #106
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
deeb6cb
[Feat]: League hero
Samu-Kiss 180501e
[Feat]: Video bg
Samu-Kiss a4e71b6
[Fix]: Carga de video en caché
Samu-Kiss c201816
Merge branch 'feat/hero-la-liga' of github.com:CapituloJaverianoACM/A…
TalkySafe143 96dfd9f
Fix: hero component and adds particle utility
Samu-Kiss edbe5dc
Merge branch 'develop' of github.com:CapituloJaverianoACM/ACM-Web-Pag…
adrianrrruiz b907b09
[Fix]: Video always going to fallback
Samu-Kiss dd71299
Merge branch 'feat/hero-la-liga' of github.com:CapituloJaverianoACM/A…
TalkySafe143 6ab2b1d
[Fix]: Mobile visibility
Samu-Kiss 22109c6
Merge branch 'feat/hero-la-liga' of github.com:CapituloJaverianoACM/A…
TalkySafe143 285d7d2
Deleted comments
TalkySafe143 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Proxy route to serve the hero background video with cache and range support | ||
| // This improves reliability and allows us to control caching headers from our origin. | ||
|
|
||
| import type { NextRequest } from "next/server"; | ||
|
|
||
| const EXTERNAL_VIDEO_MP4 = | ||
| "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; | ||
|
|
||
| export async function GET(req: NextRequest) { | ||
| try { | ||
| const range = req.headers.get("range") ?? undefined; | ||
|
|
||
| const upstream = await fetch(EXTERNAL_VIDEO_MP4, { | ||
| // Forward Range requests for seeking/streaming | ||
| headers: range ? { range } : undefined, | ||
| // Let the CDN/browser cache it; also allow Next caching | ||
| // Note: next.revalidate doesn't affect opaque streams, but it's fine. | ||
| next: { revalidate: 60 * 60 * 24 }, | ||
| }); | ||
|
|
||
| if (!upstream.ok && upstream.status !== 206) { | ||
| return new Response("Upstream error", { status: upstream.status }); | ||
| } | ||
|
|
||
| // Copy relevant headers through and set strong caching | ||
| const headers = new Headers(); | ||
| const copy = [ | ||
| "content-type", | ||
| "content-length", | ||
| "accept-ranges", | ||
| "content-range", | ||
| "etag", | ||
| "last-modified", | ||
| ]; | ||
| for (const h of copy) { | ||
| const v = upstream.headers.get(h); | ||
| if (v) headers.set(h, v); | ||
| } | ||
|
|
||
| // Our cache policy (1 day, with SWR) | ||
| headers.set( | ||
| "cache-control", | ||
| "public, max-age=86400, s-maxage=86400, stale-while-revalidate=604800" | ||
| ); | ||
|
|
||
| // Allow range responses to pass through | ||
| if (!headers.has("accept-ranges")) headers.set("accept-ranges", "bytes"); | ||
|
|
||
| return new Response(upstream.body, { | ||
| status: upstream.status, | ||
| headers, | ||
| }); | ||
| } catch { | ||
| return new Response("Video proxy failed", { status: 502 }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,253 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useRef, useState } from "react"; | ||
|
|
||
| export function Hero() { | ||
| const particlesRef = useRef<HTMLDivElement | null>(null); | ||
| const heroRef = useRef<HTMLElement | null>(null); | ||
| const titleRef = useRef<HTMLHeadingElement | null>(null); | ||
| const subtitleRef = useRef<HTMLHeadingElement | null>(null); | ||
| const videoRef = useRef<HTMLVideoElement | null>(null); | ||
| const [videoVisible, setVideoVisible] = useState(false); | ||
| // Use cached proxy route for the hero video | ||
| const videoUrl = "/api/hero-video"; | ||
|
|
||
| // Typing animation util | ||
| function typeText( | ||
| el: HTMLElement, | ||
| text: string, | ||
| speed = 30, | ||
| onDone?: () => void | ||
| ) { | ||
| let i = 0; | ||
| el.innerHTML = ""; | ||
| const cursor = document.createElement("span"); | ||
| cursor.className = "typing-cursor"; | ||
| cursor.textContent = "|"; | ||
| el.appendChild(cursor); | ||
|
|
||
| const tick = () => { | ||
| if (i < text.length) { | ||
| cursor.before(document.createTextNode(text[i])); | ||
| i++; | ||
| setTimeout(tick, speed); | ||
| } else { | ||
| cursor.remove(); | ||
| onDone?.(); | ||
| } | ||
| }; | ||
|
|
||
| tick(); | ||
| } | ||
TalkySafe143 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| // Try to play video background (fallback to CSS if fails) | ||
| const v = videoRef.current; | ||
| if (!videoUrl || !v) return; | ||
|
|
||
| const onLoaded = () => setVideoVisible(true); | ||
| const onError = () => setVideoVisible(false); | ||
|
|
||
| v.addEventListener("loadeddata", onLoaded); | ||
| v.addEventListener("error", onError); | ||
|
|
||
| // Attempt to play (muted + playsInline should allow autoplay) | ||
| try { | ||
| const maybePromise = v.play(); | ||
| if (maybePromise && typeof (maybePromise as Promise<void>).then === "function") { | ||
| (maybePromise as Promise<void>).catch(() => { | ||
| // Ignore autoplay rejection; keep showing the first frame | ||
| }); | ||
| } | ||
| } catch { | ||
| // Ignore; fallback handled by safety timeout and error event | ||
| } | ||
|
|
||
| // Safety timeout: if it doesn't get ready in time, fallback | ||
| const readyTimeout = window.setTimeout(() => { | ||
| if (v.readyState < 2) setVideoVisible(false); | ||
| }, 4000); | ||
|
|
||
| return () => { | ||
| v.removeEventListener("loadeddata", onLoaded); | ||
| v.removeEventListener("error", onError); | ||
| window.clearTimeout(readyTimeout); | ||
| }; | ||
| }, [videoUrl]); | ||
|
|
||
| useEffect(() => { | ||
| // Toggle helper class on hero when video is visible to soften overlays | ||
| const el = heroRef.current; | ||
| if (!el) return; | ||
| if (videoVisible) el.classList.add("has-video"); | ||
| else el.classList.remove("has-video"); | ||
| }, [videoVisible]); | ||
|
|
||
| useEffect(() => { | ||
| // Particles | ||
| const container = particlesRef.current; | ||
| if (!container) return; | ||
|
|
||
| const codeElements = [ | ||
| "for()", | ||
| "while()", | ||
| "if()", | ||
| "class", | ||
| "function", | ||
| "return", | ||
| "var", | ||
| "let", | ||
| "const", | ||
| "{}", | ||
| "[]", | ||
| "()", | ||
| "=>", | ||
| "==", | ||
| "!=", | ||
| "++", | ||
| "--", | ||
| "&&", | ||
| "||", | ||
| "int", | ||
| "string", | ||
| "bool", | ||
| "array", | ||
| "list", | ||
| "dict", | ||
| "map", | ||
| ]; | ||
|
|
||
| const particles: HTMLElement[] = []; | ||
|
|
||
| const addParticle = () => { | ||
| const p = document.createElement("div"); | ||
| p.className = "particle"; | ||
| p.textContent = | ||
| codeElements[Math.floor(Math.random() * codeElements.length)]; | ||
| p.style.left = Math.random() * 100 + "vw"; | ||
| p.style.animationDelay = Math.random() * 2 + "s"; | ||
| p.style.animationDuration = Math.random() * 10 + 10 + "s"; | ||
|
|
||
| container.appendChild(p); | ||
| particles.push(p); | ||
|
|
||
| // remove after animation | ||
| window.setTimeout(() => { | ||
| if (p.parentNode) p.parentNode.removeChild(p); | ||
| }, 25000); | ||
| }; | ||
|
|
||
| // initial particles | ||
| for (let i = 0; i < 5; i++) setTimeout(addParticle, i * 500); | ||
| const id = window.setInterval(addParticle, 2000); | ||
|
|
||
| return () => { | ||
| window.clearInterval(id); | ||
| particles.forEach((p) => p.remove()); | ||
| }; | ||
| }, []); | ||
TalkySafe143 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| // Typing sequence | ||
| const titleEl = titleRef.current; | ||
| const subtitleEl = subtitleRef.current; | ||
| if (!titleEl || !subtitleEl) return; | ||
|
|
||
| const timeoutId = window.setTimeout(() => { | ||
| typeText(titleEl, "La Liga", 30, () => { | ||
| window.setTimeout(() => typeText(subtitleEl, "Javeriana de Programación", 30), 300); | ||
| }); | ||
| }, 2000); | ||
|
|
||
| return () => window.clearTimeout(timeoutId); | ||
| }, []); | ||
|
|
||
| return ( | ||
| // Por ahora poner algo que ocupe un poco de espacio | ||
| <div className="h-[50dvh]"></div> | ||
| <section ref={heroRef} className="league-hero"> | ||
| {/* background video layer (fallback to CSS background if hidden) */} | ||
| {videoUrl ? ( | ||
| <div className={`hero-video-bg ${videoVisible ? "is-visible" : ""}`}> | ||
| <video | ||
| ref={videoRef} | ||
| src={videoUrl} | ||
| muted | ||
| autoPlay | ||
| loop | ||
| playsInline | ||
| preload="auto" | ||
| crossOrigin="anonymous" | ||
| aria-hidden="true" | ||
| /> | ||
| </div> | ||
| ) : null} | ||
|
|
||
| {/* dynamic particles layer */} | ||
| <div ref={particlesRef} className="code-particles" /> | ||
|
|
||
| {/* geometric background shapes */} | ||
| <div className="geometric-bg"> | ||
| <div className="geometric-shape shape-1" /> | ||
| <div className="geometric-shape shape-2" /> | ||
| <div className="geometric-shape shape-3" /> | ||
| <div className="geometric-shape shape-4" /> | ||
| </div> | ||
|
|
||
| {/* decorative code snippets */} | ||
| <div className="code-snippet code-1"> | ||
| {"while(true) {"} | ||
| <br /> | ||
| solve(); | ||
| <br /> | ||
| compete(); | ||
| <br /> | ||
| {"}"} | ||
| </div> | ||
|
|
||
| <div className="code-snippet code-2"> | ||
| {"def javeriana():"} | ||
| <br /> | ||
| return "excellence" | ||
| </div> | ||
|
|
||
| <div className="code-snippet code-3"> | ||
| {"#include <passion>"} | ||
| <br /> | ||
| {"#include <code>"} | ||
| </div> | ||
|
|
||
| <div className="hero-content"> | ||
| <h1 ref={titleRef} className="league-title" /> | ||
| <h2 ref={subtitleRef} className="league-subtitle" /> | ||
|
|
||
| <p className="league-text"> | ||
| Donde los algoritmos cobran vida y la pasión por el código nos une | ||
| </p> | ||
|
|
||
| <div className="cta-buttons"> | ||
| <a href="#" className="btn btn--niebla"> | ||
| 🚀 Únete a la Liga | ||
| </a> | ||
| <a href="#upcoming-events" className="btn btn--niebla"> | ||
| 📊 Ver Competencias | ||
| </a> | ||
| </div> | ||
|
|
||
| {/*TODO: ESTAS STATS SON DE EJEMPLO, CAMBIARLAS DESPUÉS PARA QUE MUESTREN DATOS REALES, PUEDE SER DE LA DB*/} | ||
| <div className="stats"> | ||
| <div className="stat-item"> | ||
| <span className="stat-number">500+</span> | ||
| <span className="stat-label">Participantes</span> | ||
| </div> | ||
| <div className="stat-item"> | ||
| <span className="stat-number">50+</span> | ||
| <span className="stat-label">Competencias</span> | ||
| </div> | ||
| <div className="stat-item"> | ||
| <span className="stat-number">10+</span> | ||
| <span className="stat-label">Años de Historia</span> | ||
| </div> | ||
TalkySafe143 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.