mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user