Keep draft notes off the How it works guide, link the conflict article, and print only the rule card.
This commit is contained in:
1 parent
453139c783
commit
95f7291c45
7 files changed
+136
-61
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
import {
|
||||
asHowItWorksGuideBlock,
|
||||
formatHowItWorksByline,
|
||||
HOW_IT_WORKS_RULE_CARD_ID,
|
||||
howItWorksReadMinutes,
|
||||
howItWorksWikiMarkdown,
|
||||
type HowItWorksGuideBlock,
|
||||
@@ -149,7 +150,7 @@ function TeamRuleFigure({
|
||||
const { teamRule } = page;
|
||||
return (
|
||||
<figure
|
||||
id="how-it-works-rule-card"
|
||||
id={HOW_IT_WORKS_RULE_CARD_ID}
|
||||
className="flex w-full flex-col gap-[var(--space-300)]"
|
||||
>
|
||||
<div className="flex justify-center overflow-clip rounded-[var(--radius-400)] border border-[color-mix(in_srgb,var(--color-content-default-primary)_30%,transparent)] px-[var(--space-400)] py-[var(--space-600)]">
|
||||
@@ -203,23 +204,26 @@ function GuideBlockView({
|
||||
if (block.type === "ruleFigure") {
|
||||
return <TeamRuleFigure page={page} />;
|
||||
}
|
||||
const wikiMarkdown = howItWorksWikiMarkdown(
|
||||
page.banner.title,
|
||||
page.banner.description,
|
||||
shareUrl,
|
||||
);
|
||||
const mailtoHref = `mailto:?subject=${encodeURIComponent(page.banner.title)}&body=${encodeURIComponent(`${page.banner.title}\n${shareUrl}`)}`;
|
||||
return (
|
||||
<HowItWorksShareRow
|
||||
sendLabel={page.share.send}
|
||||
copyLabel={page.share.copyWiki}
|
||||
printLabel={page.share.print}
|
||||
copiedTitle={page.share.copiedTitle}
|
||||
copyFailedTitle={page.share.copyFailedTitle}
|
||||
mailtoHref={mailtoHref}
|
||||
wikiMarkdown={wikiMarkdown}
|
||||
/>
|
||||
);
|
||||
if (block.type === "shareRow") {
|
||||
const wikiMarkdown = howItWorksWikiMarkdown(
|
||||
page.banner.title,
|
||||
page.banner.description,
|
||||
shareUrl,
|
||||
);
|
||||
const mailtoHref = `mailto:?subject=${encodeURIComponent(page.banner.title)}&body=${encodeURIComponent(`${page.banner.title}\n${shareUrl}`)}`;
|
||||
return (
|
||||
<HowItWorksShareRow
|
||||
sendLabel={page.share.send}
|
||||
copyLabel={page.share.copyWiki}
|
||||
printLabel={page.share.print}
|
||||
copiedTitle={page.share.copiedTitle}
|
||||
copyFailedTitle={page.share.copyFailedTitle}
|
||||
mailtoHref={mailtoHref}
|
||||
wikiMarkdown={wikiMarkdown}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function HowItWorksGuideBody({
|
||||
@@ -241,25 +245,34 @@ export default function HowItWorksGuideBody({
|
||||
</a>
|
||||
</p>
|
||||
|
||||
{page.sections.map((section) => (
|
||||
<section
|
||||
key={section.id}
|
||||
id={section.id}
|
||||
className="flex w-full flex-col gap-[var(--space-600)]"
|
||||
>
|
||||
<h2 className="font-bricolage-grotesque text-large-heading">
|
||||
{section.heading}
|
||||
</h2>
|
||||
{section.blocks.map((block, index) => (
|
||||
<GuideBlockView
|
||||
key={`${section.id}-${index}`}
|
||||
block={asHowItWorksGuideBlock(block)}
|
||||
page={page}
|
||||
shareUrl={shareUrl}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
))}
|
||||
{page.sections.map((section) => {
|
||||
const blocks = section.blocks.flatMap((block) => {
|
||||
const guideBlock = asHowItWorksGuideBlock(block);
|
||||
return guideBlock ? [guideBlock] : [];
|
||||
});
|
||||
const hasCopy = blocks.some((block) => block.type !== "shareRow");
|
||||
return (
|
||||
<section
|
||||
key={section.id}
|
||||
id={section.id}
|
||||
className="flex w-full flex-col gap-[var(--space-600)]"
|
||||
>
|
||||
{hasCopy ? (
|
||||
<h2 className="font-bricolage-grotesque text-large-heading">
|
||||
{section.heading}
|
||||
</h2>
|
||||
) : null}
|
||||
{blocks.map((block, index) => (
|
||||
<GuideBlockView
|
||||
key={`${section.id}-${index}`}
|
||||
block={block}
|
||||
page={page}
|
||||
shareUrl={shareUrl}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className="flex flex-wrap items-start gap-[var(--space-400)]">
|
||||
<Button
|
||||
|
||||
@@ -3,6 +3,28 @@
|
||||
import { useCallback, useState } from "react";
|
||||
import Alert from "../../../components/modals/Alert";
|
||||
import Button from "../../../components/buttons/Button";
|
||||
import { HOW_IT_WORKS_RULE_CARD_ID } from "../../../../lib/howItWorksGuide";
|
||||
|
||||
const CARD_PRINT_STYLE_ID = "how-it-works-card-print";
|
||||
|
||||
function installCardPrintStyle(): () => void {
|
||||
document.getElementById(CARD_PRINT_STYLE_ID)?.remove();
|
||||
const style = document.createElement("style");
|
||||
style.id = CARD_PRINT_STYLE_ID;
|
||||
style.textContent = `@media print {
|
||||
body * { visibility: hidden; }
|
||||
#${HOW_IT_WORKS_RULE_CARD_ID},
|
||||
#${HOW_IT_WORKS_RULE_CARD_ID} * { visibility: visible; }
|
||||
#${HOW_IT_WORKS_RULE_CARD_ID} {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}`;
|
||||
document.head.appendChild(style);
|
||||
return () => style.remove();
|
||||
}
|
||||
|
||||
type HowItWorksShareRowProps = {
|
||||
sendLabel: string;
|
||||
@@ -35,6 +57,12 @@ export default function HowItWorksShareRow({
|
||||
}, [wikiMarkdown]);
|
||||
|
||||
const handlePrint = useCallback(() => {
|
||||
const removeStyle = installCardPrintStyle();
|
||||
const cleanup = () => {
|
||||
removeStyle();
|
||||
window.removeEventListener("afterprint", cleanup);
|
||||
};
|
||||
window.addEventListener("afterprint", cleanup);
|
||||
window.print();
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in new issue
Block a user