mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-04 21:37:31 +08:00 
			
		
		
		
	* Bump next from 10.2.3 to 11.0.1 Bumps [next](https://github.com/vercel/next.js) from 10.2.3 to 11.0.1. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/compare/v10.2.3...v11.0.1) --- updated-dependencies: - dependency-name: next dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * 🚨 apply automatic linting * 🎨 remove unused imports * 🔇 allow console.* to give more debugging options * 🎨 move stuff around to reduce linter messages * 🚨 use destructuring so lint won't complain * 📌 link Chartkick and Chart.js Commit uses the linking code which was previously imported with `import "chartkick/chart.js" [1]. Next did not like the import path, but this does works now. ¯\_(ツ)_/¯ [1]: https://github.com/ankane/chartkick.js/blob/master/chart.js/chart.esm.js Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
		
			
				
	
	
		
			118 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			118 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
// EDIT CUSTOM CSS STYLES
 | 
						|
import React, { useState, useEffect, useContext } 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 './form-status-indicator';
 | 
						|
 | 
						|
import TextField, { TEXTFIELD_TYPE_TEXTAREA } from './form-textfield';
 | 
						|
import { UpdateArgs } from '../../types/config-section';
 | 
						|
 | 
						|
const { Title } = Typography;
 | 
						|
 | 
						|
export default function EditCustomStyles() {
 | 
						|
  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>
 | 
						|
  );
 | 
						|
}
 |