import { PageWrap } from '../../_shared/PageWrap' import { t } from '../../../utils/intl' import type { PageProps } from '../../types' import { Icon } from '../../_shared/Icon' import ProfileSettingsNavigation from '../../Discours/ProfileSettingsNavigation' import { For, createSignal, Show, onMount } from 'solid-js' import { clsx } from 'clsx' import styles from './Settings.module.scss' import { useProfileForm } from '../../../context/profile' import validateUrl from '../../../utils/validateUrl' export const ProfileSettingsPage = (props: PageProps) => { const [addLinkForm, setAddLinkForm] = createSignal(false) const [incorrectUrl, setIncorrectUrl] = createSignal(false) const { form, updateFormField, submit, slugError } = useProfileForm() let updateForm: HTMLFormElement const handleChangeSocial = (value: string) => { if (validateUrl(value)) { updateFormField('links', value) setAddLinkForm(false) } else { setIncorrectUrl(true) } } const handleSubmit = (event: Event): void => { event.preventDefault() submit(form) } let userpicFile: HTMLInputElement const handleFileUpload = async (file: File) => { const formData = new FormData() formData.append('file', file) console.log(formData) const response = await fetch('/api/upload', { method: 'POST', body: formData, headers: { 'Content-Type': 'multipart/form-data' } }) const json = await response.json() console.debug(json) } const handleUserpicUpload = async (ev) => { // TODO: show progress console.debug('handleUserpicUpload') try { const f = ev.target.files[0] if (f) await handleFileUpload(f) } catch (error) { console.error('[upload] error', error) } } const [hostname, setHostname] = createSignal('new.discours.io') onMount(() => setHostname(window?.location.host)) return (

{t('Profile settings')}

{t('Here you can customize your profile the way you want.')}

{t('Userpic')}

{form.name} userpicFile.click()} />

{t('Name')}

{t( 'Your name will appear on your profile page and as your signature in publications, comments and responses.' )}

updateFormField('name', event.currentTarget.value)} value={form.name} />

{t('Address on Discourse')}

updateFormField('slug', event.currentTarget.value)} value={form.slug} class="nolabel" />

{t(`${slugError()}`)}

{t('Introduce')}

{t('About myself')}