Toast fixes/refactoring (#4289)

* Memoize Toast functions
* Rename Toast.success to Toast.toast, add new Toast.success
* Disable prefer-destructuring on AssignmentExpression
This commit is contained in:
DingDongSoLong4
2023-11-20 05:14:34 +02:00
committed by GitHub
parent 049a1b15c3
commit f9e11813f0
52 changed files with 336 additions and 387 deletions

View File

@@ -103,20 +103,6 @@ export const SettingsContext: React.FC = ({ children }) => {
const [apiKey, setApiKey] = useState("");
// cannot use Toast.error directly with the debounce functions
// since they are refreshed every time the Toast context is updated.
const [saveError, setSaveError] = useState<unknown>();
useEffect(() => {
if (!saveError) {
return;
}
Toast.error(saveError);
setSaveError(undefined);
setUpdateSuccess(false);
}, [saveError, Toast]);
useEffect(() => {
if (!data?.configuration || error) return;
@@ -144,6 +130,14 @@ export const SettingsContext: React.FC = ({ children }) => {
resetSuccess();
}, [resetSuccess]);
const onError = useCallback(
(err) => {
Toast.error(err);
setUpdateSuccess(false);
},
[Toast]
);
// saves the configuration if no further changes are made after a half second
const saveGeneralConfig = useDebounce(
async (input: GQL.ConfigGeneralInput) => {
@@ -158,7 +152,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingGeneral(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
},
500
@@ -207,7 +201,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingInterface(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
},
500
@@ -256,7 +250,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingDefaults(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
},
500
@@ -305,7 +299,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingScraping(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
},
500
@@ -353,7 +347,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingDLNA(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
}, 500);
@@ -399,7 +393,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingUI(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
}, 500);
@@ -453,7 +447,7 @@ export const SettingsContext: React.FC = ({ children }) => {
setPendingPlugins(undefined);
onSuccess();
} catch (e) {
setSaveError(e);
onError(e);
}
}, 500);