mirror of
https://github.com/owncast/owncast.git
synced 2024-12-27 11:38:28 +03:00
d1f3fffe2f
* refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
164 lines
4.5 KiB
TypeScript
164 lines
4.5 KiB
TypeScript
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 (
|
|
<div className="edit-general-settings">
|
|
<Title level={3} className="section-title">
|
|
Configure Instance Details
|
|
</Title>
|
|
<br />
|
|
|
|
<TextFieldWithSubmit
|
|
fieldName="name"
|
|
{...TEXTFIELD_PROPS_SERVER_NAME}
|
|
value={formDataValues.name}
|
|
initialValue={instanceDetails.name}
|
|
onChange={handleFieldChange}
|
|
/>
|
|
|
|
<TextFieldWithSubmit
|
|
fieldName="instanceUrl"
|
|
{...TEXTFIELD_PROPS_INSTANCE_URL}
|
|
value={formDataValues.instanceUrl}
|
|
initialValue={yp.instanceUrl}
|
|
type={TEXTFIELD_TYPE_URL}
|
|
onChange={handleFieldChange}
|
|
onSubmit={handleSubmitInstanceUrl}
|
|
/>
|
|
|
|
<TextFieldWithSubmit
|
|
fieldName="summary"
|
|
{...TEXTFIELD_PROPS_SERVER_SUMMARY}
|
|
type={TEXTFIELD_TYPE_TEXTAREA}
|
|
value={formDataValues.summary}
|
|
initialValue={instanceDetails.summary}
|
|
onChange={handleFieldChange}
|
|
/>
|
|
|
|
<TextFieldWithSubmit
|
|
fieldName="offlineMessage"
|
|
{...TEXTFIELD_PROPS_SERVER_OFFLINE_MESSAGE}
|
|
type={TEXTFIELD_TYPE_TEXTAREA}
|
|
value={formDataValues.offlineMessage}
|
|
initialValue={instanceDetails.offlineMessage}
|
|
onChange={handleFieldChange}
|
|
/>
|
|
|
|
{/* Logo section */}
|
|
<EditLogo />
|
|
|
|
<ToggleSwitch
|
|
fieldName="hideViewerCount"
|
|
useSubmit
|
|
{...FIELD_PROPS_HIDE_VIEWER_COUNT}
|
|
checked={formDataValues.hideViewerCount}
|
|
onChange={handleHideViewerCountChange}
|
|
/>
|
|
|
|
<br />
|
|
<p className="description">
|
|
Increase your audience by appearing in the{' '}
|
|
<a href="https://directory.owncast.online" target="_blank" rel="noreferrer">
|
|
<strong>Owncast Directory</strong>
|
|
</a>
|
|
. This is an external service run by the Owncast project.{' '}
|
|
<a
|
|
href="https://owncast.online/docs/directory/?source=admin"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Learn more
|
|
</a>
|
|
.
|
|
</p>
|
|
{!yp.instanceUrl && (
|
|
<p className="description">
|
|
You must set your <strong>Server URL</strong> above to enable the directory.
|
|
</p>
|
|
)}
|
|
|
|
<div className="config-yp-container">
|
|
<ToggleSwitch
|
|
fieldName="enabled"
|
|
useSubmit
|
|
{...FIELD_PROPS_YP}
|
|
checked={formDataValues.enabled}
|
|
disabled={!hasInstanceUrl}
|
|
/>
|
|
<ToggleSwitch
|
|
fieldName="nsfw"
|
|
useSubmit
|
|
{...FIELD_PROPS_NSFW}
|
|
checked={formDataValues.nsfw}
|
|
disabled={!hasInstanceUrl}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|