gotosocial/web/source/settings-panel/index.js

115 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-09-07 12:51:16 +01:00
/*
2022-09-09 19:43:55 +01:00
GoToSocial
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
2022-09-07 12:51:16 +01:00
2022-09-09 19:43:55 +01: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-09-07 12:51:16 +01:00
2022-09-09 19:43:55 +01: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-09-07 12:51:16 +01:00
2022-09-09 19:43:55 +01: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-09-07 12:51:16 +01:00
*/
"use strict";
const Promise = require("bluebird");
const React = require("react");
const ReactDom = require("react-dom");
2022-09-09 19:43:55 +01:00
const Redux = require("react-redux");
const { Switch } = require("wouter");
const { Provider } = require("react-redux");
const { PersistGate } = require("redux-persist/integration/react");
2022-09-07 12:51:16 +01:00
2022-09-09 19:43:55 +01:00
const { store, persistor } = require("./redux");
const Login = require("./components/login");
2022-09-09 00:39:43 +01:00
const ErrorFallback = require("./components/error");
2022-09-07 12:51:16 +01:00
const oauthLib = require("./lib/oauth");
2022-09-09 19:43:55 +01:00
// require("./style.css");
2022-09-09 00:39:43 +01:00
2022-09-09 19:43:55 +01:00
// TODO: nested categories?
2022-09-07 12:51:16 +01:00
const nav = {
2022-09-09 00:39:43 +01:00
"User": {
Component: require("./user"),
entries: {
"Profile": require("./user/profile.js"),
"Settings": require("./user/settings.js"),
"Customization": require("./user/customization.js")
}
},
"Admin": {
Component: require("./admin"),
entries: {
"Instance Settings": require("./admin/settings.js"),
"Federation": require("./admin/federation.js"),
"Customization": require("./admin/customization.js")
}
}
2022-09-07 12:51:16 +01:00
};
2022-09-09 00:39:43 +01:00
// Generate component tree from `nav` object once, as it won't change
2022-09-09 19:43:55 +01:00
const { sidebar, panelRouter } = require("./lib/generate-views")(nav);
2022-09-07 12:51:16 +01:00
function App() {
2022-09-09 19:43:55 +01:00
const { loggedIn } = Redux.useSelector((state) => state.oauth);
// 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 (loggedIn) {
2022-09-07 12:51:16 +01:00
return (
<>
<div className="sidebar">
{sidebar}
2022-09-09 19:43:55 +01:00
{/* <button className="logout" onClick={oauth.logout}>Log out</button> */}
2022-09-07 12:51:16 +01:00
</div>
<section>
<Switch>
{panelRouter}
</Switch>
</section>
</>
);
} else {
2022-09-09 19:43:55 +01:00
return <Login />;
2022-09-07 12:51:16 +01:00
}
}
2022-09-09 19:43:55 +01:00
function Main() {
return (
<Provider store={store}>
<PersistGate loading={"loading..."} persistor={persistor}>
<App />
</PersistGate>
</Provider>
);
}
ReactDom.render(<React.StrictMode><Main /></React.StrictMode>, document.getElementById("root"));