fix: allow invite screen to properly load while signed out

This commit is contained in:
Paul 2021-12-25 20:43:54 +00:00
parent 7f586e6f8c
commit 1b644d450d
4 changed files with 25 additions and 7 deletions

View file

@ -51,7 +51,9 @@ export default observer(
{name
.split(" ")
.map((x) => x[0])
.filter((x) => typeof x !== "undefined")}
.filter((x) => typeof x !== "undefined")
.join("")
.substring(0, 3)}
</ServerText>
);
}

13
src/lib/FakeClient.tsx Normal file
View file

@ -0,0 +1,13 @@
import { useMemo } from "preact/hooks";
import { useApplicationState } from "../mobx/State";
import { AppContext } from "../context/revoltjs/RevoltClient";
import { Children } from "../types/Preact";
export default function FakeClient({ children }: { children: Children }) {
const config = useApplicationState().config;
const client = useMemo(() => config.createClient(), []);
return <AppContext.Provider value={client}>{children}</AppContext.Provider>;
}

View file

@ -3,6 +3,7 @@ import { Route, Switch } from "react-router-dom";
import { lazy, Suspense } from "preact/compat";
import ErrorBoundary from "../lib/ErrorBoundary";
import FakeClient from "../lib/FakeClient";
import Context from "../context";
import { CheckAuth } from "../context/revoltjs/CheckAuth";
@ -31,7 +32,9 @@ export function App() {
<Login />
</Route>
<Route path="/invite/:code">
<Invite />
<FakeClient>
<Invite />
</FakeClient>
</Route>
<Route path="/login">
<CheckAuth>

View file

@ -10,6 +10,8 @@ import { useContext, useEffect, useState } from "preact/hooks";
import { defer } from "../../lib/defer";
import { TextReact } from "../../lib/i18n";
import { useApplicationState } from "../../mobx/State";
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
import {
AppContext,
@ -27,6 +29,7 @@ import Preloader from "../../components/ui/Preloader";
export default function Invite() {
const history = useHistory();
const client = useContext(AppContext);
const status = useContext(StatusContext);
const { code } = useParams<{ code: string }>();
const [processing, setProcessing] = useState(false);
@ -36,10 +39,7 @@ export default function Invite() {
);
useEffect(() => {
if (
typeof invite === "undefined" &&
(status === ClientStatus.ONLINE || status === ClientStatus.READY)
) {
if (typeof invite === "undefined") {
client
.fetchInvite(code)
.then((data) => setInvite(data))
@ -91,7 +91,7 @@ export default function Invite() {
className={styles.invite}
style={{
backgroundImage: invite.server_banner
? `url('${client.generateFileURL(invite.server_banner)}')`
? `url('${client?.generateFileURL(invite.server_banner)}')`
: undefined,
}}>
<div className={styles.leave}>