import styles from "./Panes.module.scss"; import { IntlContext, Text, translate } from "preact-i18n"; import { useContext, useEffect, useState } from "preact/hooks"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { UserProfile } from "../../../context/intermediate/popovers/UserProfile"; import { FileUploader } from "../../../context/revoltjs/FileUploads"; import { ClientStatus, StatusContext, useClient, } from "../../../context/revoltjs/RevoltClient"; import AutoComplete, { useAutoComplete, } from "../../../components/common/AutoComplete"; import Button from "../../../components/ui/Button"; import { Profile } from "revolt-api/types/Users"; export function Profile() { const { intl } = useContext(IntlContext); const status = useContext(StatusContext); const client = useClient(); const [profile, setProfile] = useState( undefined, ); // ! FIXME: temporary solution // ! we should just announce profile changes through WS function refreshProfile() { client .user!.fetchProfile() .then((profile) => setProfile(profile ?? {})); } useEffect(() => { if (profile === undefined && status === ClientStatus.ONLINE) { refreshProfile(); } }, [status]); const [changed, setChanged] = useState(false); function setContent(content?: string) { setProfile({ ...profile, content }); if (!changed) setChanged(true); } const { onChange, onKeyUp, onKeyDown, onFocus, onBlur, ...autoCompleteProps } = useAutoComplete(setContent, { users: { type: "all" }, }); return (

{}} />

client.users.edit({ avatar })} remove={() => client.users.edit({ remove: "Avatar" }) } defaultPreview={client.user!.generateAvatarURL( { max_side: 256 }, true, )} previewURL={client.user!.generateAvatarURL( { max_side: 256 }, true, )} />

{ await client.users.edit({ profile: { background }, }); refreshProfile(); }} remove={async () => { await client.users.edit({ remove: "ProfileBackground", }); setProfile({ ...profile, background: undefined }); }} previewURL={ profile?.background ? client.generateFileURL( profile.background, { width: 1000 }, true, ) : undefined } />

{ onChange(ev); setContent(ev.currentTarget.value); }} placeholder={translate( `app.settings.pages.profile.${ typeof profile === "undefined" ? "fetching" : "placeholder" }`, "", (intl as any).dictionary as Record, )} onKeyUp={onKeyUp} onKeyDown={onKeyDown} onFocus={onFocus} onBlur={onBlur} />

); }