2021-04-12 10:07:08 +03:00
|
|
|
// EDIT CUSTOM CSS STYLES
|
2022-09-07 10:00:28 +03:00
|
|
|
import React, { useState, useEffect, useContext, FC } from 'react';
|
2021-04-12 10:07:08 +03:00
|
|
|
import { Typography, Button } from 'antd';
|
2022-10-11 05:47:36 +03:00
|
|
|
import CodeMirror from '@uiw/react-codemirror';
|
2022-10-11 06:16:08 +03:00
|
|
|
import { bbedit } from '@uiw/codemirror-theme-bbedit';
|
2022-10-11 05:47:36 +03:00
|
|
|
import { css } from '@codemirror/lang-css';
|
2021-04-12 10:07:08 +03:00
|
|
|
|
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
|
|
|
import {
|
|
|
|
postConfigUpdateToAPI,
|
|
|
|
RESET_TIMEOUT,
|
|
|
|
API_CUSTOM_CSS_STYLES,
|
|
|
|
} from '../../utils/config-constants';
|
|
|
|
import {
|
|
|
|
createInputStatus,
|
|
|
|
StatusState,
|
|
|
|
STATUS_ERROR,
|
|
|
|
STATUS_PROCESSING,
|
|
|
|
STATUS_SUCCESS,
|
|
|
|
} from '../../utils/input-statuses';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FormStatusIndicator } from './FormStatusIndicator';
|
2021-04-12 10:07:08 +03:00
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
|
2023-01-10 07:57:29 +03:00
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
2022-09-07 10:00:28 +03:00
|
|
|
export const EditCustomStyles: FC = () => {
|
2022-10-11 05:47:36 +03:00
|
|
|
const [content, setContent] = useState('/* Enter custom CSS here */');
|
2021-04-12 10:07:08 +03:00
|
|
|
const [submitStatus, setSubmitStatus] = useState<StatusState>(null);
|
|
|
|
const [hasChanged, setHasChanged] = useState(false);
|
|
|
|
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
|
|
|
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
|
|
|
|
|
|
|
|
const { instanceDetails } = serverConfig;
|
|
|
|
const { customStyles: initialContent } = instanceDetails;
|
|
|
|
|
|
|
|
let resetTimer = null;
|
|
|
|
|
|
|
|
// Clear out any validation states and messaging
|
|
|
|
const resetStates = () => {
|
|
|
|
setSubmitStatus(null);
|
|
|
|
setHasChanged(false);
|
|
|
|
clearTimeout(resetTimer);
|
|
|
|
resetTimer = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
// posts all the tags at once as an array obj
|
|
|
|
async function handleSave() {
|
|
|
|
setSubmitStatus(createInputStatus(STATUS_PROCESSING));
|
|
|
|
await postConfigUpdateToAPI({
|
|
|
|
apiPath: API_CUSTOM_CSS_STYLES,
|
|
|
|
data: { value: content },
|
|
|
|
onSuccess: (message: string) => {
|
|
|
|
setFieldInConfigState({
|
|
|
|
fieldName: 'customStyles',
|
|
|
|
value: content,
|
|
|
|
path: 'instanceDetails',
|
|
|
|
});
|
|
|
|
setSubmitStatus(createInputStatus(STATUS_SUCCESS, message));
|
|
|
|
},
|
|
|
|
onError: (message: string) => {
|
|
|
|
setSubmitStatus(createInputStatus(STATUS_ERROR, message));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setContent(initialContent);
|
|
|
|
}, [instanceDetails]);
|
|
|
|
|
2022-10-11 05:47:36 +03:00
|
|
|
const onCSSValueChange = React.useCallback(value => {
|
|
|
|
setContent(value);
|
|
|
|
if (value !== initialContent && !hasChanged) {
|
|
|
|
setHasChanged(true);
|
|
|
|
} else if (value === initialContent && hasChanged) {
|
|
|
|
setHasChanged(false);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2021-04-12 10:07:08 +03:00
|
|
|
return (
|
|
|
|
<div className="edit-custom-css">
|
|
|
|
<Title level={3} className="section-title">
|
|
|
|
Customize your page styling with CSS
|
|
|
|
</Title>
|
|
|
|
|
|
|
|
<p className="description">
|
|
|
|
Customize the look and feel of your Owncast instance by overriding the CSS styles of various
|
|
|
|
components on the page. Refer to the{' '}
|
2021-07-09 21:42:01 +03:00
|
|
|
<a href="https://owncast.online/docs/website/" rel="noopener noreferrer" target="_blank">
|
2021-04-12 10:07:08 +03:00
|
|
|
CSS & Components guide
|
2021-07-09 21:42:01 +03:00
|
|
|
</a>
|
|
|
|
.
|
2021-04-12 10:07:08 +03:00
|
|
|
</p>
|
|
|
|
<p className="description">
|
|
|
|
Please input plain CSS text, as this will be directly injected onto your page during load.
|
|
|
|
</p>
|
|
|
|
|
2022-10-11 05:47:36 +03:00
|
|
|
<CodeMirror
|
2021-04-12 10:07:08 +03:00
|
|
|
value={content}
|
|
|
|
placeholder="/* Enter custom CSS here */"
|
2022-10-11 06:16:08 +03:00
|
|
|
theme={bbedit}
|
2022-10-11 05:47:36 +03:00
|
|
|
height="200px"
|
|
|
|
extensions={[css()]}
|
|
|
|
onChange={onCSSValueChange}
|
2021-04-12 10:07:08 +03:00
|
|
|
/>
|
2022-10-11 05:47:36 +03:00
|
|
|
|
2021-04-12 10:07:08 +03:00
|
|
|
<br />
|
|
|
|
<div className="page-content-actions">
|
|
|
|
{hasChanged && (
|
|
|
|
<Button type="primary" onClick={handleSave}>
|
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
<FormStatusIndicator status={submitStatus} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|