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';
|
2021-02-07 06:38:58 +03:00
|
|
|
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',
|
|
|
|
};
|
|
|
|
|
2021-02-03 21:26:46 +03:00
|
|
|
const TOOLTIPS = {
|
|
|
|
1: 'lowest',
|
|
|
|
2: 'low',
|
|
|
|
3: 'medium',
|
|
|
|
4: 'high',
|
|
|
|
5: 'highest',
|
|
|
|
};
|
2021-02-13 10:55:59 +03:00
|
|
|
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 (
|
2021-02-15 05:46:34 +03:00
|
|
|
<div className="config-video-cpu-container">
|
|
|
|
<Title level={3}>CPU Usage</Title>
|
2021-02-13 10:55:59 +03:00
|
|
|
<p className="description">
|
|
|
|
There are trade-offs when considering CPU usage blah blah more wording here.
|
|
|
|
</p>
|
2021-02-04 19:04:00 +03:00
|
|
|
<div className="segment-slider-container">
|
2021-01-31 12:38:20 +03:00
|
|
|
<Slider
|
2021-02-04 19:04:00 +03:00
|
|
|
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
|
|
|
}
|