import React, { useContext, useEffect, useRef } from "react";
import { AutoSizingSvg } from "../auto-sizing-svg";
import {
CreatureContext,
CreatureContextType,
CreatureSymbol,
} from "../creature-symbol";
import {
GalleryComposition,
GalleryCompositionKind,
GalleryContext,
} from "../gallery-context";
import { LoadingIndicator } from "../loading-indicator";
import { Page } from "../page";
import { createPageWithStateSearchParams } from "../page-with-shareable-state";
import { svgScale, SvgTransform } from "../svg-transform";
import { CreatureDesign } from "./creature-page/core";
import { deserializeCreatureDesign } from "./creature-page/serialization";
import { getFriendlyPageName } from "./friendly-page-names";
import "./gallery-page.css";
import {
createMandalaAnimationRenderer,
MandalaDesign,
} from "./mandala-page/core";
import { deserializeMandalaDesign } from "./mandala-page/serialization";
function compositionRemixUrl(comp: GalleryComposition): string {
return (
"?" +
createPageWithStateSearchParams(comp.kind, comp.serializedValue).toString()
);
}
const THUMBNAIL_CLASS = "gallery-thumbnail canvas";
const THUMBNAIL_SCALE = 0.2;
const ErrorThumbnail: React.FC<{ title?: string }> = ({ title }) => (
☹
);
const CreatureThumbnail: React.FC<{ design: CreatureDesign }> = (props) => {
const svgRef = useRef(null);
const ctx: CreatureContextType = {
...useContext(CreatureContext),
...props.design.compCtx,
};
const { background } = props.design.compCtx;
return (
);
};
const MandalaThumbnail: React.FC<{ design: MandalaDesign }> = (props) => {
const render = createMandalaAnimationRenderer(props.design, THUMBNAIL_SCALE);
const { background } = props.design.baseCompCtx;
const svgRef = useRef(null);
const canvasRef = useRef(null);
return (
);
};
const THUMBNAILERS: {
[key in GalleryCompositionKind]: (gc: GalleryComposition) => JSX.Element;
} = {
creature: (gc) => (
),
mandala: (gc) => (
),
};
function getThumbnail(gc: GalleryComposition): JSX.Element {
let errorTitle: string;
if (gc.kind in THUMBNAILERS) {
try {
return THUMBNAILERS[gc.kind](gc);
} catch (e) {
errorTitle = `Could not deserialize ${gc.kind} "${gc.title}": ${e.message}`;
console.error(e);
}
} else {
errorTitle = `Found unknown gallery composition kind "${gc.kind}".`;
}
console.log(errorTitle);
return ;
}
const GalleryCompositionView: React.FC = (props) => {
const thumbnail = getThumbnail(props);
const url = compositionRemixUrl(props);
return (
);
};
export const GalleryPage: React.FC<{}> = () => {
const ctx = useContext(GalleryContext);
useEffect(() => {
if (ctx.lastRefresh === 0) {
ctx.refresh();
}
}, [ctx]);
return (
You can publish to this gallery via the sidebar on other pages of this
site.
{ctx.error &&
{ctx.error}
}
{ctx.isLoading ? (
) : (
ctx.compositions.map((comp) => (
))
)}
);
};