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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ const msPerSec = 1000;
const msPerMin = msPerSec * 60;
const msPerHour = msPerMin * 60;

function getHMS(goalTimeMs) {
export type TakeoverData = {
goalTime: string;
fundraiserImage: string;
colorScheme: string;
headline: string;
message: string;
image: string;
buttonText: string;
buttonUrl: string;
messageType: 'message' | 'goal';
boxHeadline: string;
boxHtml: string;
goalAmount: number;
};

function getHMS(goalTimeMs: number) {
const msDiff = goalTimeMs - Date.now();

return {
Expand All @@ -16,7 +31,7 @@ function getHMS(goalTimeMs) {
};
}

function useHMS(goalTime) {
function useHMS(goalTime: string) {
const goalTimeMs = new Date(goalTime).getTime();
const [hms, setHms] = React.useState(getHMS(goalTimeMs));

Expand All @@ -29,25 +44,30 @@ function useHMS(goalTime) {
return () => window.clearInterval(i);
}, [goalTimeMs]);

return (hms);
return hms;
}

export function Countdown({goalTime}) {
export function Countdown({goalTime}: {goalTime: string}) {
const {h, m, s} = useHMS(goalTime);

return (
<div className="countdown-numbers">
<div><span className="number">{h}</span> hours</div>
<div><span className="number">{m}</span> minutes</div>
<div><span className="number">{s}</span> seconds</div>
<div>
<span className="number">{h}</span> hours
</div>
<div>
<span className="number">{m}</span> minutes
</div>
<div>
<span className="number">{s}</span> seconds
</div>
</div>
);
}


const numFormat = window.Intl.NumberFormat('en-US').format; // eslint-disable-line new-cap

export function Amount({amount}) {
export function Amount({amount}: {amount: number}) {
return (
<div className="amount-box">
<div className="message">our goal is to raise</div>
Expand All @@ -56,10 +76,12 @@ export function Amount({amount}) {
);
}

export function GiveButton({text, url}) {
export function GiveButton({text, url}: {text: string; url: string}) {
const {close} = useTakeoverContext();

return (
<a className="btn primary" href={url} onClick={close}>{text}</a>
<a className="btn primary" href={url} onClick={close}>
{text}
</a>
);
}
79 changes: 0 additions & 79 deletions src/app/layouts/default/takeover-dialog/content-desktop.js
Copy link
Contributor

@RoyEJohnson RoyEJohnson Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the first commit for the real changes for all the files in the takeover-dialog folder. It's all just adding types. The final commit is prettier, which is what changed the file enough that it registered as delete-and-create.

This file was deleted.

128 changes: 128 additions & 0 deletions src/app/layouts/default/takeover-dialog/content-desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import RawHTML from '~/components/jsx-helpers/raw-html';
import {Countdown, Amount, GiveButton, TakeoverData} from './common';
import './content-desktop.scss';

function Logo() {
return (
<img
className="logo-color"
src="/dist/images/logo.svg"
alt="OpenStax logo"
width="354"
height="81"
/>
);
}

function Basic({
headline,
message,
image,
children
}: {
headline: string;
message: string;
image: string;
children?: React.ReactNode;
}) {
return (
<div className="takeover-content desktop-only">
<div className="text-side">
<Logo />
<RawHTML Tag="h1" html={headline} id="takeover-headline" />
<div className="message">{message}</div>
{children}
</div>
<div
className="picture-side"
style={{backgroundImage: `url(${image})`}}
/>
</div>
);
}

function MessageBox({
buttonText,
buttonUrl,
headline,
html
}: {
buttonText: string;
buttonUrl: string;
headline: string;
html: string;
}) {
return (
<React.Fragment>
<GiveButton text={buttonText} url={buttonUrl} />
<div className="message-box">
<div className="color-fill" />
<div className="text-content">
<h2>{headline}</h2>
<RawHTML html={html} />
</div>
</div>
</React.Fragment>
);
}

function GoalBox({
buttonText,
buttonUrl,
goalAmount,
goalTime
}: {
buttonText: string;
buttonUrl: string;
goalAmount: number;
goalTime: string;
}) {
return (
<div className="goal-box">
<Amount amount={goalAmount} />
<div className="timer-side">
<a className="btn primary" href={buttonUrl}>
{buttonText}
</a>
<div className="message">help us meet our goal in the next</div>
<Countdown goalTime={goalTime} />
</div>
</div>
);
}

function Box({data}: {data: TakeoverData}) {
return (
{
message: (
<MessageBox
buttonText={data.buttonText}
buttonUrl={data.buttonUrl}
headline={data.boxHeadline}
html={data.boxHtml}
/>
),
goal: (
<GoalBox
buttonText={data.buttonText}
buttonUrl={data.buttonUrl}
goalAmount={data.goalAmount!}
goalTime={data.goalTime}
/>
)
}[data.messageType] || <h1>OOPS, {data.messageType}</h1>
);
}

export default function DesktopContent({data}: {data: TakeoverData}) {
return (
<Basic
headline={data.headline}
message={data.message}
image={data.image}
>
<Box data={data} />
</Basic>
);
}
67 changes: 0 additions & 67 deletions src/app/layouts/default/takeover-dialog/content-mobile.js

This file was deleted.

Loading