mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
refactor(Settings): load data_export model on click
This commit is contained in:
parent
2c3e656eb5
commit
2371ca1d3f
2 changed files with 24 additions and 13 deletions
|
|
@ -21,7 +21,7 @@ const Settings = () => {
|
|||
const { core } = useServices();
|
||||
const { routeFocused } = useRouteFocused();
|
||||
const profile = useProfile();
|
||||
const dataExport = useDataExport();
|
||||
const [dataExport, loadDataExport] = useDataExport();
|
||||
const streamingServer = useStreamingServer();
|
||||
const {
|
||||
interfaceLanguageSelect,
|
||||
|
|
@ -84,10 +84,8 @@ const Settings = () => {
|
|||
// TODO
|
||||
}, []);
|
||||
const exportDataOnClick = React.useCallback(() => {
|
||||
if (dataExport.exportUrl !== null && typeof dataExport.exportUrl === 'string') {
|
||||
window.open(dataExport.exportUrl);
|
||||
}
|
||||
}, [dataExport.exportUrl]);
|
||||
loadDataExport();
|
||||
}, []);
|
||||
const reloadStreamingServer = React.useCallback(() => {
|
||||
core.transport.dispatch({
|
||||
action: 'StreamingServer',
|
||||
|
|
@ -132,6 +130,11 @@ const Settings = () => {
|
|||
const sectionsContainerOnScorll = React.useCallback(throttle(() => {
|
||||
updateSelectedSectionId();
|
||||
}, 50), []);
|
||||
React.useEffect(() => {
|
||||
if (dataExport.exportUrl !== null && typeof dataExport.exportUrl === 'string') {
|
||||
window.open(dataExport.exportUrl);
|
||||
}
|
||||
}, [dataExport.exportUrl]);
|
||||
React.useLayoutEffect(() => {
|
||||
if (routeFocused) {
|
||||
updateSelectedSectionId();
|
||||
|
|
@ -244,7 +247,7 @@ const Settings = () => {
|
|||
</Button>
|
||||
</div>
|
||||
<div className={styles['option-container']}>
|
||||
<Button className={classnames(styles['option-input-container'], styles['link-container'])} title={'Export user data'} disabled={dataExport.exportUrl === null} tabIndex={-1} onClick={exportDataOnClick}>
|
||||
<Button className={classnames(styles['option-input-container'], styles['link-container'])} title={'Export user data'} tabIndex={-1} onClick={exportDataOnClick}>
|
||||
<div className={styles['label']}>Export user data</div>
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (C) 2017-2022 Smart code 203358507
|
||||
|
||||
const React = require('react');
|
||||
const { useServices } = require('stremio/services');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const map = (dataExport) => ({
|
||||
|
|
@ -12,13 +13,20 @@ const map = (dataExport) => ({
|
|||
});
|
||||
|
||||
const useDataExport = () => {
|
||||
const action = React.useMemo(() => ({
|
||||
action: 'Load',
|
||||
args: {
|
||||
model: 'DataExport',
|
||||
}
|
||||
}), []);
|
||||
return useModelState({ model: 'data_export', action, map });
|
||||
const { core } = useServices();
|
||||
const loadDataExport = React.useCallback(() => {
|
||||
core.transport.dispatch({
|
||||
action: 'Load',
|
||||
args: {
|
||||
model: 'DataExport',
|
||||
}
|
||||
}, 'data_export');
|
||||
}, []);
|
||||
const dataExport = useModelState({ model: 'data_export', map });
|
||||
return [
|
||||
dataExport,
|
||||
loadDataExport
|
||||
];
|
||||
};
|
||||
|
||||
module.exports = useDataExport;
|
||||
|
|
|
|||
Loading…
Reference in a new issue