clean up and style tweaks

This commit is contained in:
gingervitis
2021-01-03 01:54:04 -08:00
committed by Gabe Kangas
parent 19ae6205c5
commit 5f0d7480bb
11 changed files with 81 additions and 54 deletions

View File

@@ -24,7 +24,6 @@ export const SUCCESS_STATES = {
};
export async function postConfigUpdateToAPI(args: ApiPostArgs) {
const {
apiPath,
@@ -38,9 +37,9 @@ export async function postConfigUpdateToAPI(args: ApiPostArgs) {
auth: true,
});
if (result.success && onSuccess) {
onSuccess();
onSuccess(result.message);
} else if (onError) {
onError();
onError(result.message);
}
}
@@ -96,7 +95,7 @@ export const TEXTFIELD_DEFAULTS = {
maxLength: 255,
placeholder: '/img/mylogo.png',
label: 'Logo',
tip: 'Path to your logo from website root',
tip: 'Path to your logo from website root. We recommend that you use a square image that is at least 256x256. (upload functionality coming soon)',
},
extraPageContent: {
@@ -113,8 +112,6 @@ export const TEXTFIELD_DEFAULTS = {
tip: "Turn this ON if you plan to steam explicit or adult content. You may want to respectfully set this flag so that unexpecting eyes won't accidentally see it from the Directory.",
},
//
tags: {
apiPath: '/tags',
defaultValue: '',

View File

@@ -42,7 +42,7 @@ export default function EditYPDetails() {
<p>Would you like to appear in the <a href="https://directory.owncast.online" target="_blank" rel="noreferrer"><strong>Owncast Directory</strong></a>?</p>
<p><em>NOTE: You will need to have a URL specified in the <code>Instance URL</code> field to be able to use this.</em></p>
<p style={{ backgroundColor: 'black', fontSize: '.75rem', padding: '5px' }}><em>NOTE: You will need to have a URL specified in the <code>Instance URL</code> field to be able to use this.</em></p>
<div className="config-yp-container">
<Form

View File

@@ -12,7 +12,7 @@ export default function EditInstanceTags() {
const [submitStatus, setSubmitStatus] = useState(null);
const [submitStatusMessage, setSubmitStatusMessage] = useState('');
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig, setConfigField } = serverStatusData || {};
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
const { instanceDetails } = serverConfig;
const { tags = [] } = instanceDetails;
@@ -47,7 +47,7 @@ export default function EditInstanceTags() {
apiPath,
data: { value: postValue },
onSuccess: () => {
setConfigField({ fieldName: 'tags', value: postValue, path: configPath });
setFieldInConfigState({ fieldName: 'tags', value: postValue, path: configPath });
setSubmitStatus('success');
setSubmitStatusMessage('Tags updated.');
setNewTagInput('');

View File

@@ -17,15 +17,14 @@ update vals to state, andthru api.
*/
import React, { useState, useContext } from 'react';
import { Button, Form, Input, InputNumber, Tooltip } from 'antd';
import { Button, Form, Input, InputNumber } from 'antd';
import { FormItemProps } from 'antd/es/form';
import { InfoCircleOutlined } from '@ant-design/icons';
import { TEXTFIELD_DEFAULTS, TEXT_MAXLENGTH, RESET_TIMEOUT, postConfigUpdateToAPI } from './constants';
import { TextFieldProps } from '../../../types/config-section';
import { ServerStatusContext } from '../../../utils/server-status-context';
import InfoTip from '../info-tip';
export const TEXTFIELD_TYPE_TEXT = 'default';
export const TEXTFIELD_TYPE_PASSWORD = 'password'; // Input.Password
@@ -42,7 +41,7 @@ export default function TextField(props: TextFieldProps) {
let resetTimer = null;
const serverStatusData = useContext(ServerStatusContext);
const { setConfigField } = serverStatusData || {};
const { setFieldInConfigState } = serverStatusData || {};
const {
configPath = '',
@@ -107,7 +106,7 @@ export default function TextField(props: TextFieldProps) {
apiPath,
data: { value: fieldValueForSubmit },
onSuccess: () => {
setConfigField({ fieldName, value: fieldValueForSubmit, path: configPath });
setFieldInConfigState({ fieldName, value: fieldValueForSubmit, path: configPath });
setSubmitStatus('success');
},
onError: (message: string) => {
@@ -144,11 +143,7 @@ export default function TextField(props: TextFieldProps) {
return (
<div className="textfield-container">
<div className="textfield">
<span className="info">
<Tooltip title={tip}>
<InfoCircleOutlined />
</Tooltip>
</span>
<InfoTip tip={tip} />
<Form.Item
label={label}
name={fieldName}

View File

@@ -1,13 +1,12 @@
import React, { useState, useContext } from 'react';
import { Form, Switch, Tooltip } from 'antd';
import { Form, Switch } from 'antd';
import { FormItemProps } from 'antd/es/form';
import { InfoCircleOutlined } from '@ant-design/icons';
import { TEXTFIELD_DEFAULTS, RESET_TIMEOUT, SUCCESS_STATES, postConfigUpdateToAPI } from './constants';
import { ToggleSwitchProps } from '../../../types/config-section';
import { ServerStatusContext } from '../../../utils/server-status-context';
import InfoTip from '../info-tip';
export const TEXTFIELD_TYPE_TEXT = 'default';
export const TEXTFIELD_TYPE_PASSWORD = 'password'; // Input.Password
@@ -22,7 +21,7 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
let resetTimer = null;
const serverStatusData = useContext(ServerStatusContext);
const { setConfigField } = serverStatusData || {};
const { setFieldInConfigState } = serverStatusData || {};
const {
fieldName,
@@ -53,7 +52,7 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
apiPath,
data: { value: checked },
onSuccess: () => {
setConfigField({ fieldName, value: checked, path: configPath });
setFieldInConfigState({ fieldName, value: checked, path: configPath });
setSubmitStatus('success');
},
onError: (message: string) => {
@@ -69,14 +68,6 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
message: newStatusMessage = '',
} = SUCCESS_STATES[submitStatus] || {};
const tipComponent = tip ? (
<span className="info">
<Tooltip title={tip}>
<InfoCircleOutlined />
</Tooltip>
</span>
) : null;
return (
<div className="toggleswitch-container">
<div className="toggleswitch">
@@ -95,8 +86,8 @@ export default function ToggleSwitch(props: ToggleSwitchProps) {
/>
</Form.Item>
<span className="label">{label}</span>
{tipComponent}
<span className="label">{label} <InfoTip tip={tip} /></span>
</div>
<div className={`status-message ${submitStatus || ''}`}>
{newStatusIcon} {newStatusMessage} {submitStatusMessage}

View File

@@ -0,0 +1,20 @@
import { InfoCircleOutlined } from "@ant-design/icons";
import { Tooltip } from "antd";
interface InfoTipProps {
tip: string | null;
}
export default function InfoTip({ tip }: InfoTipProps) {
if (tip === '' || tip === null) {
return null;
}
return (
<span className="info-tip">
<Tooltip title={tip}>
<InfoCircleOutlined />
</Tooltip>
</span>
);
}