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

@@ -1,5 +1,4 @@
import { Group } from "@styled-icons/boxicons-solid";
import { reaction } from "mobx";
import { observer } from "mobx-react-lite";
import { useHistory } from "react-router-dom";
import { Message, API } from "revolt.js";
@@ -12,14 +11,13 @@ import { Button, Category, Preloader } from "@revoltchat/ui";
import { isTouchscreenDevice } from "../../../../lib/isTouchscreenDevice";
import { I18nError } from "../../../../context/Locale";
import {
AppContext,
ClientStatus,
StatusContext,
} from "../../../../context/revoltjs/RevoltClient";
import { takeError } from "../../../../context/revoltjs/util";
import ServerIcon from "../../../../components/common/ServerIcon";
import {
useClient,
useSession,
} from "../../../../controllers/client/ClientController";
const EmbedInviteBase = styled.div`
width: 400px;
@@ -78,8 +76,8 @@ type Props = {
export function EmbedInvite({ code }: Props) {
const history = useHistory();
const client = useContext(AppContext);
const status = useContext(StatusContext);
const session = useSession()!;
const client = session.client!;
const [processing, setProcessing] = useState(false);
const [error, setError] = useState<string | undefined>(undefined);
const [joinError, setJoinError] = useState<string | undefined>(undefined);
@@ -90,7 +88,7 @@ export function EmbedInvite({ code }: Props) {
useEffect(() => {
if (
typeof invite === "undefined" &&
(status === ClientStatus.ONLINE || status === ClientStatus.READY)
(session.state === "Online" || session.state === "Ready")
) {
client
.fetchInvite(code)
@@ -99,7 +97,7 @@ export function EmbedInvite({ code }: Props) {
)
.catch((err) => setError(takeError(err)));
}
}, [client, code, invite, status]);
}, [client, code, invite, session.state]);
if (typeof invite === "undefined") {
return error ? (