From d39c781f3f9386afeb95cc94253dd93d27ec4421 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Fri, 24 Apr 2020 23:29:26 -0700 Subject: [PATCH] minor ui improvements to download! --- src/OutfitPreview.js | 12 +++++++++++- src/WardrobePage.js | 17 +++++++++++++---- src/useOutfitState.js | 6 +++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/OutfitPreview.js b/src/OutfitPreview.js index b3c637a..36b613d 100644 --- a/src/OutfitPreview.js +++ b/src/OutfitPreview.js @@ -12,6 +12,7 @@ import { Spinner, Text, Tooltip, + useToast, } from "@chakra-ui/core"; import { Delay } from "./util"; @@ -37,6 +38,7 @@ export const itemAppearanceFragment = gql` function OutfitPreview({ outfitState }) { const { wornItemIds, speciesId, colorId } = outfitState; + const toast = useToast(); const { loading, error, data } = useQuery( gql` @@ -125,9 +127,17 @@ function OutfitPreview({ outfitState }) { as="a" // eslint-disable-next-line no-script-url href={downloadImageUrl || "javascript:void 0"} - download="Outfit.png" + download={(outfitState.name || "Outfit") + ".png"} onMouseEnter={prepareDownload} onFocus={prepareDownload} + onClick={() => { + if (!downloadImageUrl) { + toast({ + title: + "Just a second, try again when the image is done loading!", + }); + } + }} variant="unstyled" color="gray.50" d="flex" diff --git a/src/WardrobePage.js b/src/WardrobePage.js index 3109b61..440f6c0 100644 --- a/src/WardrobePage.js +++ b/src/WardrobePage.js @@ -134,7 +134,10 @@ function ItemsPanel({ outfitState, loading, dispatchToOutfit }) { return ( - + {loading && [1, 2, 3].map((i) => ( @@ -163,12 +166,18 @@ function ItemsPanel({ outfitState, loading, dispatchToOutfit }) { ); } -function OutfitHeading() { +function OutfitHeading({ outfitState, dispatchToOutfit }) { return ( - + - + + dispatchToOutfit({ type: "rename", outfitName: value }) + } + > {({ isEditing, onRequestEdit }) => ( <> diff --git a/src/useOutfitState.js b/src/useOutfitState.js index 406b8ce..51b115a 100644 --- a/src/useOutfitState.js +++ b/src/useOutfitState.js @@ -12,6 +12,7 @@ function useOutfitState() { const [state, dispatchToOutfit] = React.useReducer( outfitStateReducer(apolloClient), { + name: "Zafara Agent (roopal27)", wornItemIds: new Set([ "38913", "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 // will find it more convenient to access them as arrays! e.g. for `.map()` @@ -79,6 +80,7 @@ function useOutfitState() { const outfitState = { zonesAndItems, + name, wornItemIds, allItemIds, speciesId, @@ -90,6 +92,8 @@ function useOutfitState() { const outfitStateReducer = (apolloClient) => (baseState, action) => { switch (action.type) { + case "rename": + return { ...baseState, name: action.outfitName }; case "wearItem": return produce(baseState, (state) => { // A hack to work around https://github.com/immerjs/immer/issues/586