feat: implement useClient from client controller

This commit is contained in:
Paul Makles
2022-06-28 19:59:58 +01:00
parent ce88fab714
commit 5f2311b09c
72 changed files with 330 additions and 457 deletions

View File

@@ -2,13 +2,13 @@ import { SubmitHandler, useForm } from "react-hook-form";
import { API } from "revolt.js";
import { Text } from "preact-i18n";
import { useContext, useState } from "preact/hooks";
import { useState } from "preact/hooks";
import { Category, Modal } from "@revoltchat/ui";
import { useClient } from "../../../controllers/client/ClientController";
import FormField from "../../../pages/login/FormField";
import { I18nError } from "../../Locale";
import { AppContext } from "../../revoltjs/RevoltClient";
import { takeError } from "../../revoltjs/util";
interface Props {
@@ -21,7 +21,7 @@ interface FormInputs {
}
export function CreateBotModal({ onClose, onCreate }: Props) {
const client = useContext(AppContext);
const client = useClient();
const { handleSubmit, register, errors } = useForm<FormInputs>();
const [error, setError] = useState<string | undefined>(undefined);

View File

@@ -7,7 +7,7 @@ import { Modal } from "@revoltchat/ui";
import AttachmentActions from "../../../components/common/messaging/attachments/AttachmentActions";
import EmbedMediaActions from "../../../components/common/messaging/embed/EmbedMediaActions";
import { useClient } from "../../revoltjs/RevoltClient";
import { useClient } from "../../../controllers/client/ClientController";
interface Props {
onClose: () => void;

View File

@@ -5,7 +5,7 @@ import { useState } from "preact/hooks";
import { Modal } from "@revoltchat/ui";
import UserCheckbox from "../../../components/common/user/UserCheckbox";
import { useClient } from "../../revoltjs/RevoltClient";
import { useClient } from "../../../controllers/client/ClientController";
interface Props {
omit?: string[];

View File

@@ -34,11 +34,7 @@ import UserIcon from "../../../components/common/user/UserIcon";
import { Username } from "../../../components/common/user/UserShort";
import UserStatus from "../../../components/common/user/UserStatus";
import Markdown from "../../../components/markdown/Markdown";
import {
ClientStatus,
StatusContext,
useClient,
} from "../../revoltjs/RevoltClient";
import { useSession } from "../../../controllers/client/ClientController";
import { useIntermediate } from "../Intermediate";
interface Props {
@@ -63,8 +59,8 @@ export const UserProfile = observer(
>();
const history = useHistory();
const client = useClient();
const status = useContext(StatusContext);
const session = useSession()!;
const client = session.client!;
const [tab, setTab] = useState("profile");
const user = client.users.get(user_id);
@@ -101,32 +97,26 @@ export const UserProfile = observer(
useEffect(() => {
if (dummy) return;
if (
status === ClientStatus.ONLINE &&
typeof mutual === "undefined"
) {
if (session.state === "Online" && typeof mutual === "undefined") {
setMutual(null);
user.fetchMutual().then(setMutual);
}
}, [mutual, status, dummy, user]);
}, [mutual, session.state, dummy, user]);
useEffect(() => {
if (dummy) return;
if (
status === ClientStatus.ONLINE &&
typeof profile === "undefined"
) {
if (session.state === "Online" && typeof profile === "undefined") {
setProfile(null);
if (user.permission & UserPermission.ViewProfile) {
user.fetchProfile().then(setProfile).catch(noop);
}
}
}, [profile, status, dummy, user]);
}, [profile, session.state, dummy, user]);
useEffect(() => {
if (
status === ClientStatus.ONLINE &&
session.state === "Online" &&
user.bot &&
typeof isPublicBot === "undefined"
) {
@@ -136,7 +126,7 @@ export const UserProfile = observer(
.then(() => setIsPublicBot(true))
.catch(noop);
}
}, [isPublicBot, status, user, client.bots]);
}, [isPublicBot, session.state, user, client.bots]);
const backgroundURL =
profile &&