// Dependencies import { welcomeSteps } from './shared.mjs' import { cloudflareImageUrl } from '@freesewing/utils' // Context import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus' // Hooks import React, { useState, useContext } from 'react' import { useAccount } from '@freesewing/react/hooks/useAccount' import { useBackend } from '@freesewing/react/hooks/useBackend' // Components import { Link as WebLink } from '@freesewing/react/components/Link' import { SaveIcon, RightIcon } from '@freesewing/react/components/Icon' import { PassiveImageInput } from '@freesewing/react/components/Input' import { IconButton } from '@freesewing/react/components/Button' import { WelcomeIcons } from './shared.mjs' /** * Component to manage the user's Avatar * * @component * @param {object} props - All component props * @param {boolean} [props.welcome = false] - Set to true to render the welcome/onboarding flow * @param {function} props.Link - A framework specific Link component for client-side routing * @returns {JSX.Element} */ export const Avatar = ({ welcome = false, Link = false }) => { if (!Link) Link = WebLink // Hooks const { account, setAccount } = useAccount() const backend = useBackend() // State const [img, setImg] = useState('') // Context const { setLoadingStatus } = useContext(LoadingStatusContext) // Save handler const save = async () => { setLoadingStatus([true, 'Uploading image']) const [status, body] = await backend.updateAccount({ img }) if (status === 200 && body.result === 'success') { setAccount(body.account) setLoadingStatus([true, 'Avatar saved', true, true]) } else setLoadingStatus([true, 'Failed to save avatar image. Please report this', true, false]) } // Next page in welcome flow const nextHref = '/docs/about/guide' return (
> )}