From 9987399737ce3d9ad70ab75dd09053e0e6a35751 Mon Sep 17 00:00:00 2001 From: f0x Date: Sun, 18 Sep 2022 22:24:41 +0200 Subject: [PATCH] proper redirect after removing block --- web/source/settings-panel/admin/federation.js | 18 +++++++-------- web/source/settings-panel/lib/api/admin.js | 16 ++++++++++++-- .../settings-panel/redux/reducers/admin.js | 22 +++++++++++++------ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/web/source/settings-panel/admin/federation.js b/web/source/settings-panel/admin/federation.js index d57c0e1a4..7afc3c699 100644 --- a/web/source/settings-panel/admin/federation.js +++ b/web/source/settings-panel/admin/federation.js @@ -308,19 +308,19 @@ function InstancePageWrapped() { return adminActions.updateDomainBlockVal([domain, key, val]); } - const fields = formFields(alterDomain, (state) => state.admin.blockedInstances[domain]); + const fields = formFields(alterDomain, (state) => state.admin.newInstanceBlocks[domain]); return ; } function InstancePage({domain, Form}) { const dispatch = Redux.useDispatch(); - const { blockedInstances } = Redux.useSelector(state => state.admin); - const entry = blockedInstances[domain]; + const entry = Redux.useSelector(state => state.admin.newInstanceBlocks[domain]); + const [_location, setLocation] = useLocation(); React.useEffect(() => { if (entry == undefined) { - dispatch(adminActions.newDomainBlock(domain)); + dispatch(api.admin.getEditableDomainBlock(domain)); } }, []); @@ -328,11 +328,7 @@ function InstancePage({domain, Form}) { const [statusMsg, setStatus] = React.useState(""); if (entry == undefined) { - if (statusMsg == "removed") { - return ; - } else { - return "Loading..."; - } + return "Loading..."; } const updateBlock = submit( @@ -342,7 +338,9 @@ function InstancePage({domain, Form}) { const removeBlock = submit( () => dispatch(api.admin.removeDomainBlock(domain)), - {setStatus, setError, startStatus: "Removing", successStatus: "Removed!"} + {setStatus, setError, startStatus: "Removing", successStatus: "Removed!", onSuccess: () => { + setLocation(base); + }} ); return ( diff --git a/web/source/settings-panel/lib/api/admin.js b/web/source/settings-panel/lib/api/admin.js index 30b72f5e0..421bdf8cd 100644 --- a/web/source/settings-panel/lib/api/admin.js +++ b/web/source/settings-panel/lib/api/admin.js @@ -57,18 +57,28 @@ module.exports = function ({ apiCall, getChanges }) { updateDomainBlock: function updateDomainBlock(domain) { return function (dispatch, getState) { return Promise.try(() => { - const state = getState().admin.blockedInstances[domain]; + const state = getState().admin.newInstanceBlocks[domain]; const update = getChanges(state, { formKeys: ["domain", "obfuscate", "public_comment", "private_comment"], }); return dispatch(apiCall("POST", "/api/v1/admin/domain_blocks", update, "form")); }).then((block) => { - console.log(block); + return Promise.all([ + dispatch(admin.newDomainBlock([domain, block])), + dispatch(admin.setDomainBlock([domain, block])) + ]); }); }; }, + getEditableDomainBlock: function getEditableDomainBlock(domain) { + return function (dispatch, getState) { + let data = getState().admin.blockedInstances[domain]; + return dispatch(admin.newDomainBlock([domain, data])); + }; + }, + bulkDomainBlock: function bulkDomainBlock() { return function (dispatch, getState) { let invalidDomains = []; @@ -138,6 +148,8 @@ module.exports = function ({ apiCall, getChanges }) { return Promise.try(() => { const id = getState().admin.blockedInstances[domain].id; return dispatch(apiCall("DELETE", `/api/v1/admin/domain_blocks/${id}`)); + }).then((removed) => { + return dispatch(admin.removeDomainBlock(removed.domain)); }); }; }, diff --git a/web/source/settings-panel/redux/reducers/admin.js b/web/source/settings-panel/redux/reducers/admin.js index e534b1a3d..20d3d748d 100644 --- a/web/source/settings-panel/redux/reducers/admin.js +++ b/web/source/settings-panel/redux/reducers/admin.js @@ -51,6 +51,7 @@ module.exports = createSlice({ exportType: "plain", ...emptyBlock() }, + newInstanceBlocks: {}, emoji: {}, newEmoji: emptyEmojiForm() }, @@ -63,20 +64,27 @@ module.exports = createSlice({ state.loadedBlockedInstances = true; }, - newDomainBlock: (state, { payload: domain }) => { - state.blockedInstances[domain] = { - domain, - new: true, - ...emptyBlock() - }; + newDomainBlock: (state, { payload: [domain, data] }) => { + if (data == undefined) { + data = { + new: true, + domain, + ...emptyBlock() + }; + } + state.newInstanceBlocks[domain] = data; }, setDomainBlock: (state, { payload: [domain, data = {}] }) => { state.blockedInstances[domain] = data; }, + removeDomainBlock: (state, {payload: domain}) => { + delete state.blockedInstances[domain]; + }, + updateDomainBlockVal: (state, { payload: [domain, key, val] }) => { - state.blockedInstances[domain][key] = val; + state.newInstanceBlocks[domain][key] = val; }, updateBulkBlockVal: (state, { payload: [key, val] }) => {