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
+103
-28
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,6 +204,7 @@ function GuideBlockView({
|
||||
if (block.type === "ruleFigure") {
|
||||
return <TeamRuleFigure page={page} />;
|
||||
}
|
||||
if (block.type === "shareRow") {
|
||||
const wikiMarkdown = howItWorksWikiMarkdown(
|
||||
page.banner.title,
|
||||
page.banner.description,
|
||||
@@ -221,6 +223,8 @@ function GuideBlockView({
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function HowItWorksGuideBody({
|
||||
page,
|
||||
@@ -241,25 +245,34 @@ export default function HowItWorksGuideBody({
|
||||
</a>
|
||||
</p>
|
||||
|
||||
{page.sections.map((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>
|
||||
{section.blocks.map((block, index) => (
|
||||
) : null}
|
||||
{blocks.map((block, index) => (
|
||||
<GuideBlockView
|
||||
key={`${section.id}-${index}`}
|
||||
block={asHowItWorksGuideBlock(block)}
|
||||
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();
|
||||
}, []);
|
||||
|
||||
|
||||
+18
-6
@@ -2,6 +2,8 @@ import type howItWorksPage from "../messages/en/pages/howItWorks.json";
|
||||
|
||||
const HOW_IT_WORKS_WORDS_PER_MINUTE = 200;
|
||||
|
||||
export const HOW_IT_WORKS_RULE_CARD_ID = "how-it-works-rule-card";
|
||||
|
||||
type HowItWorksMessages = typeof howItWorksPage;
|
||||
|
||||
export type HowItWorksGuideBlock =
|
||||
@@ -14,8 +16,16 @@ const MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
|
||||
|
||||
export function asHowItWorksGuideBlock(
|
||||
block: HowItWorksMessages["sections"][number]["blocks"][number],
|
||||
): HowItWorksGuideBlock {
|
||||
): HowItWorksGuideBlock | null {
|
||||
switch (block.type) {
|
||||
case "p":
|
||||
case "figure":
|
||||
case "ruleFigure":
|
||||
case "shareRow":
|
||||
return block as HowItWorksGuideBlock;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function stripGuideMarkup(text: string): string {
|
||||
@@ -43,10 +53,10 @@ export function collectHowItWorksGuideText(page: HowItWorksMessages): string {
|
||||
const parts: string[] = [];
|
||||
for (const section of page.sections) {
|
||||
parts.push(section.heading);
|
||||
for (const block of section.blocks) {
|
||||
parts.push(
|
||||
blockPlainText(asHowItWorksGuideBlock(block), page.teamRule.caption),
|
||||
);
|
||||
for (const rawBlock of section.blocks) {
|
||||
const block = asHowItWorksGuideBlock(rawBlock);
|
||||
if (!block) continue;
|
||||
parts.push(blockPlainText(block, page.teamRule.caption));
|
||||
}
|
||||
}
|
||||
return stripGuideMarkup(parts.filter(Boolean).join(" "));
|
||||
@@ -74,10 +84,12 @@ export function formatHowItWorksByline(
|
||||
page: HowItWorksMessages,
|
||||
minutes: number,
|
||||
): string {
|
||||
const unit = minutes === 1 ? page.byline.minute : page.byline.minutes;
|
||||
return page.byline.template
|
||||
.replace("{author}", page.banner.author)
|
||||
.replace("{date}", formatHowItWorksDate(page.banner.date))
|
||||
.replace("{minutes}", String(minutes));
|
||||
.replace("{minutes}", String(minutes))
|
||||
.replace("{unit}", unit);
|
||||
}
|
||||
|
||||
export function howItWorksWikiMarkdown(
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
"date": "2027-02-18"
|
||||
},
|
||||
"byline": {
|
||||
"template": "By {author}. {date}. {minutes} minute read. ",
|
||||
"template": "By {author}. {date}. {minutes} {unit} read. ",
|
||||
"minute": "minute",
|
||||
"minutes": "minutes",
|
||||
"beforeYouStart": "Before you start"
|
||||
},
|
||||
"relatedArticles": {
|
||||
@@ -81,7 +83,7 @@
|
||||
"blocks": [
|
||||
{
|
||||
"type": "p",
|
||||
"text": "A Rule is a short document your community can read aloud in a few minutes. [Confirm how long a typical Rule runs.] It has five parts. The first part names what your community values and the plain signs that a value is slipping. CommunityRule calls those signs signals of violation. The other four parts say how you talk, who belongs, how you decide and what happens when you disagree. Every community has answers to those four already, written or not."
|
||||
"text": "A Rule is a short document your community can read aloud in a few minutes. It has five parts. The first part names what your community values and the plain signs that a value is slipping. CommunityRule calls those signs signals of violation. The other four parts say how you talk, who belongs, how you decide and what happens when you disagree. Every community has answers to those four already, written or not."
|
||||
},
|
||||
{
|
||||
"type": "p",
|
||||
@@ -100,7 +102,7 @@
|
||||
},
|
||||
{
|
||||
"type": "p",
|
||||
"text": "A Rule is an agreement between people and it sits beside your bylaws if you have them. [One line for co-ops on what to do when practice and bylaws differ.]"
|
||||
"text": "A Rule is an agreement between people and it sits beside your bylaws if you have them."
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -129,7 +131,7 @@
|
||||
{
|
||||
"type": "p",
|
||||
"lead": "Check that your community is not in the middle of a dispute.",
|
||||
"text": "A community in a dispute cannot write fair rules. Everyone is arguing about an outcome and a Rule is about method. Write it after the dispute and start with [the conflict guide's title] for now."
|
||||
"text": "A community in a dispute cannot write fair rules. Everyone is arguing about an outcome and a Rule is about method. Write it after the dispute and start with [Resolving Active Conflicts](/blog/resolving-active-conflicts) for now."
|
||||
},
|
||||
{
|
||||
"type": "p",
|
||||
@@ -149,7 +151,7 @@
|
||||
{
|
||||
"type": "p",
|
||||
"lead": "Decide what stays out.",
|
||||
"text": "Leave out rosters, meeting places and legal names if your community's work puts people at risk. Every Rule starts private. Only the people you invite can read it until the person who holds the pen turns on a link. A Rule is public and featured only when a group asks us in writing. [Say who can see a draft and an upload and whether a group can delete them.]"
|
||||
"text": "Leave out rosters, meeting places and legal names if your community's work puts people at risk. Every Rule starts private. Only the people you invite can read it until the person who holds the pen turns on a link. A Rule is public and featured only when a group asks us in writing."
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -159,7 +161,7 @@
|
||||
"blocks": [
|
||||
{
|
||||
"type": "p",
|
||||
"text": "The screens are the quick part. One or two people can sketch a whole Rule in one sitting, and nothing is shared until you invite people. [Confirm by timing a sketch through the screens.] Answer for the community you are today and pick what is closest to what you do now. The meetings are where your community decides whether to keep it."
|
||||
"text": "The screens are the quick part. One or two people can sketch a whole Rule in one sitting, and nothing is shared until you invite people. Answer for the community you are today and pick what is closest to what you do now. The meetings are where your community decides whether to keep it."
|
||||
},
|
||||
{
|
||||
"type": "p",
|
||||
@@ -363,10 +365,6 @@
|
||||
"id": "updates-from-groups",
|
||||
"heading": "Updates from groups",
|
||||
"blocks": [
|
||||
{
|
||||
"type": "p",
|
||||
"text": "[Dated entries from groups. Empty at launch.]"
|
||||
},
|
||||
{
|
||||
"type": "shareRow"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("HowItWorksShareRow", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("copies wiki markdown and prints the page", async () => {
|
||||
it("copies wiki markdown and prints only the rule card", async () => {
|
||||
const print = vi.spyOn(window, "print").mockImplementation(() => {});
|
||||
|
||||
render(
|
||||
@@ -48,6 +48,11 @@ describe("HowItWorksShareRow", () => {
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Print the card" }));
|
||||
expect(print).toHaveBeenCalled();
|
||||
const printStyle = document.getElementById("how-it-works-card-print");
|
||||
expect(printStyle?.textContent).toContain("#how-it-works-rule-card");
|
||||
expect(printStyle?.textContent).toContain("visibility: hidden");
|
||||
window.dispatchEvent(new Event("afterprint"));
|
||||
expect(document.getElementById("how-it-works-card-print")).toBeNull();
|
||||
print.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,10 @@ import { screen, waitFor } from "@testing-library/react";
|
||||
import { renderWithProviders as render } from "../utils/test-utils";
|
||||
import HowItWorksPage from "../../app/(marketing)/how-it-works/page";
|
||||
import messages from "../../messages/en/index";
|
||||
import { howItWorksReadMinutes } from "../../lib/howItWorksGuide";
|
||||
import {
|
||||
formatHowItWorksByline,
|
||||
howItWorksReadMinutes,
|
||||
} from "../../lib/howItWorksGuide";
|
||||
|
||||
vi.mock("next/dynamic", () => ({
|
||||
default: (importFn) => {
|
||||
@@ -78,10 +81,20 @@ describe("HowItWorksPage", () => {
|
||||
).toHaveAttribute("href", "#before-you-start");
|
||||
expect(
|
||||
screen.getByText(
|
||||
`By ${page.banner.author}. 18 February 2027. ${howItWorksReadMinutes(page)} minute read.`,
|
||||
formatHowItWorksByline(page, howItWorksReadMinutes(page)).trim(),
|
||||
{ exact: false },
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("link", { name: "Resolving Active Conflicts" }),
|
||||
).toHaveAttribute("href", "/blog/resolving-active-conflicts");
|
||||
expect(screen.queryByText(/\[Confirm how long/)).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText(/Dated entries from groups/),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("heading", { name: "Updates from groups" }),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("related-articles")).toBeInTheDocument();
|
||||
|
||||
@@ -15,13 +15,19 @@ describe("howItWorksGuide", () => {
|
||||
expect(formatHowItWorksDate(page.banner.date)).toBe("18 February 2027");
|
||||
const minutes = howItWorksReadMinutes(page);
|
||||
expect(minutes).toBeGreaterThanOrEqual(10);
|
||||
expect(formatHowItWorksByline(page, minutes)).toBe(
|
||||
`By CommunityRule Creative Team. 18 February 2027. ${minutes} minute read. `,
|
||||
expect(formatHowItWorksByline(page, 1)).toBe(
|
||||
"By CommunityRule Creative Team. 18 February 2027. 1 minute read. ",
|
||||
);
|
||||
expect(collectHowItWorksGuideText(page)).toContain(
|
||||
expect(formatHowItWorksByline(page, minutes)).toBe(
|
||||
`By CommunityRule Creative Team. 18 February 2027. ${minutes} minutes read. `,
|
||||
);
|
||||
const guideText = collectHowItWorksGuideText(page);
|
||||
expect(guideText).toContain(
|
||||
"A Rule is a short document your community can read aloud in a few minutes.",
|
||||
);
|
||||
expect(collectHowItWorksGuideText(page)).not.toContain("](/kit)");
|
||||
expect(guideText).toContain("Resolving Active Conflicts");
|
||||
expect(guideText).not.toContain("](/kit)");
|
||||
expect(guideText).not.toMatch(/\[[^\]]*\]/);
|
||||
});
|
||||
|
||||
it("builds wiki markdown from the title, description and URL", () => {
|
||||
|
||||
Reference in new issue
Block a user