2022-08-08 10:40:51 +02:00
|
|
|
/*
|
2022-09-09 20:43:55 +02:00
|
|
|
GoToSocial
|
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2022-08-08 10:40:51 +02:00
|
|
|
|
2022-09-09 20:43:55 +02:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2022-08-08 10:40:51 +02:00
|
|
|
|
2022-09-09 20:43:55 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
2022-08-08 10:40:51 +02:00
|
|
|
|
2022-09-09 20:43:55 +02:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-08-08 10:40:51 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-07 13:51:16 +02:00
|
|
|
"use strict";
|
2022-08-08 10:40:51 +02:00
|
|
|
|
2022-09-15 20:02:55 +02:00
|
|
|
const Promise = require("bluebird");
|
|
|
|
const React = require("react");
|
|
|
|
const Redux = require("react-redux");
|
2022-09-15 21:16:18 +02:00
|
|
|
const {Switch, Route, Link, useRoute} = require("wouter");
|
2022-09-15 20:02:55 +02:00
|
|
|
|
|
|
|
const Submit = require("../components/submit");
|
|
|
|
|
|
|
|
const api = require("../lib/api");
|
|
|
|
const adminActions = require("../redux/reducers/instances").actions;
|
|
|
|
|
2022-09-15 21:16:18 +02:00
|
|
|
const base = "/settings/admin/federation";
|
|
|
|
|
|
|
|
// const {
|
|
|
|
// TextInput,
|
|
|
|
// TextArea,
|
|
|
|
// File
|
|
|
|
// } = require("../components/form-fields").formFields(adminActions.setAdminSettingsVal, (state) => state.instances.adminSettings);
|
2022-09-15 20:02:55 +02:00
|
|
|
|
|
|
|
module.exports = function AdminSettings() {
|
|
|
|
const dispatch = Redux.useDispatch();
|
2022-09-15 21:16:18 +02:00
|
|
|
// const instance = Redux.useSelector(state => state.instances.adminSettings);
|
|
|
|
const { blockedInstances } = Redux.useSelector(state => state.admin);
|
2022-09-15 20:02:55 +02:00
|
|
|
|
|
|
|
const [errorMsg, setError] = React.useState("");
|
|
|
|
const [statusMsg, setStatus] = React.useState("");
|
|
|
|
|
2022-09-15 21:16:18 +02:00
|
|
|
const [loaded, setLoaded] = React.useState(false);
|
|
|
|
|
2022-09-15 20:02:55 +02:00
|
|
|
React.useEffect(() => {
|
2022-09-15 21:16:18 +02:00
|
|
|
if (blockedInstances != undefined) {
|
2022-09-15 20:02:55 +02:00
|
|
|
setLoaded(true);
|
2022-09-15 21:16:18 +02:00
|
|
|
} else {
|
|
|
|
return Promise.try(() => {
|
|
|
|
return dispatch(api.admin.fetchDomainBlocks());
|
|
|
|
}).then(() => {
|
|
|
|
setLoaded(true);
|
|
|
|
});
|
|
|
|
}
|
2022-09-15 20:02:55 +02:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!loaded) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>Federation</h1>
|
2022-09-15 21:16:18 +02:00
|
|
|
Loading...
|
2022-09-15 20:02:55 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-15 21:16:18 +02:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Switch>
|
|
|
|
<Route path={`${base}/:domain`}>
|
|
|
|
<InstancePage blockedInstances={blockedInstances}/>
|
|
|
|
</Route>
|
|
|
|
<InstanceOverview blockedInstances={blockedInstances} />
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function InstanceOverview({blockedInstances}) {
|
2022-09-15 20:02:55 +02:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>Federation</h1>
|
2022-09-15 21:16:18 +02:00
|
|
|
{blockedInstances.map((entry) => {
|
|
|
|
return (
|
|
|
|
<Link key={entry.domain} to={`${base}/${entry.domain}`}>
|
|
|
|
<a>{entry.domain}</a>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function BackButton() {
|
|
|
|
return (
|
|
|
|
<Link to={base}>
|
|
|
|
<a className="button">< back</a>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function InstancePage({blockedInstances}) {
|
|
|
|
let [_match, {domain}] = useRoute(`${base}/:domain`);
|
|
|
|
let [status, setStatus] = React.useState("");
|
|
|
|
let [entry, setEntry] = React.useState(() => {
|
|
|
|
let entry = blockedInstances.find((a) => a.domain == domain);
|
|
|
|
|
|
|
|
if (entry == undefined) {
|
|
|
|
setStatus(`No block entry found for ${domain}, but you can create one below:`);
|
|
|
|
return {
|
|
|
|
private_comment: ""
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{status}
|
|
|
|
<h1><BackButton/> Federation settings for: {domain}</h1>
|
|
|
|
<div>{entry.private_comment}</div>
|
2022-09-15 20:02:55 +02:00
|
|
|
</div>
|
|
|
|
);
|
2022-09-15 21:16:18 +02:00
|
|
|
}
|