Skip to content
Myr

how-to.tsx

This file

Path

apps/web/src/features/front/how-to.tsx

163 lines · 4.9 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–163why, one step back
1/**
2 * The strip of three steps above the asks, which a reader may dismiss. The3 * dismissal is kept in this browser's localStorage, never a cookie: a cookie4 * would take the page out of the edge cache (ADR 0042 says the same of the5 * theme). The server has no storage and draws the strip; a reader who6 * dismissed it sees it go once the page has read the storage.7 */8import { pushCommand } from "@repo/agent-kit/install";9import { Brand } from "@repo/brand";10import { Result } from "effect";11import { X } from "lucide-react";12import { useCallback, useId, useSyncExternalStore } from "react";1314import { Button } from "../../components/ui/button.tsx";15import { CommandLine } from "../shared/command.tsx";16import { AppLink } from "../shared/link.tsx";17import { INSTALL_PATH } from "../shared/paths.ts";18import { browserStorage } from "../shared/storage.ts";1920const DISMISSED = "asks.how-to";2122export const readHowToDismissed = (storage?: Storage): boolean =>23 storage !== undefined &&24 Result.getOrElse(25 Result.try(() => storage.getItem(DISMISSED) === "dismissed"),26 () => false27 );2829export const dismissHowTo = (storage?: Storage) => {30 Result.try(() => storage?.setItem(DISMISSED, "dismissed"));31};3233export const restoreHowTo = (storage?: Storage) => {34 Result.try(() => storage?.removeItem(DISMISSED));35};3637/** Said on this page when it changes the storage; another tab says `storage`. */38const CHANGED = "asks-how-to";3940const subscribe = (onChange: () => void) => {41 globalThis.addEventListener(CHANGED, onChange);42 globalThis.addEventListener("storage", onChange);4344 return () => {45 globalThis.removeEventListener(CHANGED, onChange);46 globalThis.removeEventListener("storage", onChange);47 };48};4950const dismissedHere = () => readHowToDismissed(browserStorage());5152const shownOnServer = () => false;5354export const useHowTo = () => {55 const dismissed = useSyncExternalStore(56 subscribe,57 dismissedHere,58 shownOnServer59 );6061 const dismiss = useCallback(() => {62 dismissHowTo(browserStorage());63 globalThis.dispatchEvent(new Event(CHANGED));64 }, []);6566 const restore = useCallback(() => {67 restoreHowTo(browserStorage());68 globalThis.dispatchEvent(new Event(CHANGED));69 }, []);7071 return { dismiss, dismissed, restore };72};7374export const HOW_TO_TITLE = "How to take an ask";7576const STEPS = [77 {78 command: `${Brand.cli} claim <ask> --project <owner>/<name>`,79 label: "Claim one you may take",80 },81 { command: `${Brand.cli} check`, label: "Check your answer before you push" },82 {83 command: pushCommand,84 label: "Push it to your fork",85 },86] as const;8788const LINK = "decoration-rule underline hover:decoration-current";8990/**91 * The strip itself. Its onward line links Install through the router and92 * `llms.txt` as a plain anchor, since `llms.txt` is a server route. On a phone93 * only the first step is a command box; the other two read as code in the94 * list, so the strip never becomes a column of code blocks (ADR 0041).95 */96export const HowToTake = ({97 onDismiss,98}: {99 readonly onDismiss: () => void;100}) => {101 const heading = useId();102103 return (104 <section105 aria-labelledby={heading}106 className="border-rule bg-card flex flex-col gap-4 border p-4"107 data-how-to=""108 >109 <div className="flex items-center justify-between gap-3">110 <h2 className="text-ui font-semibold" id={heading}>111 {HOW_TO_TITLE}112 </h2>113 <Button114 aria-label={`Dismiss ${HOW_TO_TITLE.toLowerCase()}`}115 onClick={onDismiss}116 size="icon-sm"117 title="Dismiss"118 type="button"119 variant="ghost"120 >121 <X aria-hidden="true" strokeWidth={1.75} />122 </Button>123 </div>124 <ol className="columns:grid-cols-3 tablet:gap-4 grid gap-3">125 {STEPS.map(({ command, label }, index) => (126 <li className="flex min-w-0 flex-col gap-1" key={command}>127 <p className="text-label text-muted-foreground">128 {index + 1}. {label}129 </p>130 {index === 0 ? (131 <CommandLine command={command} numbered />132 ) : (133 <>134 <code135 className="text-mono tablet:hidden font-mono [overflow-wrap:anywhere]"136 data-step-text=""137 >138 {command}139 </code>140 <div className="max-tablet:hidden">141 <CommandLine command={command} numbered />142 </div>143 </>144 )}145 </li>146 ))}147 </ol>148 <p className="text-ui text-muted-foreground">149 New here?{" "}150 <AppLink className={`text-foreground ${LINK}`} to={INSTALL_PATH}>151 Install the command line152 </AppLink>{" "}153 first. For agents:{" "}154 <a155 className={`text-foreground text-mono font-mono ${LINK}`}156 href="/llms.txt"157 >158 llms.txt159 </a>160 </p>161 </section>162 );163};