TootBottomSheet: catch fetch error
This commit is contained in:
parent
f4c0104d48
commit
d88921f245
1 changed files with 18 additions and 27 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { useLocation, useNavigate, useParams } from "@solidjs/router";
|
import { useLocation, useNavigate, useParams } from "@solidjs/router";
|
||||||
import {
|
import {
|
||||||
|
catchError,
|
||||||
createEffect,
|
createEffect,
|
||||||
createRenderEffect,
|
createRenderEffect,
|
||||||
createResource,
|
createResource,
|
||||||
|
@ -42,7 +43,6 @@ function getCache(acct: string, id: string) {
|
||||||
const TootBottomSheet: Component = (props) => {
|
const TootBottomSheet: Component = (props) => {
|
||||||
const params = useParams<{ acct: string; id: string }>();
|
const params = useParams<{ acct: string; id: string }>();
|
||||||
const location = useLocation<{
|
const location = useLocation<{
|
||||||
tootBottomSheetPushedCount?: number;
|
|
||||||
tootReply?: boolean;
|
tootReply?: boolean;
|
||||||
}>();
|
}>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -51,10 +51,6 @@ const TootBottomSheet: Component = (props) => {
|
||||||
const acctText = () => decodeURIComponent(params.acct);
|
const acctText = () => decodeURIComponent(params.acct);
|
||||||
const session = useSessionForAcctStr(acctText);
|
const session = useSessionForAcctStr(acctText);
|
||||||
|
|
||||||
const pushedCount = () => {
|
|
||||||
return location.state?.tootBottomSheetPushedCount || 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const [remoteToot, { mutate: setRemoteToot }] = createResource(
|
const [remoteToot, { mutate: setRemoteToot }] = createResource(
|
||||||
() => [session().client, params.id] as const,
|
() => [session().client, params.id] as const,
|
||||||
async ([client, id]) => {
|
async ([client, id]) => {
|
||||||
|
@ -62,7 +58,9 @@ const TootBottomSheet: Component = (props) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const toot = () => remoteToot() ?? getCache(acctText(), params.id);
|
const toot = () => catchError(remoteToot, (error) => {
|
||||||
|
console.error(error)
|
||||||
|
}) ?? getCache(acctText(), params.id);
|
||||||
|
|
||||||
createEffect((lastTootId?: string) => {
|
createEffect((lastTootId?: string) => {
|
||||||
const tootId = toot()?.id;
|
const tootId = toot()?.id;
|
||||||
|
@ -78,13 +76,19 @@ const TootBottomSheet: Component = (props) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const [tootContext, { refetch: refetchContext }] = createResource(
|
const [tootContextErrorUncaught, { refetch: refetchContext }] =
|
||||||
|
createResource(
|
||||||
() => [session().client, params.id] as const,
|
() => [session().client, params.id] as const,
|
||||||
async ([client, id]) => {
|
async ([client, id]) => {
|
||||||
return await client.v1.statuses.$select(id).context.fetch();
|
return await client.v1.statuses.$select(id).context.fetch();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const tootContext = () =>
|
||||||
|
catchError(tootContextErrorUncaught, (error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
const ancestors = createTimelineControlsForArray(
|
const ancestors = createTimelineControlsForArray(
|
||||||
() => tootContext()?.ancestors,
|
() => tootContext()?.ancestors,
|
||||||
);
|
);
|
||||||
|
@ -160,19 +164,6 @@ const TootBottomSheet: Component = (props) => {
|
||||||
setRemoteToot(result);
|
setRemoteToot(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
const switchContext = (status: mastodon.v1.Status) => {
|
|
||||||
if (isInTyping()) {
|
|
||||||
setInTyping(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCache(params.acct, status);
|
|
||||||
navigate(`/${params.acct}/toot/${status.id}`, {
|
|
||||||
state: {
|
|
||||||
tootBottomSheetPushedCount: pushedCount() + 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const defaultMentions = () => {
|
const defaultMentions = () => {
|
||||||
const tootAcct = remoteToot()?.reblog?.account ?? remoteToot()?.account;
|
const tootAcct = remoteToot()?.reblog?.account ?? remoteToot()?.account;
|
||||||
if (!tootAcct) {
|
if (!tootAcct) {
|
||||||
|
@ -246,7 +237,7 @@ const TootBottomSheet: Component = (props) => {
|
||||||
sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }}
|
sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }}
|
||||||
>
|
>
|
||||||
<IconButton color="inherit" onClick={[navigate, -1]} disableRipple>
|
<IconButton color="inherit" onClick={[navigate, -1]} disableRipple>
|
||||||
{pushedCount() > 0 ? <BackIcon /> : <CloseIcon />}
|
<CloseIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Title component="div" class="name" use:solid-styled>
|
<Title component="div" class="name" use:solid-styled>
|
||||||
<span
|
<span
|
||||||
|
@ -302,7 +293,7 @@ const TootBottomSheet: Component = (props) => {
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<Show when={tootContext.loading}>
|
<Show when={tootContextErrorUncaught.loading}>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
|
Loading…
Reference in a new issue