From aecf74951cecb4de9ca94dd93e48af6f62300a0f Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:24:24 +0200 Subject: [PATCH] [chore] Settings refactor 2: the re-refactoring-ing (#2866) * [chore] Bit more refactoring of settings panel * fix up some remaining things * groovy baby yeah! * remove unused Suspense --- web/source/index.js | 2 +- web/source/package.json | 8 +- .../{back-button.jsx => back-button.tsx} | 0 .../{combo-box.jsx => combo-box.tsx} | 12 +- .../components/{error.jsx => error.tsx} | 4 +- .../{fake-profile.jsx => fake-profile.tsx} | 6 +- .../{fake-toot.jsx => fake-toot.tsx} | 11 +- .../{languages.jsx => languages.tsx} | 10 +- .../components/{loading.jsx => loading.tsx} | 6 +- ...r-logout-card.jsx => user-logout-card.tsx} | 15 +- web/source/settings/index.tsx | 35 +- web/source/settings/style.css | 20 +- .../views/admin/actions/keys/expireremote.tsx | 2 +- .../views/admin/actions/media/cleanup.tsx | 2 +- .../views/admin/emoji/local/new-emoji.tsx | 2 +- .../views/admin/emoji/local/overview.tsx | 2 +- .../rules.tsx => instance/ruledetail.tsx} | 60 +- .../settings/views/admin/instance/rules.tsx | 75 ++ .../index.tsx => instance/settings.tsx} | 10 +- web/source/settings/views/admin/menu.tsx | 129 ++ web/source/settings/views/admin/router.tsx | 151 +++ web/source/settings/views/admin/routes.tsx | 177 --- .../moderation/accounts/detail/actions.tsx | 5 +- .../accounts/detail/handlesignup.tsx | 6 +- .../moderation/accounts/detail/index.tsx | 5 +- .../moderation/accounts/pending/index.tsx | 2 +- .../moderation/accounts/search/index.tsx | 3 +- .../moderation/domain-permissions/form.tsx | 4 - .../domain-permissions/overview.tsx | 3 - .../moderation/domain-permissions/process.tsx | 2 - web/source/settings/views/moderation/menu.tsx | 121 ++ .../views/moderation/reports/detail.tsx | 10 +- .../views/moderation/reports/overview.tsx | 4 +- .../views/moderation/reports/username.tsx | 36 +- .../moderation/{routes.tsx => router.tsx} | 180 +-- .../query/index.js => views/user/menu.tsx} | 39 +- web/source/settings/views/user/profile.tsx | 3 +- .../views/user/{routes.tsx => router.tsx} | 60 +- web/source/settings/views/user/settings.tsx | 9 +- web/source/tsconfig.json | 6 +- web/source/yarn.lock | 1081 ++++++++++------- 41 files changed, 1360 insertions(+), 958 deletions(-) rename web/source/settings/components/{back-button.jsx => back-button.tsx} (100%) rename web/source/settings/components/{combo-box.jsx => combo-box.tsx} (85%) rename web/source/settings/components/{error.jsx => error.tsx} (96%) rename web/source/settings/components/{fake-profile.jsx => fake-profile.tsx} (93%) rename web/source/settings/components/{fake-toot.jsx => fake-toot.tsx} (90%) rename web/source/settings/components/{languages.jsx => languages.tsx} (86%) rename web/source/settings/components/{loading.jsx => loading.tsx} (92%) rename web/source/settings/components/{user-logout-card.jsx => user-logout-card.tsx} (84%) rename web/source/settings/views/admin/{settings/rules.tsx => instance/ruledetail.tsx} (63%) create mode 100644 web/source/settings/views/admin/instance/rules.tsx rename web/source/settings/views/admin/{settings/index.tsx => instance/settings.tsx} (96%) create mode 100644 web/source/settings/views/admin/menu.tsx create mode 100644 web/source/settings/views/admin/router.tsx delete mode 100644 web/source/settings/views/admin/routes.tsx create mode 100644 web/source/settings/views/moderation/menu.tsx rename web/source/settings/views/moderation/{routes.tsx => router.tsx} (52%) rename web/source/settings/{lib/query/index.js => views/user/menu.tsx} (57%) rename web/source/settings/views/user/{routes.tsx => router.tsx} (58%) diff --git a/web/source/index.js b/web/source/index.js index d9ef70ff9..5cee28046 100644 --- a/web/source/index.js +++ b/web/source/index.js @@ -96,4 +96,4 @@ skulk({ }]] } } -}); \ No newline at end of file +}); diff --git a/web/source/package.json b/web/source/package.json index d72cf7764..919bf3c83 100644 --- a/web/source/package.json +++ b/web/source/package.json @@ -35,10 +35,10 @@ "wouter": "^3.1.0" }, "devDependencies": { - "@babel/core": "^7.23.0", - "@babel/preset-env": "^7.22.20", - "@babel/preset-react": "^7.22.15", - "@babel/preset-typescript": "^7.23.0", + "@babel/core": "^7.24.4", + "@babel/preset-env": "^7.24.4", + "@babel/preset-react": "^7.24.1", + "@babel/preset-typescript": "^7.24.1", "@browserify/envify": "^6.0.0", "@browserify/uglifyify": "^6.0.0", "@joepie91/eslint-config": "^1.1.1", diff --git a/web/source/settings/components/back-button.jsx b/web/source/settings/components/back-button.tsx similarity index 100% rename from web/source/settings/components/back-button.jsx rename to web/source/settings/components/back-button.tsx diff --git a/web/source/settings/components/combo-box.jsx b/web/source/settings/components/combo-box.tsx similarity index 85% rename from web/source/settings/components/combo-box.jsx rename to web/source/settings/components/combo-box.tsx index fc0133583..113e6179d 100644 --- a/web/source/settings/components/combo-box.jsx +++ b/web/source/settings/components/combo-box.tsx @@ -17,15 +17,11 @@ along with this program. If not, see . */ -const React = require("react"); +import React from "react"; -const { - Combobox, - ComboboxItem, - ComboboxPopover, -} = require("ariakit/combobox"); +import { Combobox, ComboboxItem, ComboboxPopover } from "ariakit/combobox"; -module.exports = function ComboBox({ field, items, label, children, ...inputProps }) { +export default function ComboBox({ field, items, label, children, ...inputProps }) { return (
); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/web/source/settings/components/error.jsx b/web/source/settings/components/error.tsx similarity index 96% rename from web/source/settings/components/error.jsx rename to web/source/settings/components/error.tsx index 3205cd5e3..15c3bccd4 100644 --- a/web/source/settings/components/error.jsx +++ b/web/source/settings/components/error.tsx @@ -17,7 +17,7 @@ along with this program. If not, see . */ -const React = require("react"); +import React from "react"; function ErrorFallback({ error, resetErrorBoundary }) { return ( @@ -81,4 +81,4 @@ function Error({ error }) { ); } -module.exports = { ErrorFallback, Error }; \ No newline at end of file +export { ErrorFallback, Error }; diff --git a/web/source/settings/components/fake-profile.jsx b/web/source/settings/components/fake-profile.tsx similarity index 93% rename from web/source/settings/components/fake-profile.jsx rename to web/source/settings/components/fake-profile.tsx index 6cb8d0187..4a5157378 100644 --- a/web/source/settings/components/fake-profile.jsx +++ b/web/source/settings/components/fake-profile.tsx @@ -17,9 +17,9 @@ along with this program. If not, see . */ -const React = require("react"); +import React from "react"; -module.exports = function FakeProfile({ avatar, header, display_name, username, role }) { +export default function FakeProfile({ avatar, header, display_name, username, role }) { return ( // Keep in sync with web/template/profile.tmpl
@@ -49,4 +49,4 @@ module.exports = function FakeProfile({ avatar, header, display_name, username,
); -}; \ No newline at end of file +} diff --git a/web/source/settings/components/fake-toot.jsx b/web/source/settings/components/fake-toot.tsx similarity index 90% rename from web/source/settings/components/fake-toot.jsx rename to web/source/settings/components/fake-toot.tsx index 08f806008..ad0c387a4 100644 --- a/web/source/settings/components/fake-toot.jsx +++ b/web/source/settings/components/fake-toot.tsx @@ -17,16 +17,15 @@ along with this program. If not, see . */ -const React = require("react"); +import React from "react"; +import { useVerifyCredentialsQuery } from "../lib/query/oauth"; -const query = require("../lib/query"); - -module.exports = function FakeToot({ children }) { +export default function FakeToot({ children }) { const { data: account = { avatar: "/assets/default_avatars/GoToSocial_icon1.png", display_name: "", username: "" - } } = query.useVerifyCredentialsQuery(); + } } = useVerifyCredentialsQuery(); return (
@@ -54,4 +53,4 @@ module.exports = function FakeToot({ children }) {
); -}; \ No newline at end of file +} diff --git a/web/source/settings/components/languages.jsx b/web/source/settings/components/languages.tsx similarity index 86% rename from web/source/settings/components/languages.jsx rename to web/source/settings/components/languages.tsx index 61c76e03a..7c2986438 100644 --- a/web/source/settings/components/languages.jsx +++ b/web/source/settings/components/languages.tsx @@ -17,10 +17,10 @@ along with this program. If not, see . */ -const React = require("react"); -const langs = require("langs"); +import React from "react"; +import { all } from "langs"; -const asElements = langs.all().map((l) => { +const asElements = all().map((l) => { let code = l["1"].toUpperCase(); let name = l.name; if (l.name != l.local) { @@ -29,6 +29,6 @@ const asElements = langs.all().map((l) => { return ; }); -module.exports = function Languages() { +export default function Languages() { return asElements; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/web/source/settings/components/loading.jsx b/web/source/settings/components/loading.tsx similarity index 92% rename from web/source/settings/components/loading.jsx rename to web/source/settings/components/loading.tsx index c62c72a0a..f7635534f 100644 --- a/web/source/settings/components/loading.jsx +++ b/web/source/settings/components/loading.tsx @@ -17,10 +17,10 @@ along with this program. If not, see . */ -const React = require("react"); +import React from "react"; -module.exports = function Loading() { +export default function Loading() { return ( ); -}; \ No newline at end of file +} diff --git a/web/source/settings/components/user-logout-card.jsx b/web/source/settings/components/user-logout-card.tsx similarity index 84% rename from web/source/settings/components/user-logout-card.jsx rename to web/source/settings/components/user-logout-card.tsx index 9d88642a5..f8eeaf63c 100644 --- a/web/source/settings/components/user-logout-card.jsx +++ b/web/source/settings/components/user-logout-card.tsx @@ -17,15 +17,12 @@ along with this program. If not, see . */ -const React = require("react"); -const Loading = require("./loading"); -const { - useVerifyCredentialsQuery, - useLogoutMutation, -} = require("../lib/query/oauth"); -const { useInstanceV1Query } = require("../lib/query"); +import React from "react"; +import Loading from "./loading"; +import { useVerifyCredentialsQuery, useLogoutMutation } from "../lib/query/oauth"; +import { useInstanceV1Query } from "../lib/query/gts-api"; -module.exports = function UserLogoutCard() { +export default function UserLogoutCard() { const { data: profile, isLoading } = useVerifyCredentialsQuery(); const { data: instance } = useInstanceV1Query(); const [logoutQuery] = useLogoutMutation(); @@ -44,4 +41,4 @@ module.exports = function UserLogoutCard() { ); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/web/source/settings/index.tsx b/web/source/settings/index.tsx index d0af8524d..977a94150 100644 --- a/web/source/settings/index.tsx +++ b/web/source/settings/index.tsx @@ -17,7 +17,7 @@ along with this program. If not, see . */ -import React, { StrictMode } from "react"; +import React, { StrictMode, useMemo } from "react"; import "./style.css"; import { createRoot } from "react-dom/client"; @@ -29,18 +29,21 @@ import Loading from "./components/loading"; import { Account } from "./lib/types/account"; import { BaseUrlContext, RoleContext } from "./lib/navigation/util"; import { SidebarMenu } from "./lib/navigation/menu"; -import { UserMenu, UserRouter } from "./views/user/routes"; -import { ModerationMenu, ModerationRouter } from "./views/moderation/routes"; -import { AdminMenu, AdminRouter } from "./views/admin/routes"; import { Redirect, Route, Router } from "wouter"; +import AdminMenu from "./views/admin/menu"; +import ModerationMenu from "./views/moderation/menu"; +import UserMenu from "./views/user/menu"; +import UserRouter from "./views/user/router"; +import { ErrorBoundary } from "./lib/navigation/error"; +import ModerationRouter from "./views/moderation/router"; +import AdminRouter from "./views/admin/router"; interface AppProps { account: Account; } export function App({ account }: AppProps) { - const roles: string[] = [ account.role.name ]; - + const roles: string[] = useMemo(() => [ account.role.name ], [account]); return ( @@ -51,15 +54,17 @@ export function App({ account }: AppProps) {
- - - - {/* - Redirect to first part of UserRouter if - just the bare settings page is open, so - user isn't greeted with a blank page. - */} - + + + + + {/* + Redirect to first part of UserRouter if + just the bare settings page is open, so + user isn't greeted with a blank page. + */} + +
diff --git a/web/source/settings/style.css b/web/source/settings/style.css index 57f8bf4cf..5af9dbc67 100644 --- a/web/source/settings/style.css +++ b/web/source/settings/style.css @@ -601,31 +601,33 @@ span.form-info { @media screen and (max-width: 60rem) { /* vertical layout */ #root { - padding: 1rem; + padding: 0.5rem; + margin: 0; grid-template-columns: 100%; grid-template-rows: auto auto; - .sidebar { + div.sidebar { justify-self: auto; - margin-bottom: 2rem; + margin-bottom: 0; } - .sidebar, section.with-sidebar { + div.sidebar, section.with-sidebar { border-top-left-radius: $br; border-top-right-radius: $br; border-bottom-left-radius: $br; border-bottom-right-radius: $br; } - .sidebar a:first-child h2 { + section.with-sidebar { + grid-column: 1; + padding: 1rem; + } + + div.sidebar a:first-child h2 { border-top-right-radius: $br; } } - section { - grid-column: 1; - } - .user-profile .overview { grid-template-columns: auto; grid-template-rows: auto 1fr; diff --git a/web/source/settings/views/admin/actions/keys/expireremote.tsx b/web/source/settings/views/admin/actions/keys/expireremote.tsx index c7a410267..82045942c 100644 --- a/web/source/settings/views/admin/actions/keys/expireremote.tsx +++ b/web/source/settings/views/admin/actions/keys/expireremote.tsx @@ -18,10 +18,10 @@ */ import React from "react"; -import { useInstanceKeysExpireMutation } from "../../../../lib/query"; import { TextInput } from "../../../../components/form/inputs"; import MutationButton from "../../../../components/form/mutation-button"; import { useTextInput } from "../../../../lib/form"; +import { useInstanceKeysExpireMutation } from "../../../../lib/query/admin"; export default function ExpireRemote({}) { const domainField = useTextInput("domain"); diff --git a/web/source/settings/views/admin/actions/media/cleanup.tsx b/web/source/settings/views/admin/actions/media/cleanup.tsx index d4bae24a6..c1df511e1 100644 --- a/web/source/settings/views/admin/actions/media/cleanup.tsx +++ b/web/source/settings/views/admin/actions/media/cleanup.tsx @@ -19,10 +19,10 @@ import React from "react"; -import { useMediaCleanupMutation } from "../../../../lib/query"; import { useTextInput } from "../../../../lib/form"; import { TextInput } from "../../../../components/form/inputs"; import MutationButton from "../../../../components/form/mutation-button"; +import { useMediaCleanupMutation } from "../../../../lib/query/admin"; export default function Cleanup({}) { const daysField = useTextInput("days", { defaultValue: "30" }); diff --git a/web/source/settings/views/admin/emoji/local/new-emoji.tsx b/web/source/settings/views/admin/emoji/local/new-emoji.tsx index 73e846f16..8ff8236a7 100644 --- a/web/source/settings/views/admin/emoji/local/new-emoji.tsx +++ b/web/source/settings/views/admin/emoji/local/new-emoji.tsx @@ -26,7 +26,7 @@ import { CategorySelect } from '../category-select'; import FakeToot from "../../../../components/fake-toot"; import MutationButton from "../../../../components/form/mutation-button"; import { useAddEmojiMutation } from "../../../../lib/query/admin/custom-emoji"; -import { useInstanceV1Query } from "../../../../lib/query"; +import { useInstanceV1Query } from "../../../../lib/query/gts-api"; export default function NewEmojiForm() { const shortcode = useShortcode(); diff --git a/web/source/settings/views/admin/emoji/local/overview.tsx b/web/source/settings/views/admin/emoji/local/overview.tsx index b28af59f3..b4fa48d74 100644 --- a/web/source/settings/views/admin/emoji/local/overview.tsx +++ b/web/source/settings/views/admin/emoji/local/overview.tsx @@ -29,7 +29,7 @@ import { TextInput } from "../../../../components/form/inputs"; import { useListEmojiQuery } from "../../../../lib/query/admin/custom-emoji"; import { CustomEmoji } from "../../../../lib/types/custom-emoji"; -export function EmojiOverview() { +export default function EmojiOverview() { const { data: emoji = [], isLoading, isError, error } = useListEmojiQuery({ filter: "domain:local" }); let content: React.JSX.Element; diff --git a/web/source/settings/views/admin/settings/rules.tsx b/web/source/settings/views/admin/instance/ruledetail.tsx similarity index 63% rename from web/source/settings/views/admin/settings/rules.tsx rename to web/source/settings/views/admin/instance/ruledetail.tsx index 2b8a51c22..31447c74b 100644 --- a/web/source/settings/views/admin/settings/rules.tsx +++ b/web/source/settings/views/admin/instance/ruledetail.tsx @@ -18,66 +18,18 @@ */ import React from "react"; -import { Link, Redirect, useParams } from "wouter"; -import { useInstanceRulesQuery, useAddInstanceRuleMutation, useUpdateInstanceRuleMutation, useDeleteInstanceRuleMutation } from "../../../lib/query"; +import { Redirect, useParams } from "wouter"; import { useBaseUrl } from "../../../lib/navigation/util"; import { useValue, useTextInput } from "../../../lib/form"; import useFormSubmit from "../../../lib/form/submit"; import { TextArea } from "../../../components/form/inputs"; import MutationButton from "../../../components/form/mutation-button"; -import { Error } from "../../../components/error"; import BackButton from "../../../components/back-button"; -import { InstanceRule, MappedRules } from "../../../lib/types/rules"; import Loading from "../../../components/loading"; -import FormWithData from "../../../lib/form/form-with-data"; +import { useDeleteInstanceRuleMutation, useInstanceRulesQuery, useUpdateInstanceRuleMutation } from "../../../lib/query/admin"; +import { Error } from "../../../components/error"; -export function InstanceRules() { - return ( - <> -

Instance Rules

- - - ); -} - -function InstanceRulesForm({ data: rules }: { data: MappedRules }) { - const baseUrl = useBaseUrl(); - const newRule = useTextInput("text"); - - const [submitForm, result] = useFormSubmit({ newRule }, useAddInstanceRuleMutation(), { - changedOnly: true, - onFinish: () => newRule.reset() - }); - - return ( -
-
    - {Object.values(rules).map((rule: InstanceRule) => ( - -
  1. -

    {rule.text}

    -
  2. - {new Date(rule.created_at).toLocaleString()} - - ))} -
-