Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/components/hero.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const HeroSection = () => {
</div>
))}
</div>
<span>1,000+ Active Learners</span>
<span>10,000+ Active Learners</span>
</div>
<div className="flex items-center gap-2">
<svg
Expand Down
12 changes: 10 additions & 2 deletions app/components/ui/DailyDSAEmbed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ const FALLBACK_HEIGHT = 350;

// `bordered` mirrors NewsletterEmbed: defaults to true so existing placements
// are untouched, opt out per usage.
const DailyDSAEmbed = ({ mobile = false, theme = "light", bordered = true }) => {
// `eager` opts out of lazy loading. Inside the mobile carousel the iframe can
// be scrolled past while it is the inactive slide, and a lazy iframe that never
// intersected the viewport stays on about:blank — an empty dashed box.
const DailyDSAEmbed = ({
mobile = false,
theme = "light",
bordered = true,
eager = false,
}) => {
const [height, setHeight] = useState(FALLBACK_HEIGHT);
const iframeRef = useRef(null);

Expand Down Expand Up @@ -48,7 +56,7 @@ const DailyDSAEmbed = ({ mobile = false, theme = "light", bordered = true }) =>
bordered ? "rounded-none border border-dashed border-black" : "border-0"
}`}
title="Daily DSA Challenge"
loading="lazy"
loading={eager ? "eager" : "lazy"}
></iframe>
</div>
</div>
Expand Down
154 changes: 154 additions & 0 deletions app/components/ui/MobileEmbedCarousel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"use client";

import { useEffect, useRef, useState } from "react";
import DailyDSAEmbed from "@/app/components/ui/DailyDSAEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";

/**
* Phone-only carousel for the partner embeds.
*
* On desktop these sit stacked in the sidebar. On a phone the grid collapses to
* one column and stacking them means a long scroll past content the reader did
* not come for, so instead one slot cycles through them on its own.
*
* The newsletter embed is deliberately not in here — it stays desktop-only.
*
* Slides are stacked in a single CSS grid cell rather than laid side by side.
* That makes the container as tall as the tallest slide, so swapping slides
* never changes the page height — important when one slide is an iframe that
* reports its own height after load.
*/

// How long each slide stays up. One number, change it here.
const ROTATE_MS = 5000;

const SLIDES = [
{
id: "daily-dsa",
label: "Daily DSA challenge",
// eager: a lazy iframe that is scrolled past while it is the hidden slide
// never leaves about:blank, which shows up as an empty box.
// bordered={false}: matches the desktop sidebar, no dashed frame.
render: (theme) => (
<DailyDSAEmbed mobile eager bordered={false} theme={theme} />
),
},
{
id: "backend-engineer",
label: "Backend Engineer",
render: (theme) => (
<BackendEngineerCard
theme={theme}
utmContent="mobile-carousel"
// Must not collide with the sidebar card's default id on the same page.
targetId="be-mobile-carousel"
// No bottom margin: it would throw off the vertical centring, and the
// carousel supplies the spacing below the slide itself.
className=""
/>
),
},
];

export default function MobileEmbedCarousel({ theme = "light" }) {
const [index, setIndex] = useState(0);
// Hiding with CSS alone still downloads the iframe on desktop, so the slides
// are not mounted at all until we know this is a phone.
const [isPhone, setIsPhone] = useState(false);
const [paused, setPaused] = useState(false);
const [reducedMotion, setReducedMotion] = useState(false);

useEffect(() => {
const mq = window.matchMedia("(max-width: 767px)");
const update = () => setIsPhone(mq.matches);
update();
mq.addEventListener("change", update);
return () => mq.removeEventListener("change", update);
}, []);

useEffect(() => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
const update = () => setReducedMotion(mq.matches);
update();
mq.addEventListener("change", update);
return () => mq.removeEventListener("change", update);
}, []);

// A backgrounded tab should not keep cycling.
useEffect(() => {
const onVisibility = () => setPaused(document.hidden);
document.addEventListener("visibilitychange", onVisibility);
return () => document.removeEventListener("visibilitychange", onVisibility);
}, []);

useEffect(() => {
if (!isPhone || paused || SLIDES.length < 2) return;
const timer = setInterval(
() => setIndex((i) => (i + 1) % SLIDES.length),
ROTATE_MS
);
return () => clearInterval(timer);
}, [isPhone, paused]);

if (!isPhone) return null;

return (
<section
className="block w-full md:hidden"
aria-roledescription="carousel"
aria-label="Partner embeds"
// Stop rotating while the reader is actually interacting with a slide,
// otherwise it can swap out from under a tap.
onPointerDown={() => setPaused(true)}
onPointerUp={() => setPaused(false)}
onFocusCapture={() => setPaused(true)}
onBlurCapture={() => setPaused(false)}
>
{/* A sliding track, not a stack of faded layers. Stacking the slides and
fading between them left the hidden one's cross-origin iframe parked
on about:blank — it never navigated, so the slide came back as an
empty box. Here every slide stays in normal flow and is merely
clipped, so each one loads and paints exactly as it would on its own.

`items-center` keeps the shorter card centred against the taller
slide, and the track's height is the tallest slide's, so nothing
below it moves when the slide changes. */}
<div className="overflow-hidden">
<div
className={`flex items-center ${
reducedMotion ? "" : "transition-transform duration-500 ease-out"
}`}
style={{ transform: `translateX(-${index * 100}%)` }}
>
{SLIDES.map((slide) => (
<div key={slide.id} className="w-full min-w-0 shrink-0">
{slide.render(theme)}
</div>
))}
</div>
</div>

<div className="mb-4 flex items-center justify-center gap-1">
{SLIDES.map((slide, i) => (
<button
key={slide.id}
type="button"
onClick={() => setIndex(i)}
aria-label={`Show ${slide.label}`}
aria-current={i === index}
// 44px touch target around a small visual dot.
className="flex h-11 w-11 items-center justify-center focus-visible:outline-none"
>
<span
className={`h-1.5 rounded-full transition-all duration-200 ${
i === index
? "w-5 bg-blue-500"
: "w-1.5 bg-gray-300 dark:bg-gray-600"
}`}
/>
</button>
))}
</div>
</section>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// The three steps drawn as one picture: a problem splitting into subproblems,
// those being solved, and the answers flowing back up. Seeing the shape once
Expand Down Expand Up @@ -644,8 +645,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// The real cost of the first 32 appends to a doubling array: mostly 1, with a
// spike every power of two. Seeing the spikes next to the flat amortized line
Expand Down Expand Up @@ -694,8 +695,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// Plots f(n) against a scaled bound c*g(n) so the reader can see what "for all
// n >= n0" actually means: the bound only has to hold to the right of n0.
Expand Down Expand Up @@ -843,8 +844,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

const Section = ({ title, children }) => (
<section className="p-6 border-b border-gray-100 dark:border-gray-700 last:border-b-0">
Expand Down Expand Up @@ -699,8 +700,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// A three-level recursion tree for T(n) = a*T(n/b) + f(n). Seeing that every
// level costs the same amount is what makes the n log n result obvious.
Expand Down Expand Up @@ -660,8 +661,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// A recursion tree drawn from a level description. Each node carries the size
// of its subproblem; the right-hand column carries what that whole level costs,
Expand Down Expand Up @@ -710,8 +711,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@/app/contexts/ThemeContext";
import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

// The method is a loop, not a straight line: a failed proof sends you back to
// strengthen the guess rather than to abandon it. The diagram makes that cycle
Expand Down Expand Up @@ -662,8 +663,7 @@ const Content = () => {
/>
</Section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
4 changes: 2 additions & 2 deletions app/visualizer/graph/algorithms/dijkstra/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import { motion } from "framer-motion";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

const WalkthroughDiagram = () => {
const vertices = [
Expand Down Expand Up @@ -219,8 +220,7 @@ const Content = () => {
</div>
</section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
4 changes: 2 additions & 2 deletions app/visualizer/graph/algorithms/kruskal/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import { motion } from "framer-motion";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

const WalkthroughDiagram = () => {
const vertices = [
Expand Down Expand Up @@ -217,8 +218,7 @@ const Content = () => {
</div>
</section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
4 changes: 2 additions & 2 deletions app/visualizer/graph/algorithms/prim/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import { motion } from "framer-motion";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

const WalkthroughDiagram = () => {
const vertices = [
Expand Down Expand Up @@ -220,8 +221,7 @@ const Content = () => {
</div>
</section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
4 changes: 2 additions & 2 deletions app/visualizer/graph/algorithms/topological-sort/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NewsletterEmbed from "@/app/components/ui/NewsletterEmbed";
import BackendEngineerCard from "@/app/components/ui/BackendEngineerCard";
import InContentAd from "@/app/components/ads/InContentAd";
import { motion } from "framer-motion";
import MobileEmbedCarousel from "@/app/components/ui/MobileEmbedCarousel";

const WalkthroughDiagram = () => {
const vertices = [
Expand Down Expand Up @@ -213,8 +214,7 @@ const Content = () => {
</div>
</section>
</article>
<NewsletterEmbed mobile theme={theme} />
<DailyDSAEmbed mobile theme={theme} />
<MobileEmbedCarousel theme={theme} />
</main>
);
};
Expand Down
Loading
Loading