From d0ace4c26ac4ff12a3570c7a36cb7bb610357fb0 Mon Sep 17 00:00:00 2001 From: f0x Date: Fri, 9 Sep 2022 01:39:43 +0200 Subject: [PATCH] basic router layout, error boundary --- web/source/package.json | 1 + web/source/settings-panel/admin/index.js | 33 +++++ web/source/settings-panel/components/error.js | 45 +++++++ .../components}/submit.js | 0 web/source/settings-panel/index.js | 83 ++++++++---- web/source/settings-panel/style.css | 7 ++ web/source/settings-panel/user/index.js | 51 ++++++++ web/source/settings-panel/user/profile.js | 119 +++++++++++++++++- web/source/yarn.lock | 14 +++ 9 files changed, 325 insertions(+), 28 deletions(-) create mode 100644 web/source/settings-panel/admin/index.js create mode 100644 web/source/settings-panel/components/error.js rename web/source/{lib => settings-panel/components}/submit.js (100%) create mode 100644 web/source/settings-panel/user/index.js diff --git a/web/source/package.json b/web/source/package.json index a12d6fe77..8a561af42 100644 --- a/web/source/package.json +++ b/web/source/package.json @@ -34,6 +34,7 @@ "pretty-bytes": "^5.6.0", "react": "^17.0.1", "react-dom": "^17.0.1", + "react-error-boundary": "^3.1.4", "reactify": "^1.1.1", "uglifyify": "^5.0.2", "wouter": "^2.8.0-alpha.2" diff --git a/web/source/settings-panel/admin/index.js b/web/source/settings-panel/admin/index.js new file mode 100644 index 000000000..551f71af2 --- /dev/null +++ b/web/source/settings-panel/admin/index.js @@ -0,0 +1,33 @@ +/* + 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 . +*/ + +"use strict"; + +const Promise = require("bluebird"); +const React = require("react"); +const { Route, Switch } = require("wouter"); + +module.exports = function AdminPanel({oauth, routes}) { + return ( + + {routes.map(([path, component]) => { + return ; + })} + + ); +}; \ No newline at end of file diff --git a/web/source/settings-panel/components/error.js b/web/source/settings-panel/components/error.js new file mode 100644 index 000000000..e5e0ff139 --- /dev/null +++ b/web/source/settings-panel/components/error.js @@ -0,0 +1,45 @@ +/* + 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 . +*/ + +"use strict"; + +const Promise = require("bluebird"); +const React = require("react"); + +module.exports = function ErrorFallback({error, resetErrorBoundary}) { + return ( +
+

+ {"An error occured, please report this on the "} + GoToSocial issue tracker + {" or "} + Matrix support room. +
Include the details below: +

+
+				{error.name}: {error.message}
+			
+
+				{error.stack}
+			
+

+ or refresh the page +

+
+ ); +}; \ No newline at end of file diff --git a/web/source/lib/submit.js b/web/source/settings-panel/components/submit.js similarity index 100% rename from web/source/lib/submit.js rename to web/source/settings-panel/components/submit.js diff --git a/web/source/settings-panel/index.js b/web/source/settings-panel/index.js index c2586d12e..a69819f9c 100644 --- a/web/source/settings-panel/index.js +++ b/web/source/settings-panel/index.js @@ -22,23 +22,35 @@ const Promise = require("bluebird"); const React = require("react"); const ReactDom = require("react-dom"); const { Link, Route, Switch, useRoute, Redirect } = require("wouter"); +const { ErrorBoundary } = require("react-error-boundary"); const Auth = require("./components/auth"); +const ErrorFallback = require("./components/error"); + const oauthLib = require("./lib/oauth"); require("./style.css"); +const UserPanel = require("./user"); +const AdminPanel = require("./admin"); + const nav = { - "User": [ - ["Profile", require("./user/profile.js")], - ["Settings", require("./user/settings.js")], - ["Customization", require("./user/customization.js")] - ], - "Admin": [ - ["Instance Settings", require("./admin/settings.js")], - ["Federation", require("./admin/federation.js")], - ["Customization", require("./admin/customization.js")] - ] + "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") + } + } }; function urlSafe(str) { @@ -49,31 +61,50 @@ function urlSafe(str) { const sidebar = []; const panelRouter = []; -Object.entries(nav).forEach(([category, entries]) => { - let base = `/settings/${urlSafe(category)}`; +// Generate component tree from `nav` object once, as it won't change +Object.entries(nav).forEach(([name, {Component, entries}]) => { + let base = `/settings/${urlSafe(name)}`; + + let links = []; + let routes = []; + + let firstRoute; + + Object.entries(entries).forEach(([name, component]) => { + let url = `${base}/${urlSafe(name)}`; + + if (firstRoute == undefined) { + firstRoute = `${base}/${urlSafe(name)}`; + } + + routes.push([url, component]); + + links.push( + + ); + }); - // Category header goes to first page in category panelRouter.push( - + ); - let links = entries.map(([name, component]) => { - let url = `${base}/${urlSafe(name)}`; - - panelRouter.push( - - ); - - return ; - }); + let childrenPath = `${base}/:section`; + panelRouter.push( + + {}}> + {/* FIXME: implement onReset */} + + + + ); sidebar.push( - - + + -

{category}

+

{name}