From 7a1e6394831fb07e303c5ed0900dfe1ea4820de5 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Wed, 24 Apr 2024 12:12:47 +0200
Subject: [chore] Refactor settings panel routing (and other fixes) (#2864)
---
web/source/settings/views/user/migration.tsx | 208 ++++++++++++++++++++
web/source/settings/views/user/profile.tsx | 279 +++++++++++++++++++++++++++
web/source/settings/views/user/routes.tsx | 80 ++++++++
web/source/settings/views/user/settings.tsx | 169 ++++++++++++++++
4 files changed, 736 insertions(+)
create mode 100644 web/source/settings/views/user/migration.tsx
create mode 100644 web/source/settings/views/user/profile.tsx
create mode 100644 web/source/settings/views/user/routes.tsx
create mode 100644 web/source/settings/views/user/settings.tsx
(limited to 'web/source/settings/views/user')
diff --git a/web/source/settings/views/user/migration.tsx b/web/source/settings/views/user/migration.tsx
new file mode 100644
index 000000000..69aae6059
--- /dev/null
+++ b/web/source/settings/views/user/migration.tsx
@@ -0,0 +1,208 @@
+/*
+ GoToSocial
+ Copyright (C) GoToSocial Authors admin@gotosocial.org
+ SPDX-License-Identifier: AGPL-3.0-or-later
+
+ 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 .
+*/
+
+import React from "react";
+
+import FormWithData from "../../lib/form/form-with-data";
+
+import { useVerifyCredentialsQuery } from "../../lib/query/oauth";
+import { useArrayInput, useTextInput } from "../../lib/form";
+import { TextInput } from "../../components/form/inputs";
+import useFormSubmit from "../../lib/form/submit";
+import MutationButton from "../../components/form/mutation-button";
+import { useAliasAccountMutation, useMoveAccountMutation } from "../../lib/query/user";
+import { FormContext, useWithFormContext } from "../../lib/form/context";
+import { store } from "../../redux/store";
+
+export default function UserMigration() {
+ return (
+
+ );
+}
+
+function UserMigrationForm({ data: profile }) {
+ return (
+ <>
+
Account Migration Settings
+
+ The following settings allow you to alias your account to
+ another account elsewhere, or to move to another account.
+
+
+ Account aliasing is harmless and reversible; you can
+ set and unset up to five account aliases as many times as you wish.
+
+
+ The account move action, on the other
+ hand, has serious and irreversible consequences.
+
+
+ For more information on account migration, please see the documentation.
+
+ );
+}
diff --git a/web/source/settings/views/user/routes.tsx b/web/source/settings/views/user/routes.tsx
new file mode 100644
index 000000000..76ac50bc2
--- /dev/null
+++ b/web/source/settings/views/user/routes.tsx
@@ -0,0 +1,80 @@
+/*
+ GoToSocial
+ Copyright (C) GoToSocial Authors admin@gotosocial.org
+ SPDX-License-Identifier: AGPL-3.0-or-later
+
+ 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 .
+*/
+
+import { MenuItem } from "../../lib/navigation/menu";
+import React from "react";
+import { BaseUrlContext, useBaseUrl } from "../../lib/navigation/util";
+import UserProfile from "./profile";
+import UserSettings from "./settings";
+import UserMigration from "./migration";
+import { Redirect, Route, Router, Switch } from "wouter";
+
+/**
+ *
+ * Basic user menu. Profile + accounts
+ * settings, post settings, migration.
+ */
+export function UserMenu() {
+ return (
+
+ );
+}
+
+export function UserRouter() {
+ const baseUrl = useBaseUrl();
+ const thisBase = "/user";
+ const absBase = baseUrl + thisBase;
+
+ return (
+
+
+
+
+
+
+ {/* Fallback component */}
+
+
+
+
+ );
+}
diff --git a/web/source/settings/views/user/settings.tsx b/web/source/settings/views/user/settings.tsx
new file mode 100644
index 000000000..2827cc53f
--- /dev/null
+++ b/web/source/settings/views/user/settings.tsx
@@ -0,0 +1,169 @@
+/*
+ GoToSocial
+ Copyright (C) GoToSocial Authors admin@gotosocial.org
+ SPDX-License-Identifier: AGPL-3.0-or-later
+
+ 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 .
+*/
+
+import React from "react";
+import query from "../../lib/query";
+import { useTextInput, useBoolInput } from "../../lib/form";
+import useFormSubmit from "../../lib/form/submit";
+import { Select, TextInput, Checkbox } from "../../components/form/inputs";
+import FormWithData from "../../lib/form/form-with-data";
+import Languages from "../../components/languages";
+import MutationButton from "../../components/form/mutation-button";
+
+export default function UserSettings() {
+ return (
+
+ );
+}
+
+function UserSettingsForm({ data }) {
+ /* form keys
+ - string source[privacy]
+ - bool source[sensitive]
+ - string source[language]
+ - string source[status_content_type]
+ */
+
+ const form = {
+ defaultPrivacy: useTextInput("source[privacy]", { source: data, defaultValue: "unlisted" }),
+ isSensitive: useBoolInput("source[sensitive]", { source: data }),
+ language: useTextInput("source[language]", { source: data, valueSelector: (s) => s.source.language?.toUpperCase() ?? "EN" }),
+ statusContentType: useTextInput("source[status_content_type]", { source: data, defaultValue: "text/plain" }),
+ };
+
+ const [submitForm, result] = useFormSubmit(form, query.useUpdateCredentialsMutation());
+
+ return (
+ <>
+
Account Settings
+
+
+ >
+ );
+}
+
+function PasswordChange() {
+ const form = {
+ oldPassword: useTextInput("old_password"),
+ newPassword: useTextInput("new_password", {
+ validator(val) {
+ if (val != "" && val == form.oldPassword.value) {
+ return "New password same as old password";
+ }
+ return "";
+ }
+ })
+ };
+
+ const verifyNewPassword = useTextInput("verifyNewPassword", {
+ validator(val) {
+ if (val != "" && val != form.newPassword.value) {
+ return "Passwords do not match";
+ }
+ return "";
+ }
+ });
+
+ const [submitForm, result] = useFormSubmit(form, query.usePasswordChangeMutation());
+
+ return (
+
+ );
+}
--
cgit v1.3