From 5ce535682536468a3d1a6a267812823fc464bca3 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 29 Aug 2020 14:54:02 -0700 Subject: [PATCH] migrate to new useSupport hook Just smoothing out the API for cases where you want to know `isSupportUser`, but not the secret! --- .../support/ItemLayerSupportModal.js | 6 ++--- .../support/ItemLayerSupportUploadModal.js | 4 +-- .../WardrobePage/support/ItemSupportDrawer.js | 6 ++--- src/app/WardrobePage/support/SupportOnly.js | 6 ++--- .../WardrobePage/support/useSupportSecret.js | 26 ------------------- 5 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 src/app/WardrobePage/support/useSupportSecret.js diff --git a/src/app/WardrobePage/support/ItemLayerSupportModal.js b/src/app/WardrobePage/support/ItemLayerSupportModal.js index 68ce8ef..5e9826c 100644 --- a/src/app/WardrobePage/support/ItemLayerSupportModal.js +++ b/src/app/WardrobePage/support/ItemLayerSupportModal.js @@ -31,7 +31,7 @@ import SpeciesColorPicker from "../../components/SpeciesColorPicker"; import useOutfitAppearance, { itemAppearanceFragment, } from "../../components/useOutfitAppearance"; -import useSupportSecret from "./useSupportSecret"; +import useSupport from "./useSupport"; /** * ItemLayerSupportModal offers Support info and tools for a specific item @@ -52,7 +52,7 @@ function ItemLayerSupportModal({ isValid: true, }); const [uploadModalIsOpen, setUploadModalIsOpen] = React.useState(false); - const supportSecret = useSupportSecret(); + const { supportSecret } = useSupport(); const toast = useToast(); const [ @@ -362,7 +362,7 @@ function ItemLayerSupportModalRemoveButton({ }) { const { isOpen, onOpen, onClose } = useDisclosure(); const toast = useToast(); - const supportSecret = useSupportSecret(); + const { supportSecret } = useSupport(); const [mutate, { loading, error }] = useMutation( gql` diff --git a/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js b/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js index 5ae4b50..b1a4619 100644 --- a/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js +++ b/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js @@ -15,7 +15,7 @@ import { } from "@chakra-ui/core"; import { ExternalLinkIcon } from "@chakra-ui/icons"; -import useSupportSecret from "./useSupportSecret"; +import useSupport from "./useSupport"; /** * ItemLayerSupportUploadModal helps Support users create and upload PNGs for @@ -36,7 +36,7 @@ function ItemLayerSupportUploadModal({ item, itemLayer, isOpen, onClose }) { const [conflictMode, setConflictMode] = React.useState("onBlack"); - const supportSecret = useSupportSecret(); + const { supportSecret } = useSupport(); const toast = useToast(); const apolloClient = useApolloClient(); diff --git a/src/app/WardrobePage/support/ItemSupportDrawer.js b/src/app/WardrobePage/support/ItemSupportDrawer.js index fe1bfaa..438ac1b 100644 --- a/src/app/WardrobePage/support/ItemSupportDrawer.js +++ b/src/app/WardrobePage/support/ItemSupportDrawer.js @@ -32,7 +32,7 @@ import Metadata, { MetadataLabel, MetadataValue } from "./Metadata"; import { OutfitLayers } from "../../components/OutfitPreview"; import useOutfitAppearance from "../../components/useOutfitAppearance"; import { OutfitStateContext } from "../useOutfitState"; -import useSupportSecret from "./useSupportSecret"; +import useSupport from "./useSupport"; /** * ItemSupportDrawer shows Support UI for the item when open. @@ -195,7 +195,7 @@ function ItemSupportSpecialColorFields({ item, manualSpecialColor, }) { - const supportSecret = useSupportSecret(); + const { supportSecret } = useSupport(); const { loading: colorsLoading, @@ -324,7 +324,7 @@ function ItemSupportPetCompatibilityRuleFields({ item, explicitlyBodySpecific, }) { - const supportSecret = useSupportSecret(); + const { supportSecret } = useSupport(); const [ mutate, diff --git a/src/app/WardrobePage/support/SupportOnly.js b/src/app/WardrobePage/support/SupportOnly.js index 870066a..a1702bf 100644 --- a/src/app/WardrobePage/support/SupportOnly.js +++ b/src/app/WardrobePage/support/SupportOnly.js @@ -1,4 +1,4 @@ -import useSupportSecret from "./useSupportSecret"; +import useSupport from "./useSupport"; /** * SupportOnly only shows its contents to Support users. For most users, the @@ -12,8 +12,8 @@ import useSupportSecret from "./useSupportSecret"; * the server checks the provided secret for each Support request. */ function SupportOnly({ children }) { - const supportSecret = useSupportSecret(); - return supportSecret ? children : null; + const { isSupportUser } = useSupport(); + return isSupportUser ? children : null; } export default SupportOnly; diff --git a/src/app/WardrobePage/support/useSupportSecret.js b/src/app/WardrobePage/support/useSupportSecret.js deleted file mode 100644 index 160d200..0000000 --- a/src/app/WardrobePage/support/useSupportSecret.js +++ /dev/null @@ -1,26 +0,0 @@ -import * as React from "react"; - -/** - * useSupportSecret returns the Support secret that the server requires for - * Support actions... if the user has it set. For most users, this returns - * nothing! - * - * To become a Support user, you visit /?supportSecret=..., which saves the - * secret to your device. - * - * Note that this hook doesn't check that the secret is *correct*, so it's - * possible that it will return an invalid secret. That's okay, because - * the server checks the provided secret for each Support request. - * - * DEPRECATED: Use `useSupport` instead! - */ -function useSupportSecret() { - return React.useMemo(() => localStorage.getItem("supportSecret"), []); -} - -export function useIsSupportUser() { - const supportSecret = useSupportSecret(); - return supportSecret != null; -} - -export default useSupportSecret;