import React, { useState, useContext, useEffect, FC } from 'react'; import { Typography } from 'antd'; import { TextFieldWithSubmit, TEXTFIELD_TYPE_TEXTAREA, TEXTFIELD_TYPE_URL, } from './TextFieldWithSubmit'; import { ServerStatusContext } from '../../utils/server-status-context'; import { postConfigUpdateToAPI, TEXTFIELD_PROPS_INSTANCE_URL, TEXTFIELD_PROPS_SERVER_NAME, TEXTFIELD_PROPS_SERVER_SUMMARY, TEXTFIELD_PROPS_SERVER_OFFLINE_MESSAGE, API_YP_SWITCH, FIELD_PROPS_YP, FIELD_PROPS_NSFW, FIELD_PROPS_HIDE_VIEWER_COUNT, } from '../../utils/config-constants'; import { UpdateArgs } from '../../types/config-section'; import { ToggleSwitch } from './ToggleSwitch'; import { EditLogo } from './EditLogo'; const { Title } = Typography; export const EditInstanceDetails: FC = () => { const [formDataValues, setFormDataValues] = useState(null); const serverStatusData = useContext(ServerStatusContext); const { serverConfig } = serverStatusData || {}; const { instanceDetails, yp } = serverConfig; const { instanceUrl } = yp; useEffect(() => { setFormDataValues({ ...instanceDetails, ...yp, }); }, [instanceDetails, yp]); if (!formDataValues) { return null; } // if instanceUrl is empty, we should also turn OFF the `enabled` field of directory. const handleSubmitInstanceUrl = () => { if (formDataValues.instanceUrl === '') { if (yp.enabled === true) { postConfigUpdateToAPI({ apiPath: API_YP_SWITCH, data: { value: false }, }); } } }; const handleFieldChange = ({ fieldName, value }: UpdateArgs) => { setFormDataValues({ ...formDataValues, [fieldName]: value, }); }; function handleHideViewerCountChange(enabled: boolean) { handleFieldChange({ fieldName: 'hideViewerCount', value: enabled }); } const hasInstanceUrl = instanceUrl !== ''; return (
Configure Instance Details
{/* Logo section */}

Increase your audience by appearing in the{' '} Owncast Directory . This is an external service run by the Owncast project.{' '} Learn more .

{!yp.instanceUrl && (

You must set your Server URL above to enable the directory.

)}
); };