cleanup, fix most eslint errors

This commit is contained in:
f0x 2022-11-07 20:05:17 +00:00
parent c37542932c
commit 17ffab3be9
11 changed files with 5 additions and 148 deletions

View file

@ -18,7 +18,6 @@
"use strict"; "use strict";
const Promise = require("bluebird");
const React = require("react"); const React = require("react");
const Redux = require("react-redux"); const Redux = require("react-redux");

View file

@ -45,7 +45,7 @@ module.exports = function EmojiDetailWrapped() {
</>); </>);
}; };
function EmojiDetail({emoji, Form}) { function EmojiDetail({emoji}) {
if (emoji == undefined) { if (emoji == undefined) {
return (<> return (<>
<Link to={base}> <Link to={base}>

View file

@ -50,7 +50,7 @@ module.exports = function AdminSettings() {
return dispatch(api.admin.fetchDomainBlocks()); return dispatch(api.admin.fetchDomainBlocks());
}); });
} }
}, []); }, [dispatch, loadedBlockedInstances]);
if (!loadedBlockedInstances) { if (!loadedBlockedInstances) {
return ( return (
@ -315,7 +315,7 @@ function InstancePage({domain, Form}) {
if (entry == undefined) { if (entry == undefined) {
dispatch(api.admin.getEditableDomainBlock(domain)); dispatch(api.admin.getEditableDomainBlock(domain));
} }
}, []); }, [dispatch, domain, entry]);
const [errorMsg, setError] = React.useState(""); const [errorMsg, setError] = React.useState("");
const [statusMsg, setStatus] = React.useState(""); const [statusMsg, setStatus] = React.useState("");

View file

@ -18,7 +18,6 @@
"use strict"; "use strict";
const Promise = require("bluebird");
const React = require("react"); const React = require("react");
const Redux = require("react-redux"); const Redux = require("react-redux");

View file

@ -94,7 +94,7 @@ function App() {
console.error(e); console.error(e);
}); });
} }
}, []); }, [loginState, dispatch]);
let ErrorElement = null; let ErrorElement = null;
if (errorMsg != undefined) { if (errorMsg != undefined) {

View file

@ -24,14 +24,12 @@ const d = require("dotty");
const { APIError, AuthenticationError } = require("../errors"); const { APIError, AuthenticationError } = require("../errors");
const { setInstanceInfo, setNamedInstanceInfo } = require("../../redux/reducers/instances").actions; const { setInstanceInfo, setNamedInstanceInfo } = require("../../redux/reducers/instances").actions;
const oauth = require("../../redux/reducers/oauth").actions;
function apiCall(method, route, payload, type = "json") { function apiCall(method, route, payload, type = "json") {
return function (dispatch, getState) { return function (dispatch, getState) {
const state = getState(); const state = getState();
let base = state.oauth.instance; let base = state.oauth.instance;
let auth = state.oauth.token; let auth = state.oauth.token;
console.log(method, base, route, "auth:", auth != undefined);
return Promise.try(() => { return Promise.try(() => {
let url = new URL(base); let url = new URL(base);

View file

@ -19,8 +19,7 @@
"use strict"; "use strict";
const React = require("react"); const React = require("react");
const Redux = require("react-redux"); const { Link, Route, Redirect } = require("wouter");
const { Link, Route, Switch, Redirect } = require("wouter");
const { ErrorBoundary } = require("react-error-boundary"); const { ErrorBoundary } = require("react-error-boundary");
const ErrorFallback = require("../components/error"); const ErrorFallback = require("../components/error");

View file

@ -1,134 +0,0 @@
/*
GoToSocial
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
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.
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.
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/>.
*/
"use strict";
const Promise = require("bluebird");
const React = require("react");
const ReactDom = require("react-dom");
const oauthLib = require("./oauth");
module.exports = function createPanel(clientName, scope, Component) {
ReactDom.render(<Panel/>, document.getElementById("root"));
function Panel() {
const [oauth, setOauth] = React.useState();
const [hasAuth, setAuth] = React.useState(false);
const [oauthState, setOauthState] = React.useState(localStorage.getItem("oauth"));
React.useEffect(() => {
let state = localStorage.getItem("oauth");
if (state != undefined) {
state = JSON.parse(state);
let restoredOauth = oauthLib(state.config, state);
Promise.try(() => {
return restoredOauth.callback();
}).then(() => {
setAuth(true);
});
setOauth(restoredOauth);
}
}, [setAuth, setOauth]);
if (!hasAuth && oauth && oauth.isAuthorized()) {
setAuth(true);
}
if (oauth && oauth.isAuthorized()) {
return <Component oauth={oauth} />;
} else if (oauthState != undefined) {
return "processing oauth...";
} else {
return <Auth setOauth={setOauth} />;
}
}
function Auth({setOauth}) {
const [ instance, setInstance ] = React.useState("");
React.useEffect(() => {
let isStillMounted = true;
// check if current domain runs an instance
let thisUrl = new URL(window.location.origin);
thisUrl.pathname = "/api/v1/instance";
Promise.try(() => {
return fetch(thisUrl.href);
}).then((res) => {
if (res.status == 200) {
return res.json();
}
}).then((json) => {
if (json && json.uri && isStillMounted) {
setInstance(json.uri);
}
}).catch((e) => {
console.log("error checking instance response:", e);
});
return () => {
// cleanup function
isStillMounted = false;
};
}, []);
function doAuth() {
return Promise.try(() => {
return new URL(instance);
}).catch(TypeError, () => {
return new URL(`https://${instance}`);
}).then((parsedURL) => {
let url = parsedURL.toString();
let oauth = oauthLib({
instance: url,
client_name: clientName,
scope: scope,
website: window.location.href
});
setOauth(oauth);
setInstance(url);
return oauth.register().then(() => {
return oauth;
});
}).then((oauth) => {
return oauth.authorize();
}).catch((e) => {
console.log("error authenticating:", e);
});
}
function updateInstance(e) {
if (e.key == "Enter") {
doAuth();
} else {
setInstance(e.target.value);
}
}
return (
<section className="login">
<h1>OAUTH Login:</h1>
<form onSubmit={(e) => e.preventDefault()}>
<label htmlFor="instance">Instance: </label>
<input value={instance} onChange={updateInstance} id="instance"/>
<button onClick={doAuth}>Authenticate</button>
</form>
</section>
);
}
};

View file

@ -18,8 +18,6 @@
"use strict"; "use strict";
const Promise = require("bluebird");
const base = require("./base"); const base = require("./base");
const endpoints = (build) => ({ const endpoints = (build) => ({

View file

@ -19,7 +19,6 @@
"use strict"; "use strict";
const { createSlice } = require("@reduxjs/toolkit"); const { createSlice } = require("@reduxjs/toolkit");
const defaultValue = require("default-value");
function sortBlocks(blocks) { function sortBlocks(blocks) {
return blocks.sort((a, b) => { // alphabetical sort return blocks.sort((a, b) => { // alphabetical sort

View file

@ -18,7 +18,6 @@
"use strict"; "use strict";
const Promise = require("bluebird");
const React = require("react"); const React = require("react");
const Redux = require("react-redux"); const Redux = require("react-redux");