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
12 changes: 12 additions & 0 deletions app/components/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ const SERVICES = [
iconBg: "bg-purple-100 text-purple-600",
href: "/visualizer"
},
{
title: "Design & Analysis of Algorithms",
description: "Complexity analysis and algorithm design techniques",
icon: (
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M3 3v18h18"></path>
<path d="M7 15l4-5 3 3 5-7"></path>
</svg>
),
iconBg: "bg-blue-100 text-blue-600",
href: "/design-algorithm"
},
{
title: "Blogs",
description: "Tutorials & guides on development",
Expand Down
51 changes: 32 additions & 19 deletions app/components/ui/DailyDSAEmbed.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
"use client";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";

const EMBED_ORIGIN = "https://scaleengineer.com";
// Used until the embed reports its real height, and if the message never lands.
const FALLBACK_HEIGHT = 350;

const DailyDSAEmbed = ({ mobile = false, theme = "light" }) => {
const src = `https://scaleengineer.com/embed/daily/dsa?theme=${theme}`;
const [height, setHeight] = useState(FALLBACK_HEIGHT);
const iframeRef = useRef(null);

const src = `${EMBED_ORIGIN}/embed/daily/dsa?theme=${theme}`;
const wrapperClasses = mobile
? "block md:hidden w-full"
: "max-w-full hidden md:block";
const height = mobile ? 350 : 350;

// The embed posts its document height on load and on every resize. Growing
// the iframe to match keeps the frame from getting its own scrollbar, which
// looked broken next to the article on narrow viewports.
useEffect(() => {
const onMessage = (event) => {
if (event.origin !== EMBED_ORIGIN) return;
if (event.source !== iframeRef.current?.contentWindow) return;
if (event.data?.type !== "se-embed-resize") return;

const reported = Number(event.data.height);
if (Number.isFinite(reported) && reported > 0) {
setHeight(Math.ceil(reported));
}
};

window.addEventListener("message", onMessage);
return () => window.removeEventListener("message", onMessage);
}, []);

return (
<div className={wrapperClasses}>
<div className="max-w-full mb-4">
<a
href="https://scaleengineer.com/daily"
target="_blank"
rel="noopener noreferrer"
className="mb-2 inline-block text-[#737373] no-underline"
style={{
font: "500 12px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
}}
>
Daily DSA Challenge by{" "}
<span className="text-[#0a0a0a] underline underline-offset-[3px]">
Scale Engineer
</span>
</a>
<iframe
ref={iframeRef}
src={src}
width="100%"
height={height}
className="border border-black border-dashed rounded-none overflow-hidden"
scrolling="no"
style={{ height: `${height}px` }}
className="block w-full border border-black border-dashed rounded-none overflow-hidden"
title="Daily DSA Challenge"
loading="lazy"
></iframe>
Expand Down
36 changes: 31 additions & 5 deletions app/components/ui/NewsletterEmbed.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"use client";

import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";

const EMBED_ORIGIN = "https://scaleengineer.com";
// Used until the embed reports its real height, and if the message never lands.
const FALLBACK_HEIGHT = 360;

const NewsletterEmbed = ({ mobile = false, theme = "light" }) => {
const [pageUrl, setPageUrl] = useState("");
// Only mount the iframe on desktop. Hiding it with CSS still downloads it on
// phones, which hurts the mobile performance/SEO score.
const [isDesktop, setIsDesktop] = useState(false);
const [height, setHeight] = useState(FALLBACK_HEIGHT);
const iframeRef = useRef(null);

useEffect(() => {
setPageUrl(encodeURIComponent(window.location.href));
Expand All @@ -20,20 +26,40 @@ const NewsletterEmbed = ({ mobile = false, theme = "light" }) => {
return () => mq.removeEventListener("change", update);
}, []);

// The embed posts its document height on load and on every resize. Growing
// the iframe to match keeps the frame from getting its own scrollbar, which
// looked broken next to the article on narrow viewports.
useEffect(() => {
const onMessage = (event) => {
if (event.origin !== EMBED_ORIGIN) return;
if (event.source !== iframeRef.current?.contentWindow) return;
if (event.data?.type !== "se-embed-resize") return;

const reported = Number(event.data.height);
if (Number.isFinite(reported) && reported > 0) {
setHeight(Math.ceil(reported));
}
};

window.addEventListener("message", onMessage);
return () => window.removeEventListener("message", onMessage);
}, [isDesktop]);

// The mobile variant is retired; the desktop variant is desktop-only.
if (mobile || !isDesktop) return null;

const src = `https://scaleengineer.com/embed/subscribe?theme=${theme}&utm_campaign=dsa_visualizer&utm_source=${pageUrl}`;
const height = 360;
const src = `${EMBED_ORIGIN}/embed/subscribe?theme=${theme}&utm_campaign=dsa_visualizer&utm_source=${pageUrl}`;

return (
<div className="max-w-full">
<div className="max-w-full mb-4">
<iframe
ref={iframeRef}
src={src}
width="100%"
height={height}
className="border border-black border-dashed rounded-none overflow-hidden"
scrolling="no"
style={{ height: `${height}px` }}
className="block w-full border border-black border-dashed rounded-none overflow-hidden"
title="Newsletter Subscribe"
loading="lazy"
></iframe>
Expand Down
32 changes: 32 additions & 0 deletions app/design-algorithm/DesignAlgorithmClient.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use client";
import { useState } from "react";
import SearchBar from "@/app/components/ui/SearchBar";
import SectionsDisplay from "@/app/components/SectionsDisplay";

const DesignAlgorithmClient = ({ initialSections }) => {
const [filteredSections, setFilteredSections] = useState(initialSections);
const [searchQuery, setSearchQuery] = useState("");

return (
<>
{ /* search bar display */ }
<div className="mb-10">
<SearchBar
sections={initialSections}
onSearchResults={setFilteredSections}
setSearchQuery={setSearchQuery}
/>
</div>

{ /* section display */ }
<div>
<SectionsDisplay
sections={filteredSections}
searchQuery={searchQuery}
/>
</div>
</>
);
};

export default DesignAlgorithmClient;
Loading