mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Use mui components
This commit is contained in:
parent
bbec426232
commit
2e4848ade9
1 changed files with 65 additions and 57 deletions
|
@ -1,23 +1,31 @@
|
||||||
import React, { FormEvent, useCallback, useEffect, useRef, useState } from 'react';
|
import React, { ChangeEvent, FormEvent, useCallback, useEffect, useState } from 'react';
|
||||||
import type { LogFile } from '@jellyfin/sdk/lib/generated-client/models/log-file';
|
import type { LogFile } from '@jellyfin/sdk/lib/generated-client/models/log-file';
|
||||||
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
||||||
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
||||||
import LogItem from 'components/dashboard/logs/LogItem';
|
import LogItem from 'components/dashboard/logs/LogItem';
|
||||||
import Loading from 'components/loading/LoadingComponent';
|
import Loading from 'components/loading/LoadingComponent';
|
||||||
import Page from 'components/Page';
|
import Page from 'components/Page';
|
||||||
import ButtonElement from 'elements/ButtonElement';
|
|
||||||
import CheckBoxElement from 'elements/CheckBoxElement';
|
|
||||||
import InputElement from 'elements/InputElement';
|
|
||||||
import SectionTitleContainer from 'elements/SectionTitleContainer';
|
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
import globalize from 'lib/globalize';
|
import globalize from 'lib/globalize';
|
||||||
import toast from 'components/toast/toast';
|
import { Alert, Box, Button, FormControlLabel, Stack, Switch, TextField, Typography } from '@mui/material';
|
||||||
|
import { Form } from 'react-router-dom';
|
||||||
|
|
||||||
const Logs = () => {
|
const Logs = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
const [ logs, setLogs ] = useState<LogFile[]>([]);
|
const [ logs, setLogs ] = useState<LogFile[]>([]);
|
||||||
const [ loading, setLoading ] = useState(false);
|
const [ logsLoading, setLogsLoading ] = useState<boolean>(true);
|
||||||
const element = useRef<HTMLDivElement>(null);
|
const [ configLoading, setConfigLoading ] = useState<boolean>(true);
|
||||||
|
const [ logWarningMessageChecked, setLogWarningMessageChecked ] = useState<boolean>(false);
|
||||||
|
const [ slowResponseTime, setSlowResponseTime ] = useState<string>('');
|
||||||
|
const [ submitted, setSubmitted ] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const setLogWarningMessage = useCallback((_: ChangeEvent<HTMLInputElement>, checked: boolean) => {
|
||||||
|
setLogWarningMessageChecked(checked);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onResponseTimeChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
setSlowResponseTime(event.target.value);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const loadLogs = useCallback(() => {
|
const loadLogs = useCallback(() => {
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
@ -33,18 +41,14 @@ const Logs = () => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
|
||||||
const page = element.current;
|
|
||||||
|
|
||||||
if (!page) return;
|
|
||||||
|
|
||||||
getConfigurationApi(api)
|
getConfigurationApi(api)
|
||||||
.getConfiguration()
|
.getConfiguration()
|
||||||
.then(({ data: config }) => {
|
.then(({ data: config }) => {
|
||||||
config.EnableSlowResponseWarning = (page.querySelector('.chkSlowResponseWarning') as HTMLInputElement).checked;
|
config.EnableSlowResponseWarning = logWarningMessageChecked;
|
||||||
config.SlowResponseThresholdMs = parseInt((page.querySelector('#txtSlowResponseWarning') as HTMLInputElement).value, 10);
|
config.SlowResponseThresholdMs = parseInt(slowResponseTime, 10);
|
||||||
getConfigurationApi(api)
|
getConfigurationApi(api)
|
||||||
.updateConfiguration({ serverConfiguration: config })
|
.updateConfiguration({ serverConfiguration: config })
|
||||||
.then(() => toast(globalize.translate('SettingsSaved')))
|
.then(() => setSubmitted(true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('[logs] failed to update configuration data', err);
|
console.error('[logs] failed to update configuration data', err);
|
||||||
});
|
});
|
||||||
|
@ -52,37 +56,34 @@ const Logs = () => {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('[logs] failed to get configuration data', err);
|
console.error('[logs] failed to get configuration data', err);
|
||||||
});
|
});
|
||||||
}, [api]);
|
}, [api, logWarningMessageChecked, slowResponseTime]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
|
||||||
loadLogs()?.then(() => {
|
loadLogs()?.then(() => {
|
||||||
setLoading(false);
|
setLogsLoading(false);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('[logs] An error occurred while fetching logs', err);
|
console.error('[logs] An error occurred while fetching logs', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
const page = element.current;
|
|
||||||
|
|
||||||
if (!page || loading) return;
|
|
||||||
|
|
||||||
getConfigurationApi(api)
|
getConfigurationApi(api)
|
||||||
.getConfiguration()
|
.getConfiguration()
|
||||||
.then(({ data: config }) => {
|
.then(({ data: config }) => {
|
||||||
if (config.EnableSlowResponseWarning) {
|
if (config.EnableSlowResponseWarning) {
|
||||||
(page.querySelector('.chkSlowResponseWarning') as HTMLInputElement).checked = config.EnableSlowResponseWarning;
|
setLogWarningMessageChecked(config.EnableSlowResponseWarning);
|
||||||
}
|
}
|
||||||
if (config.SlowResponseThresholdMs != null) {
|
if (config.SlowResponseThresholdMs != null) {
|
||||||
(page.querySelector('#txtSlowResponseWarning') as HTMLInputElement).value = String(config.SlowResponseThresholdMs);
|
setSlowResponseTime(String(config.SlowResponseThresholdMs));
|
||||||
}
|
}
|
||||||
|
setConfigLoading(false);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('[logs] An error occurred while fetching system config', err);
|
console.error('[logs] An error occurred while fetching system config', err);
|
||||||
});
|
});
|
||||||
}, [loading, api, loadLogs]);
|
}, [logsLoading, configLoading, api, loadLogs]);
|
||||||
|
|
||||||
if (loading) {
|
if (logsLoading || configLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,38 +93,45 @@ const Logs = () => {
|
||||||
title={globalize.translate('TabLogs')}
|
title={globalize.translate('TabLogs')}
|
||||||
className='mainAnimatedPage type-interior'
|
className='mainAnimatedPage type-interior'
|
||||||
>
|
>
|
||||||
<div ref={element} className='content-primary'>
|
<Box className='content-primary'>
|
||||||
<form className='logsForm' onSubmit={onSubmit}>
|
<Form className='logsForm' method='POST' onSubmit={onSubmit}>
|
||||||
<div className='verticalSection'>
|
<Stack spacing={3}>
|
||||||
<SectionTitleContainer
|
<Typography variant='h1'>
|
||||||
title={globalize.translate('TabLogs')}
|
{globalize.translate('TabLogs')}
|
||||||
/>
|
</Typography>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='verticalSection'>
|
{submitted && (
|
||||||
<div className='checkboxContainer checkboxContainer-withDescription'>
|
<Alert severity='success'>
|
||||||
<CheckBoxElement
|
{globalize.translate('SettingsSaved')}
|
||||||
className='chkSlowResponseWarning'
|
</Alert>
|
||||||
title='LabelSlowResponseEnabled'
|
)}
|
||||||
|
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Switch
|
||||||
|
checked={logWarningMessageChecked}
|
||||||
|
onChange={setLogWarningMessage}
|
||||||
/>
|
/>
|
||||||
</div>
|
}
|
||||||
<div className='inputContainer'>
|
label={globalize.translate('LabelSlowResponseEnabled')}
|
||||||
<InputElement
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
type='number'
|
type='number'
|
||||||
id='txtSlowResponseWarning'
|
label={globalize.translate('LabelSlowResponseTime')}
|
||||||
label='LabelSlowResponseTime'
|
value={slowResponseTime}
|
||||||
|
onChange={onResponseTimeChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<br />
|
<Button
|
||||||
<div>
|
|
||||||
<ButtonElement
|
|
||||||
type='submit'
|
type='submit'
|
||||||
className='raised button-submit block'
|
size='large'
|
||||||
title='Save'
|
>
|
||||||
/>
|
{globalize.translate('Save')}
|
||||||
</div>
|
</Button>
|
||||||
</div>
|
</Stack>
|
||||||
</form>
|
</Form>
|
||||||
<div className='serverLogs readOnlyContent'>
|
<div className='serverLogs readOnlyContent'>
|
||||||
<div className='paperList'>
|
<div className='paperList'>
|
||||||
{logs.map(log => {
|
{logs.map(log => {
|
||||||
|
@ -134,7 +142,7 @@ const Logs = () => {
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Box>
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue