import React from "react"; import { css } from "emotion"; import gql from "graphql-tag"; import { Box, Button, Flex, IconButton, Input, Textarea, useColorModeValue, useTheme, useToast, } from "@chakra-ui/core"; import { CloseIcon } from "@chakra-ui/icons"; import { useHistory, useLocation } from "react-router-dom"; import { useLazyQuery } from "@apollo/client"; import { Heading1, usePageTitle } from "./util"; import OutfitPreview from "./components/OutfitPreview"; import SpeciesColorPicker from "./components/SpeciesColorPicker"; import HomepageSplashImg from "../images/homepage-splash.png"; import HomepageSplashImg2x from "../images/homepage-splash@2x.png"; import FeedbackXweeImg from "../images/feedback-xwee.png"; import FeedbackXweeImg2x from "../images/feedback-xwee@2x.png"; function HomePage() { usePageTitle(null); useSupportSetup(); const [previewState, setPreviewState] = React.useState(null); return ( } /> Dress to Impress Design and share your Neopets outfits! or ); } function StartOutfitForm({ onChange }) { const history = useHistory(); const idealPose = React.useMemo( () => (Math.random() > 0.5 ? "HAPPY_FEM" : "HAPPY_MASC"), [] ); const [speciesId, setSpeciesId] = React.useState("1"); const [colorId, setColorId] = React.useState("8"); const [isValid, setIsValid] = React.useState(true); const [closestPose, setClosestPose] = React.useState(idealPose); const onSubmit = (e) => { e.preventDefault(); if (!isValid) { return; } const params = new URLSearchParams({ species: speciesId, color: colorId, pose: closestPose, }); history.push(`/outfits/new?${params}`); }; const buttonBgColor = useColorModeValue("green.600", "green.300"); const buttonBgColorHover = useColorModeValue("green.700", "green.200"); return (
{ setSpeciesId(species.id); setColorId(color.id); setIsValid(isValid); setClosestPose(closestPose); if (isValid) { onChange({ speciesId: species.id, colorId: color.id, pose: closestPose, }); } }} />
); } function SubmitPetForm() { const history = useHistory(); const theme = useTheme(); const toast = useToast(); const [petName, setPetName] = React.useState(""); const [loadPet, { loading }] = useLazyQuery( gql` query SubmitPetForm($petName: String!) { petOnNeopetsDotCom(petName: $petName) { color { id } species { id } pose items { id } } } `, { fetchPolicy: "network-only", onCompleted: (data) => { if (!data) return; const { species, color, pose, items } = data.petOnNeopetsDotCom; const params = new URLSearchParams({ name: petName, species: species.id, color: color.id, pose, }); for (const item of items) { params.append("objects[]", item.id); } history.push(`/outfits/new?${params}`); }, onError: () => { toast({ title: "We couldn't load that pet, sorry 😓", description: "Is it spelled correctly?", status: "error", }); }, } ); const onSubmit = (e) => { e.preventDefault(); loadPet({ variables: { petName } }); // Start preloading the WardrobePage, too! // eslint-disable-next-line no-unused-expressions import("./WardrobePage"); }; const inputBorderColor = useColorModeValue("green.600", "green.500"); const inputBorderColorHover = useColorModeValue("green.400", "green.300"); const buttonBgColor = useColorModeValue("green.600", "green.300"); const buttonBgColorHover = useColorModeValue("green.700", "green.200"); return (
setPetName(e.target.value)} isDisabled={loading} placeholder="Enter a pet's name" aria-label="Enter a pet's name" borderColor={inputBorderColor} _hover={{ borderColor: inputBorderColorHover }} boxShadow="md" width="14em" className={css` &::placeholder { color: ${theme.colors.gray["500"]}; } `} />
); } function FeedbackFormSection() { const [isOpen, setIsOpen] = React.useState(false); const borderColor = useColorModeValue("gray.300", "blue.400"); const openButtonRef = React.useRef(null); const emailFieldRef = React.useRef(null); const elementAwaitingFocusRef = React.useRef(null); const openForm = React.useCallback(() => { setIsOpen(true); // Wait for the re-render to enable the field, then focus it. elementAwaitingFocusRef.current = emailFieldRef.current; }, [setIsOpen]); const closeForm = React.useCallback(() => { setIsOpen(false); // Wait for the re-render to enable the button, then focus it. elementAwaitingFocusRef.current = openButtonRef.current; }, [setIsOpen]); // This lil layout effect will focus whatever element is awaiting focus, then // clear it out. We use this to set up focus() calls, but wait until the next // layout finishes to actually call them. React.useLayoutEffect(() => { if (elementAwaitingFocusRef.current) { elementAwaitingFocusRef.current.focus(); elementAwaitingFocusRef.current = null; } }); return ( } size="xs" variant="ghost" onClick={closeForm} isDisabled={!isOpen} /> ); } function FeedbackFormPitch({ isDisabled, onClick, openButtonRef }) { return ( Hi friends! Welcome to the beta! This is the new Dress to Impress! It's ready for the future, and it even works great on mobile! More coming soon! Tell us what you think → ); } function FeedbackForm({ isDisabled, onClose, emailFieldRef }) { const [content, setContent] = React.useState(""); const toast = useToast(); return ( { e.preventDefault(); toast({ title: "Ah, well, this form isn't hooked up yet!", description: "That's coming soon! 😅 For now, please send an email to matchu@openneo.net. Sorry and thanks!", duration: null, isClosable: true, }); }} onKeyDown={(e) => { if (e.key === "Escape") { onClose(); e.stopPropagation(); } }} >