// Dependencies import { cloudflareImageUrl, getSearchParam } from '@freesewing/utils' // Context import { ModalContext } from '@freesewing/react/context/Modal' // Hooks import React, { useState, useEffect, useContext } from 'react' import { useAccount } from '@freesewing/react/hooks/useAccount' import { useBackend } from '@freesewing/react/hooks/useBackend' // Components import { ModalWrapper } from '@freesewing/react/components/Modal' import { Link as WebLink } from '@freesewing/react/components/Link' import { MiniWarning } from '@freesewing/react/components/Mini' import { KeyVal } from '@freesewing/react/components/KeyVal' import Markdown from 'react-markdown' /** * A component for to display the current user's profile. * * @component * @param {object} props - All component props * @param {React.FC} [props.Link = false] - An optional framework-specific Link component * @param {function} [props.setTitle = false] - An optional method to set the page title * @returns {JSX.Element} */ export const OwnProfile = (props) => { const { account } = useAccount() return } /** * A component for to display a user profile. Either props.uid or props.fromUrl should be set. * * @component * @param {object} props - All component props * @param {boolean} [props.fromUrl = false] - Set this to the nbame of the search parameters in the URL to extract the UID from * @param {React.FC} [props.Link = false] - An optional framework-specific Link component * @param {function} [props.setTitle = false] - An optional method to set the page title * @param {number} [props.uid = false] - The user ID for which to show the profile * @returns {JSX.Element} */ export const UserProfile = ({ Link = false, setTitle = false, uid = false, fromUrl = false }) => { if (!uid && !fromUrl) return ( You must provide either a uid or fromUrl prop ) if (!Link) Link = WebLink const [ruid, setRuid] = useState() // Hooks const backend = useBackend() // State const [data, setData] = useState(false) // Effect useEffect(() => { if (uid && uid !== ruid) setRuid(uid) if (fromUrl) { const urlId = getSearchParam(fromUrl) if (urlId && urlId !== ruid) setRuid(urlId) } if (ruid) loadProfileData(ruid, backend, setData, setTitle) }, [uid, fromUrl, ruid]) return ( <>

{data.username}

Permalink: {`freesewing.eu/users?id=${ruid}`}
{data.bio} ) } /** * A component to render an avatar image * * @component * @param {string} ihash - The ihash of the account * @returns {JSX.Element} */ export const Avatar = ({ ihash }) => { const { setModal } = useContext(ModalContext) return ( ) } async function loadProfileData(uid, backend, setData, setTitle = false) { const [status, body] = await backend.getUserProfile(uid) if (status === 200 && body.result === 'success' && body.profile) { setData(body.profile) if (typeof setTitle === 'function' && body.profile.username) setTitle(body.profile.username) } }