diff --git a/web/source/settings-panel/admin/actions.js b/web/source/settings-panel/admin/actions.js
index a9d779312..d4980d021 100644
--- a/web/source/settings-panel/admin/actions.js
+++ b/web/source/settings-panel/admin/actions.js
@@ -25,6 +25,7 @@ const Redux = require("react-redux");
const Submit = require("../components/submit");
const api = require("../lib/api");
+const submit = require("../lib/submit");
module.exports = function AdminActionPanel() {
const dispatch = Redux.useDispatch();
@@ -34,18 +35,10 @@ module.exports = function AdminActionPanel() {
const [errorMsg, setError] = React.useState("");
const [statusMsg, setStatus] = React.useState("");
- function submit() {
- setStatus("PATCHing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.admin.mediaCleanup(days));
- }).then(() => {
- setStatus("Saved!");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const removeMedia = submit(
+ () => dispatch(api.admin.mediaCleanup(days)),
+ {setStatus, setError}
+ );
return (
<>
@@ -61,7 +54,7 @@ module.exports = function AdminActionPanel() {
setDays(e.target.value)}/>
-
+
>
);
diff --git a/web/source/settings-panel/admin/federation.js b/web/source/settings-panel/admin/federation.js
index 1c5070efc..d57c0e1a4 100644
--- a/web/source/settings-panel/admin/federation.js
+++ b/web/source/settings-panel/admin/federation.js
@@ -28,6 +28,7 @@ const { formFields } = require("../components/form-fields");
const api = require("../lib/api");
const adminActions = require("../redux/reducers/admin").actions;
+const submit = require("../lib/submit");
const base = "/settings/admin/federation";
@@ -334,31 +335,15 @@ function InstancePage({domain, Form}) {
}
}
- function submit() {
- setStatus("PATCHing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.admin.updateDomainBlock(domain));
- }).then(() => {
- setStatus("Saved!");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const updateBlock = submit(
+ () => dispatch(api.admin.updateDomainBlock(domain)),
+ {setStatus, setError}
+ );
- function removeBlock() {
- setStatus("removing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.admin.removeDomainBlock(domain));
- }).then(() => {
- setStatus("removed");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const removeBlock = submit(
+ () => dispatch(api.admin.removeDomainBlock(domain)),
+ {setStatus, setError, startStatus: "Removing", successStatus: "Removed!"}
+ );
return (
@@ -381,7 +366,7 @@ function InstancePage({domain, Form}) {
/>
-
+
{!entry.new &&
diff --git a/web/source/settings-panel/admin/settings.js b/web/source/settings-panel/admin/settings.js
index c88aa4549..09c8580ac 100644
--- a/web/source/settings-panel/admin/settings.js
+++ b/web/source/settings-panel/admin/settings.js
@@ -25,6 +25,8 @@ const Redux = require("react-redux");
const Submit = require("../components/submit");
const api = require("../lib/api");
+const submit = require("../lib/submit");
+
const adminActions = require("../redux/reducers/instances").actions;
const {
@@ -35,23 +37,14 @@ const {
module.exports = function AdminSettings() {
const dispatch = Redux.useDispatch();
- const instance = Redux.useSelector(state => state.instances.adminSettings);
const [errorMsg, setError] = React.useState("");
const [statusMsg, setStatus] = React.useState("");
- function submit() {
- setStatus("PATCHing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.admin.updateInstance());
- }).then(() => {
- setStatus("Saved!");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const updateSettings = submit(
+ () => dispatch(api.admin.updateInstance()),
+ {setStatus, setError}
+ );
return (
@@ -111,7 +104,7 @@ module.exports = function AdminSettings() {
/>
*/}
-
+
);
};
\ No newline at end of file
diff --git a/web/source/settings-panel/lib/submit.js b/web/source/settings-panel/lib/submit.js
index 4092b292b..f268b5cf9 100644
--- a/web/source/settings-panel/lib/submit.js
+++ b/web/source/settings-panel/lib/submit.js
@@ -34,7 +34,6 @@ module.exports = function submit(func, {
}).then(() => {
setStatus(successStatus);
if (onSuccess != undefined) {
- console.log("running", onSuccess);
return onSuccess();
}
}).catch((e) => {
diff --git a/web/source/settings-panel/user/profile.js b/web/source/settings-panel/user/profile.js
index e06d3cde1..7cf3a7b52 100644
--- a/web/source/settings-panel/user/profile.js
+++ b/web/source/settings-panel/user/profile.js
@@ -26,6 +26,7 @@ const Submit = require("../components/submit");
const api = require("../lib/api");
const user = require("../redux/reducers/user").actions;
+const submit = require("../lib/submit");
const { formFields } = require("../components/form-fields");
@@ -46,18 +47,10 @@ module.exports = function UserProfile() {
const [errorMsg, setError] = React.useState("");
const [statusMsg, setStatus] = React.useState("");
- function submit() {
- setStatus("PATCHing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.user.updateProfile());
- }).then(() => {
- setStatus("Saved!");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const saveProfile = submit(
+ () => dispatch(api.user.updateProfile()),
+ {setStatus, setError}
+ );
return (
);
};
\ No newline at end of file
diff --git a/web/source/settings-panel/user/settings.js b/web/source/settings-panel/user/settings.js
index 29f382cb9..47d1a41d7 100644
--- a/web/source/settings-panel/user/settings.js
+++ b/web/source/settings-panel/user/settings.js
@@ -24,6 +24,7 @@ const Redux = require("react-redux");
const api = require("../lib/api");
const user = require("../redux/reducers/user").actions;
+const submit = require("../lib/submit");
const Languages = require("../components/languages");
const Submit = require("../components/submit");
@@ -39,18 +40,10 @@ module.exports = function UserSettings() {
const [errorMsg, setError] = React.useState("");
const [statusMsg, setStatus] = React.useState("");
- function submit() {
- setStatus("PATCHing");
- setError("");
- return Promise.try(() => {
- return dispatch(api.user.updateSettings());
- }).then(() => {
- setStatus("Saved!");
- }).catch((e) => {
- setError(e.message);
- setStatus("");
- });
- }
+ const updateSettings = submit(
+ () => dispatch(api.user.updateSettings()),
+ {setStatus, setError}
+ );
return (
<>
@@ -82,7 +75,7 @@ module.exports = function UserSettings() {
name="Mark my posts as sensitive by default"
/>
-
+
-
+
>
);
}
\ No newline at end of file