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 {name
.split(" ") .split(" ")
.map((x) => x[0]) .map((x) => x[0])
.filter((x) => typeof x !== "undefined")} .filter((x) => typeof x !== "undefined")
.join("")
.substring(0, 3)}
</ServerText> </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 { lazy, Suspense } from "preact/compat";
import ErrorBoundary from "../lib/ErrorBoundary"; import ErrorBoundary from "../lib/ErrorBoundary";
import FakeClient from "../lib/FakeClient";
import Context from "../context"; import Context from "../context";
import { CheckAuth } from "../context/revoltjs/CheckAuth"; import { CheckAuth } from "../context/revoltjs/CheckAuth";
@ -31,7 +32,9 @@ export function App() {
<Login /> <Login />
</Route> </Route>
<Route path="/invite/:code"> <Route path="/invite/:code">
<FakeClient>
<Invite /> <Invite />
</FakeClient>
</Route> </Route>
<Route path="/login"> <Route path="/login">
<CheckAuth> <CheckAuth>

View file

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