{entry.noticeText}
import { ChevronRightIcon, ExternalLinkIcon } from "lucide-react";
import { useAtomRefresh, useAtomValue } from "@effect/atom-react";
import * as Cause from "effect/Cause";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import { FetchHttpClient, HttpClient } from "effect/http";
import { Atom } from "effect/reactivity";
import { useState } from "react";
import {
decodeThirdPartyLicenseManifest,
filterThirdPartyLicenseEntries,
formatLicenseBundles,
thirdPartyLicenseEntryKey,
type ThirdPartyLicenseEntry,
} from "@t3tools/shared/thirdPartyLicenses";
import { Button } from "../ui/button";
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
import { Badge } from "../ui/badge";
import {
SettingsLoadingRows,
SettingsNoMatches,
SettingsPageContainer,
SettingsSearchField,
SettingsSection,
SettingsToolbar,
} from "./settingsLayout";
class LicenseManifestLoadError extends Data.TaggedError("LicenseManifestLoadError")<{
readonly message: string;
}> {}
// Not keepAlive: a failed load must not stick for the session, so each visit to the page loads
// the manifest again (a static asset the HTTP cache serves).
const licenseManifestAtom = Atom.make(
Effect.gen(function* () {
const response = yield* HttpClient.get(
`${import.meta.env.BASE_URL.replace(/\/$/, "")}/third-party-licenses.json`,
);
if (response.status < 200 || response.status >= 300) {
return yield* new LicenseManifestLoadError({
message: `The license manifest request failed with status ${String(response.status)}.`,
});
}
const body = yield* response.json;
return yield* Effect.try({
try: () => decodeThirdPartyLicenseManifest(body),
catch: (error) =>
new LicenseManifestLoadError({
message: error instanceof Error ? error.message : "The license manifest could not load.",
}),
});
}).pipe(
Effect.catchTags({
HttpClientError: (error) =>
Effect.fail(new LicenseManifestLoadError({ message: error.message })),
}),
Effect.timeoutOrElse({
duration: "30 seconds",
orElse: () =>
Effect.fail(
new LicenseManifestLoadError({ message: "The license manifest took too long to load." }),
),
}),
Effect.provide(FetchHttpClient.layer),
),
).pipe(Atom.withLabel("settings:open-source-licenses"));
/** Name over version and bundles, a license chip, and a chevron; the notice expands in place. */
function LicenseNoticeRow({
entry,
open,
onOpenChange,
}: {
readonly entry: ThirdPartyLicenseEntry;
readonly open: boolean;
readonly onOpenChange: (open: boolean) => void;
}) {
return (
{entry.noticeText}
{message}