minor ui improvements to download!

This commit is contained in:
Matt Dunn-Rankin 2020-04-24 23:29:26 -07:00
parent 4f7c8b1332
commit d39c781f3f
3 changed files with 29 additions and 6 deletions

View file

@ -12,6 +12,7 @@ import {
Spinner, Spinner,
Text, Text,
Tooltip, Tooltip,
useToast,
} from "@chakra-ui/core"; } from "@chakra-ui/core";
import { Delay } from "./util"; import { Delay } from "./util";
@ -37,6 +38,7 @@ export const itemAppearanceFragment = gql`
function OutfitPreview({ outfitState }) { function OutfitPreview({ outfitState }) {
const { wornItemIds, speciesId, colorId } = outfitState; const { wornItemIds, speciesId, colorId } = outfitState;
const toast = useToast();
const { loading, error, data } = useQuery( const { loading, error, data } = useQuery(
gql` gql`
@ -125,9 +127,17 @@ function OutfitPreview({ outfitState }) {
as="a" as="a"
// eslint-disable-next-line no-script-url // eslint-disable-next-line no-script-url
href={downloadImageUrl || "javascript:void 0"} href={downloadImageUrl || "javascript:void 0"}
download="Outfit.png" download={(outfitState.name || "Outfit") + ".png"}
onMouseEnter={prepareDownload} onMouseEnter={prepareDownload}
onFocus={prepareDownload} onFocus={prepareDownload}
onClick={() => {
if (!downloadImageUrl) {
toast({
title:
"Just a second, try again when the image is done loading!",
});
}
}}
variant="unstyled" variant="unstyled"
color="gray.50" color="gray.50"
d="flex" d="flex"

View file

@ -134,7 +134,10 @@ function ItemsPanel({ outfitState, loading, dispatchToOutfit }) {
return ( return (
<Box color="green.800"> <Box color="green.800">
<OutfitHeading /> <OutfitHeading
outfitState={outfitState}
dispatchToOutfit={dispatchToOutfit}
/>
<Stack spacing="10"> <Stack spacing="10">
{loading && {loading &&
[1, 2, 3].map((i) => ( [1, 2, 3].map((i) => (
@ -163,12 +166,18 @@ function ItemsPanel({ outfitState, loading, dispatchToOutfit }) {
); );
} }
function OutfitHeading() { function OutfitHeading({ outfitState, dispatchToOutfit }) {
return ( return (
<Box> <Box>
<PseudoBox role="group" d="inline-block" position="relative"> <PseudoBox role="group" d="inline-block" position="relative" width="100%">
<Heading1 mb="6"> <Heading1 mb="6">
<Editable defaultValue="Zafara Agent (roopal27)"> <Editable
value={outfitState.name}
placeholder="Untitled outfit (click to edit)"
onChange={(value) =>
dispatchToOutfit({ type: "rename", outfitName: value })
}
>
{({ isEditing, onRequestEdit }) => ( {({ isEditing, onRequestEdit }) => (
<> <>
<EditablePreview /> <EditablePreview />

View file

@ -12,6 +12,7 @@ function useOutfitState() {
const [state, dispatchToOutfit] = React.useReducer( const [state, dispatchToOutfit] = React.useReducer(
outfitStateReducer(apolloClient), outfitStateReducer(apolloClient),
{ {
name: "Zafara Agent (roopal27)",
wornItemIds: new Set([ wornItemIds: new Set([
"38913", "38913",
"38911", "38911",
@ -28,7 +29,7 @@ function useOutfitState() {
} }
); );
const { speciesId, colorId } = state; const { name, speciesId, colorId } = state;
// It's more convenient to manage these as a Set in state, but most callers // It's more convenient to manage these as a Set in state, but most callers
// will find it more convenient to access them as arrays! e.g. for `.map()` // will find it more convenient to access them as arrays! e.g. for `.map()`
@ -79,6 +80,7 @@ function useOutfitState() {
const outfitState = { const outfitState = {
zonesAndItems, zonesAndItems,
name,
wornItemIds, wornItemIds,
allItemIds, allItemIds,
speciesId, speciesId,
@ -90,6 +92,8 @@ function useOutfitState() {
const outfitStateReducer = (apolloClient) => (baseState, action) => { const outfitStateReducer = (apolloClient) => (baseState, action) => {
switch (action.type) { switch (action.type) {
case "rename":
return { ...baseState, name: action.outfitName };
case "wearItem": case "wearItem":
return produce(baseState, (state) => { return produce(baseState, (state) => {
// A hack to work around https://github.com/immerjs/immer/issues/586 // A hack to work around https://github.com/immerjs/immer/issues/586