mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
proper redirect after removing block
This commit is contained in:
parent
7cebb50e0e
commit
9987399737
3 changed files with 37 additions and 19 deletions
|
@ -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 <InstancePage domain={domain} Form={fields} />;
|
||||
}
|
||||
|
||||
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,12 +328,8 @@ function InstancePage({domain, Form}) {
|
|||
const [statusMsg, setStatus] = React.useState("");
|
||||
|
||||
if (entry == undefined) {
|
||||
if (statusMsg == "removed") {
|
||||
return <Redirect to={base}/>;
|
||||
} else {
|
||||
return "Loading...";
|
||||
}
|
||||
}
|
||||
|
||||
const updateBlock = submit(
|
||||
() => dispatch(api.admin.updateDomainBlock(domain)),
|
||||
|
@ -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 (
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
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] }) => {
|
||||
|
|
Loading…
Reference in a new issue