import { usePublicationData, useNormalizedPublicationRecord, } from "app/lish/[did]/[publication]/dashboard/PublicationSWRProvider"; import { useState } from "react"; import { pickers, SectionArrow } from "./ThemeSetter"; import { Color } from "react-aria-components"; import { PubLeafletThemeBackgroundImage } from "lexicons/api"; import { AtUri } from "@atproto/syntax"; import { useLocalPubTheme } from "./PublicationThemeProvider"; import { BaseThemeProvider } from "./ThemeProvider"; import { blobRefToSrc } from "src/utils/blobRefToSrc"; import { updatePublicationTheme } from "app/lish/createPub/updatePublication"; import { PagePickers } from "./PubPickers/PubTextPickers"; import { BackgroundPicker } from "./PubPickers/PubBackgroundPickers"; import { PubAccentPickers } from "./PubPickers/PubAcccentPickers"; import { Separator } from "components/Layout"; import { PubSettingsHeader } from "app/lish/[did]/[publication]/dashboard/settings/PublicationSettings"; import { ColorToRGB, ColorToRGBA } from "./colorToLexicons"; import { useToaster } from "components/Toast"; import { OAuthErrorMessage, isOAuthSessionError } from "components/OAuthError"; import { PubPageWidthSetter } from "./PubPickers/PubPageWidthSetter"; import { FontPicker } from "./Pickers/TextPickers"; export type ImageState = { src: string; file?: File; repeat: number | null; }; export const PubThemeSetter = (props: { backToMenu: () => void; loading: boolean; setLoading: (l: boolean) => void; }) => { let [sample, setSample] = useState<"pub" | "post">("pub"); let [openPicker, setOpenPicker] = useState("null"); let { data, mutate } = usePublicationData(); let { publication: pub } = data || {}; let record = useNormalizedPublicationRecord(); let [showPageBackground, setShowPageBackground] = useState( !!record?.theme?.showPageBackground, ); let { theme: localPubTheme, setTheme, changes, } = useLocalPubTheme(record?.theme, showPageBackground); let [image, setImage] = useState( PubLeafletThemeBackgroundImage.isMain(record?.theme?.backgroundImage) ? { src: blobRefToSrc( record.theme.backgroundImage.image.ref, pub?.identity_did!, ), repeat: record.theme.backgroundImage.repeat ? record.theme.backgroundImage.width || 500 : null, } : null, ); let [pageWidth, setPageWidth] = useState( record?.theme?.pageWidth || 624, ); let [headingFont, setHeadingFont] = useState(record?.theme?.headingFont); let [bodyFont, setBodyFont] = useState(record?.theme?.bodyFont); let pubBGImage = image?.src || null; let leafletBGRepeat = image?.repeat || null; let toaster = useToaster(); return (
{ e.preventDefault(); if (!pub) return; props.setLoading(true); let result = await updatePublicationTheme({ uri: pub.uri, theme: { pageBackground: ColorToRGBA(localPubTheme.bgPage), showPageBackground: showPageBackground, backgroundColor: image ? ColorToRGBA(localPubTheme.bgLeaflet) : ColorToRGB(localPubTheme.bgLeaflet), backgroundRepeat: image?.repeat, backgroundImage: image ? image.file : null, pageWidth: pageWidth, primary: ColorToRGB(localPubTheme.primary), accentBackground: ColorToRGB(localPubTheme.accent1), accentText: ColorToRGB(localPubTheme.accent2), headingFont: headingFont, bodyFont: bodyFont, }, }); if (!result.success) { props.setLoading(false); if (result.error && isOAuthSessionError(result.error)) { toaster({ content: , type: "error", }); } else { toaster({ content: "Failed to update theme", type: "error", }); } return; } mutate((pub) => { if (result.publication && pub?.publication) return { ...pub, publication: { ...pub.publication, ...result.publication }, }; return pub; }, false); props.setLoading(false); }} > Theme and Layout
{ setTheme((t) => ({ ...t, bgPage: color })); }} setBackgroundColor={(color) => { setTheme((t) => ({ ...t, bgLeaflet: color })); }} openPicker={openPicker} setOpenPicker={setOpenPicker} hasPageBackground={!!showPageBackground} setHasPageBackground={setShowPageBackground} />
{ setTheme((t) => ({ ...t, bgPage: color })); }} setPrimary={(color) => { setTheme((t) => ({ ...t, primary: color })); }} openPicker={openPicker} setOpenPicker={(pickers) => setOpenPicker(pickers)} hasPageBackground={showPageBackground} />
{ setTheme((t) => ({ ...t, accent1: color })); }} accent2={localPubTheme.accent2} setAccent2={(color) => { setTheme((t) => ({ ...t, accent2: color })); }} openPicker={openPicker} setOpenPicker={(pickers) => setOpenPicker(pickers)} />
Preview
{" "}
{sample === "pub" ? ( ) : ( )}
); }; const SamplePub = (props: { pubBGImage: string | null; pubBGRepeat: number | null; showPageBackground: boolean; }) => { let { data } = usePublicationData(); let { publication } = data || {}; let record = useNormalizedPublicationRecord(); return (
{record?.icon && publication?.uri && (
)}
{record?.name}
{record?.description}
Subscribe with Bluesky
A Sample Post
This is a sample description about the sample post
Jan 1, 20XX
); }; const SamplePost = (props: { pubBGImage: string | null; pubBGRepeat: number | null; showPageBackground: boolean; }) => { let { data } = usePublicationData(); let { publication } = data || {}; let record = useNormalizedPublicationRecord(); return (
{record?.name}
A Sample Post
A short sample description about the sample post
Jan 1, 20XX
Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor.
Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos.
Sed et nisi semper, egestas purus a, egestas nulla. Nulla ultricies, purus non dapibus tincidunt, nunc sem rhoncus sem, vel malesuada tellus enim sit amet magna. Donec ac justo a ipsum fermentum vulputate. Etiam sit amet viverra leo. Aenean accumsan consectetur velit. Vivamus at justo a nisl imperdiet dictum. Donec scelerisque ex eget turpis scelerisque tincidunt. Proin non convallis nibh, eget aliquet ex. Curabitur ornare a ipsum in ultrices.
); };