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

63 lines
1.5 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',
};
2021-01-31 12:38:20 +03:00
export default function CPUUsageSelector({ defaultValue, onChange }) {
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-segements-conatiner">
2021-01-31 09:53:00 +03:00
<Title level={3}>CPU Usage</Title>
2021-01-31 12:38:20 +03:00
<p>There are trade-offs when considering CPU usage blah blah more wording here.</p>
<br />
<br />
<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}
/>
</div>
</div>
);
2021-01-31 12:38:20 +03:00
}