mirror of
https://github.com/owncast/owncast.git
synced 2024-11-27 07:53: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>
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
// EDIT CUSTOM CSS STYLES
|
|
import React, { useState, useEffect, useContext, FC } from 'react';
|
|
import { Typography, Button } from 'antd';
|
|
|
|
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';
|
|
import { FormStatusIndicator } from './FormStatusIndicator';
|
|
import { TextField, TEXTFIELD_TYPE_TEXTAREA } from './TextField';
|
|
import { UpdateArgs } from '../../types/config-section';
|
|
|
|
const { Title } = Typography;
|
|
|
|
export const EditCustomStyles: FC = () => {
|
|
const [content, setContent] = useState('');
|
|
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;
|
|
|
|
function handleFieldChange({ value }: UpdateArgs) {
|
|
setContent(value);
|
|
if (value !== initialContent && !hasChanged) {
|
|
setHasChanged(true);
|
|
} else if (value === initialContent && hasChanged) {
|
|
setHasChanged(false);
|
|
}
|
|
}
|
|
|
|
// 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]);
|
|
|
|
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{' '}
|
|
<a href="https://owncast.online/docs/website/" rel="noopener noreferrer" target="_blank">
|
|
CSS & Components guide
|
|
</a>
|
|
.
|
|
</p>
|
|
<p className="description">
|
|
Please input plain CSS text, as this will be directly injected onto your page during load.
|
|
</p>
|
|
|
|
<TextField
|
|
fieldName="customStyles"
|
|
type={TEXTFIELD_TYPE_TEXTAREA}
|
|
value={content}
|
|
maxLength={null}
|
|
onChange={handleFieldChange}
|
|
placeholder="/* Enter custom CSS here */"
|
|
/>
|
|
<br />
|
|
<div className="page-content-actions">
|
|
{hasChanged && (
|
|
<Button type="primary" onClick={handleSave}>
|
|
Save
|
|
</Button>
|
|
)}
|
|
<FormStatusIndicator status={submitStatus} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|