Make getThumbnail() more DRY.
rodzic
0def79264c
commit
89bf28339a
|
@ -5,7 +5,11 @@ import {
|
||||||
CreatureContextType,
|
CreatureContextType,
|
||||||
CreatureSymbol,
|
CreatureSymbol,
|
||||||
} from "../creature-symbol";
|
} from "../creature-symbol";
|
||||||
import { GalleryComposition, GalleryContext } from "../gallery-context";
|
import {
|
||||||
|
GalleryComposition,
|
||||||
|
GalleryCompositionKind,
|
||||||
|
GalleryContext,
|
||||||
|
} from "../gallery-context";
|
||||||
import { Page } from "../page";
|
import { Page } from "../page";
|
||||||
import { createPageWithStateSearchParams } from "../page-with-shareable-state";
|
import { createPageWithStateSearchParams } from "../page-with-shareable-state";
|
||||||
import { svgScale, SvgTransform } from "../svg-transform";
|
import { svgScale, SvgTransform } from "../svg-transform";
|
||||||
|
@ -78,27 +82,28 @@ const MandalaThumbnail: React.FC<{ design: MandalaDesign }> = (props) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const THUMBNAILERS: {
|
||||||
|
[key in GalleryCompositionKind]: (gc: GalleryComposition) => JSX.Element;
|
||||||
|
} = {
|
||||||
|
creature: (gc) => (
|
||||||
|
<CreatureThumbnail design={deserializeCreatureDesign(gc.serializedValue)} />
|
||||||
|
),
|
||||||
|
mandala: (gc) => (
|
||||||
|
<MandalaThumbnail design={deserializeMandalaDesign(gc.serializedValue)} />
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
function getThumbnail(gc: GalleryComposition): JSX.Element {
|
function getThumbnail(gc: GalleryComposition): JSX.Element {
|
||||||
if (gc.kind === "creature") {
|
if (gc.kind in THUMBNAILERS) {
|
||||||
let design: CreatureDesign;
|
|
||||||
try {
|
try {
|
||||||
design = deserializeCreatureDesign(gc.serializedValue);
|
return THUMBNAILERS[gc.kind](gc);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Could not deserialize creature "${gc.title}"`, e);
|
console.log(`Could not deserialize ${gc.kind} "${gc.title}"`, e);
|
||||||
return <EmptyThumbnail />;
|
|
||||||
}
|
}
|
||||||
return <CreatureThumbnail design={design} />;
|
} else {
|
||||||
}
|
console.log(`Found unknown gallery composition kind "${gc.kind}".`);
|
||||||
if (gc.kind === "mandala") {
|
|
||||||
let design: MandalaDesign;
|
|
||||||
try {
|
|
||||||
design = deserializeMandalaDesign(gc.serializedValue);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(`Could not deserialize creature "${gc.title}"`, e);
|
|
||||||
return <EmptyThumbnail />;
|
|
||||||
}
|
|
||||||
return <MandalaThumbnail design={design} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return <EmptyThumbnail />;
|
return <EmptyThumbnail />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue