owncast/web/components/config/cpu-usage.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-01-31 09:53:00 +03:00
import React, { useContext, useState, useEffect } from 'react';
2021-01-31 12:38:20 +03:00
import { Typography, Slider } from 'antd';
import { ServerStatusContext } from '../../utils/server-status-context';
2021-01-31 09:53:00 +03:00
const { Title } = Typography;
const SLIDER_MARKS = {
1: 'lowest',
2: '',
3: '',
4: '',
5: 'highest',
};
const TOOLTIPS = {
1: 'lowest',
2: 'low',
3: 'medium',
4: 'high',
5: 'highest',
};
interface Props {
defaultValue: number;
onChange: (arg: number) => void;
}
export default function CPUUsageSelector({ defaultValue, onChange }: Props) {
2021-01-31 09:53:00 +03:00
const [selectedOption, setSelectedOption] = useState(null);
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig } = serverStatusData || {};
const { videoSettings } = serverConfig || {};
if (!videoSettings) {
return null;
}
useEffect(() => {
setSelectedOption(defaultValue);
}, [videoSettings]);
2021-01-31 12:38:20 +03:00
2021-01-31 09:53:00 +03:00
const handleChange = value => {
2021-01-31 12:38:20 +03:00
setSelectedOption(value);
onChange(value);
2021-01-31 09:53:00 +03:00
};
return (
<div className="config-video-cpu-container">
<Title level={3}>CPU Usage</Title>
<p className="description">
There are trade-offs when considering CPU usage blah blah more wording here.
</p>
<div className="segment-slider-container">
2021-01-31 12:38:20 +03:00
<Slider
tipFormatter={value => TOOLTIPS[value]}
2021-01-31 09:53:00 +03:00
onChange={handleChange}
min={1}
max={Object.keys(SLIDER_MARKS).length}
marks={SLIDER_MARKS}
defaultValue={selectedOption}
value={selectedOption}
/>
2021-02-15 06:04:38 +03:00
<p className="selected-value-note">Selected: {TOOLTIPS[selectedOption]}</p>
2021-01-31 09:53:00 +03:00
</div>
</div>
);
2021-01-31 12:38:20 +03:00
}