diff --git a/src/components/common/user/UserIcon.tsx b/src/components/common/user/UserIcon.tsx
index 27c8cdb1..c1eade4a 100644
--- a/src/components/common/user/UserIcon.tsx
+++ b/src/components/common/user/UserIcon.tsx
@@ -56,7 +56,7 @@ export default observer(
keyof Props | "children" | "as"
>,
) => {
- const client = useClient();
+ const client = useApplicationState().client!;
const {
target,
diff --git a/src/components/settings/account/EditAccount.tsx b/src/components/settings/account/EditAccount.tsx
index ce7a6088..6220214b 100644
--- a/src/components/settings/account/EditAccount.tsx
+++ b/src/components/settings/account/EditAccount.tsx
@@ -12,6 +12,7 @@ import {
} from "@revoltchat/ui";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
+import { modalController } from "../../../context/modals";
import {
ClientStatus,
StatusContext,
@@ -62,8 +63,9 @@ export default function EditAccount() {
account
action={}
onClick={() =>
- openScreen({
- id: "modify_account",
+ modalController.push({
+ type: "modify_account",
+ client,
field,
})
}>
diff --git a/src/context/intermediate/Popovers.tsx b/src/context/intermediate/Popovers.tsx
index 34e80f40..4d6dc501 100644
--- a/src/context/intermediate/Popovers.tsx
+++ b/src/context/intermediate/Popovers.tsx
@@ -8,8 +8,6 @@ import { SpecialPromptModal } from "./modals/Prompt";
import { ChannelInfo } from "./popovers/ChannelInfo";
import { CreateBotModal } from "./popovers/CreateBot";
import { ImageViewer } from "./popovers/ImageViewer";
-import { ModifyAccountModal } from "./popovers/ModifyAccount";
-import { PendingRequests } from "./popovers/PendingRequests";
import { ServerIdentityModal } from "./popovers/ServerIdentityModal";
import { UserPicker } from "./popovers/UserPicker";
import { UserProfile } from "./popovers/UserProfile";
@@ -35,12 +33,6 @@ export default function Popovers() {
case "channel_info":
// @ts-expect-error someone figure this out :)
return ;
- case "pending_requests":
- // @ts-expect-error someone figure this out :)
- return ;
- case "modify_account":
- // @ts-expect-error someone figure this out :)
- return ;
case "create_bot":
// @ts-expect-error someone figure this out :)
return ;
diff --git a/src/context/intermediate/popovers/PendingRequests.tsx b/src/context/intermediate/popovers/PendingRequests.tsx
deleted file mode 100644
index 2f41e5bf..00000000
--- a/src/context/intermediate/popovers/PendingRequests.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { observer } from "mobx-react-lite";
-import { User } from "revolt.js";
-
-import styles from "./UserPicker.module.scss";
-import { Text } from "preact-i18n";
-
-import { Modal } from "@revoltchat/ui";
-
-import { Friend } from "../../../pages/friends/Friend";
-
-interface Props {
- users: User[];
- onClose: () => void;
-}
-
-export const PendingRequests = observer(({ users, onClose }: Props) => {
- return (
- }
- onClose={onClose}>
-
- {users.map((x) => (
-
- ))}
-
-
- );
-});
diff --git a/src/context/intermediate/popovers/ModifyAccount.tsx b/src/context/modals/components/ModifyAccount.tsx
similarity index 91%
rename from src/context/intermediate/popovers/ModifyAccount.tsx
rename to src/context/modals/components/ModifyAccount.tsx
index 9feb5ba1..b3fd934c 100644
--- a/src/context/intermediate/popovers/ModifyAccount.tsx
+++ b/src/context/modals/components/ModifyAccount.tsx
@@ -5,14 +5,12 @@ import { useContext, useState } from "preact/hooks";
import { Category, Error, Modal } from "@revoltchat/ui";
+import { noopTrue } from "../../../lib/js";
+
import FormField from "../../../pages/login/FormField";
import { AppContext } from "../../revoltjs/RevoltClient";
import { takeError } from "../../revoltjs/util";
-
-interface Props {
- onClose: () => void;
- field: "username" | "email" | "password";
-}
+import { ModalProps } from "../types";
interface FormInputs {
password: string;
@@ -25,7 +23,10 @@ interface FormInputs {
current_password?: string;
}
-export function ModifyAccountModal({ onClose, field }: Props) {
+export default function ModifyAccount({
+ field,
+ ...props
+}: ModalProps<"modify_account">) {
const client = useContext(AppContext);
const [processing, setProcessing] = useState(false);
const { handleSubmit, register, errors } = useForm();
@@ -46,19 +47,19 @@ export function ModifyAccountModal({ onClose, field }: Props) {
current_password: password,
email: new_email,
});
- onClose();
+ props.onClose();
} else if (field === "password") {
await client.api.patch("/auth/account/change/password", {
current_password: password,
password: new_password,
});
- onClose();
+ props.onClose();
} else if (field === "username") {
await client.api.patch("/users/@me/username", {
username: new_username,
password,
});
- onClose();
+ props.onClose();
}
} catch (err) {
setError(takeError(err));
@@ -68,16 +69,13 @@ export function ModifyAccountModal({ onClose, field }: Props) {
return (
}
disabled={processing}
actions={[
{
confirmation: true,
- onClick: async () => {
- await handleSubmit(onSubmit)();
- return true;
- },
+ onClick: () => void handleSubmit(onSubmit)(),
children:
field === "email" ? (
@@ -86,7 +84,7 @@ export function ModifyAccountModal({ onClose, field }: Props) {
),
},
{
- onClick: onClose,
+ onClick: noopTrue,
children: ,
palette: "plain",
},
diff --git a/src/context/modals/components/PendingFriendRequests.tsx b/src/context/modals/components/PendingFriendRequests.tsx
new file mode 100644
index 00000000..2b9464d7
--- /dev/null
+++ b/src/context/modals/components/PendingFriendRequests.tsx
@@ -0,0 +1,21 @@
+import { Text } from "preact-i18n";
+
+import { Column, Modal } from "@revoltchat/ui";
+
+import { Friend } from "../../../pages/friends/Friend";
+import { ModalProps } from "../types";
+
+export default function PendingFriendRequests({
+ users,
+ ...props
+}: ModalProps<"pending_friend_requests">) {
+ return (
+ }>
+
+ {users.map((x) => (
+
+ ))}
+
+
+ );
+}
diff --git a/src/context/modals/index.tsx b/src/context/modals/index.tsx
index 6a2485d0..7c370496 100644
--- a/src/context/modals/index.tsx
+++ b/src/context/modals/index.tsx
@@ -21,7 +21,9 @@ import LinkWarning from "./components/LinkWarning";
import MFAEnableTOTP from "./components/MFAEnableTOTP";
import MFAFlow from "./components/MFAFlow";
import MFARecovery from "./components/MFARecovery";
+import ModifyAccount from "./components/ModifyAccount";
import OutOfDate from "./components/OutOfDate";
+import PendingFriendRequests from "./components/PendingFriendRequests";
import ShowToken from "./components/ShowToken";
import SignOutSessions from "./components/SignOutSessions";
import SignedOut from "./components/SignedOut";
@@ -206,7 +208,9 @@ export const modalController = new ModalControllerExtended({
mfa_flow: MFAFlow,
mfa_recovery: MFARecovery,
mfa_enable_totp: MFAEnableTOTP,
+ modify_account: ModifyAccount,
out_of_date: OutOfDate,
+ pending_friend_requests: PendingFriendRequests,
show_token: ShowToken,
signed_out: SignedOut,
sign_out_sessions: SignOutSessions,
diff --git a/src/context/modals/types.ts b/src/context/modals/types.ts
index d6bb5883..d9ca14b0 100644
--- a/src/context/modals/types.ts
+++ b/src/context/modals/types.ts
@@ -1,4 +1,4 @@
-import { API, Client } from "revolt.js";
+import { API, Client, User } from "revolt.js";
export type Modal = {
key?: string;
@@ -56,6 +56,15 @@ export type Modal = {
link: string;
callback: () => true;
}
+ | {
+ type: "pending_friend_requests";
+ users: User[];
+ }
+ | {
+ type: "modify_account";
+ client: Client;
+ field: "username" | "email" | "password";
+ }
| {
type: "signed_out";
}
diff --git a/src/pages/friends/Friends.tsx b/src/pages/friends/Friends.tsx
index 335462f6..aa3af078 100644
--- a/src/pages/friends/Friends.tsx
+++ b/src/pages/friends/Friends.tsx
@@ -13,6 +13,7 @@ import { TextReact } from "../../lib/i18n";
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
import { useIntermediate } from "../../context/intermediate/Intermediate";
+import { modalController } from "../../context/modals";
import { useClient } from "../../context/revoltjs/RevoltClient";
import CollapsibleSection from "../../components/common/CollapsibleSection";
@@ -129,8 +130,8 @@ export default observer(() => {
- openScreen({
- id: "pending_requests",
+ modalController.push({
+ type: "pending_friend_requests",
users: incoming,
})
}>