mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-11 11:05:28 +00:00
feat: implement useClient from client controller
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { ArrowBack } from "@styled-icons/boxicons-regular";
|
||||
import { autorun } from "mobx";
|
||||
import { Redirect, useHistory, useParams } from "react-router-dom";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import styles from "./Invite.module.scss";
|
||||
import { Text } from "preact-i18n";
|
||||
import { useContext, useEffect, useState } from "preact/hooks";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { Button, Category, Error, Preloader } from "@revoltchat/ui";
|
||||
|
||||
@@ -14,23 +13,22 @@ import { TextReact } from "../../lib/i18n";
|
||||
import { useApplicationState } from "../../mobx/State";
|
||||
|
||||
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
|
||||
import {
|
||||
AppContext,
|
||||
ClientStatus,
|
||||
StatusContext,
|
||||
} from "../../context/revoltjs/RevoltClient";
|
||||
import { takeError } from "../../context/revoltjs/util";
|
||||
|
||||
import ServerIcon from "../../components/common/ServerIcon";
|
||||
import UserIcon from "../../components/common/user/UserIcon";
|
||||
import {
|
||||
useClient,
|
||||
useSession,
|
||||
} from "../../controllers/client/ClientController";
|
||||
|
||||
export default function Invite() {
|
||||
const history = useHistory();
|
||||
const client = useContext(AppContext);
|
||||
const session = useSession();
|
||||
const client = useClient();
|
||||
|
||||
const layout = useApplicationState().layout;
|
||||
|
||||
const status = useContext(StatusContext);
|
||||
const { code } = useParams<{ code: string }>();
|
||||
const [processing, setProcessing] = useState(false);
|
||||
const [error, setError] = useState<string | undefined>(undefined);
|
||||
@@ -45,7 +43,7 @@ export default function Invite() {
|
||||
.then((data) => setInvite(data))
|
||||
.catch((err) => setError(takeError(err)));
|
||||
}
|
||||
}, [client, code, invite, status]);
|
||||
}, [code, invite]);
|
||||
|
||||
if (code === undefined) return <Redirect to={layout.getLastPath()} />;
|
||||
|
||||
@@ -154,7 +152,7 @@ export default function Invite() {
|
||||
<Button
|
||||
palette="secondary"
|
||||
onClick={async () => {
|
||||
if (status === ClientStatus.READY) {
|
||||
if (!session) {
|
||||
return history.push("/");
|
||||
}
|
||||
|
||||
@@ -172,7 +170,7 @@ export default function Invite() {
|
||||
setProcessing(false);
|
||||
}
|
||||
}}>
|
||||
{status === ClientStatus.READY ? (
|
||||
{!session ? (
|
||||
<Text id="app.special.invite.login" />
|
||||
) : (
|
||||
<Text id="app.special.invite.accept" />
|
||||
|
||||
@@ -6,10 +6,9 @@ import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { Button, Category, ComboBox, Preloader, Tip } from "@revoltchat/ui";
|
||||
|
||||
import { useClient } from "../../context/revoltjs/RevoltClient";
|
||||
|
||||
import UserIcon from "../../components/common/user/UserIcon";
|
||||
import Markdown from "../../components/markdown/Markdown";
|
||||
import { useClient } from "../../controllers/client/ClientController";
|
||||
|
||||
const BotInfo = styled.div`
|
||||
gap: 12px;
|
||||
|
||||
Reference in New Issue
Block a user