fix #35: the actions don't update the status
All checks were successful
/ depoly (push) Successful in 1m18s

This commit is contained in:
thislight 2024-11-08 23:17:01 +08:00
parent 17e738e21a
commit 29eaf1a02b
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
5 changed files with 114 additions and 96 deletions

View file

@ -18,9 +18,9 @@ type Timeline<T extends mastodon.DefaultPaginationParams> = {
type TimelineParamsOf<T> = T extends Timeline<infer P> ? P : never; type TimelineParamsOf<T> = T extends Timeline<infer P> ? P : never;
function createControlsForLookup( export type ThreadNode = TreeNode<mastodon.v1.Status>;
lookup: ReactiveMap<string, TreeNode<mastodon.v1.Status>>,
) { function createControlsForLookup(lookup: ReactiveMap<string, ThreadNode>) {
return { return {
get(id: string) { get(id: string) {
return lookup.get(id); return lookup.get(id);
@ -45,7 +45,7 @@ function createControlsForLookup(
export function createTimelineControlsForArray( export function createTimelineControlsForArray(
status: () => mastodon.v1.Status[] | undefined, status: () => mastodon.v1.Status[] | undefined,
): TimelineControls { ): TimelineControls {
const lookup = new ReactiveMap<string, TreeNode<mastodon.v1.Status>>(); const lookup = new ReactiveMap<string, ThreadNode>();
const [threads, setThreads] = createStore([] as mastodon.v1.Status["id"][]); const [threads, setThreads] = createStore([] as mastodon.v1.Status["id"][]);
@ -55,22 +55,24 @@ export function createTimelineControlsForArray(
}); });
if (!nls) return; if (!nls) return;
batch(() => {
setThreads([]); setThreads([]);
lookup.clear(); lookup.clear();
const existence = [] as boolean[]; for (const status of nls) {
for (const [idx, status] of nls.entries()) {
existence[idx] = !!untrack(() => lookup.get(status.id));
lookup.set(status.id, { lookup.set(status.id, {
value: status, value: status,
}); });
} }
});
untrack(() => {
for (const status of nls) { for (const status of nls) {
const node = untrack(() => lookup.get(status.id))!; const node = lookup.get(status.id)!;
if (status.inReplyToId) { const parent = status.inReplyToId
const parent = lookup.get(status.inReplyToId); ? lookup.get(status.inReplyToId)
: undefined;
if (parent) { if (parent) {
const children = parent.children ?? []; const children = parent.children ?? [];
if (!children.find((x) => x.value.id == status.id)) { if (!children.find((x) => x.value.id == status.id)) {
@ -80,12 +82,13 @@ export function createTimelineControlsForArray(
node.parent = parent; node.parent = parent;
} }
} }
} });
const newThreads = nls const newThreads = untrack(() =>
.filter((x, i) => !existence[i]) nls
.map((x) => x.id) .map((x) => x.id)
.filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0); .filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0),
);
setThreads(newThreads); setThreads(newThreads);
}); });
@ -269,24 +272,27 @@ export function createTimeline<
return; return;
} }
const existence = [] as boolean[];
batch(() => {
if (chk.rebuilt) { if (chk.rebuilt) {
lookup.clear(); lookup.clear();
setThreads([]); setThreads([]);
} }
const existence = [] as boolean[];
for (const [idx, status] of chk.chunk.entries()) { for (const [idx, status] of chk.chunk.entries()) {
existence[idx] = !!untrack(() => lookup.get(status.id)); existence[idx] = !!untrack(() => lookup.get(status.id));
lookup.set(status.id, { lookup.set(status.id, {
value: status, value: status,
}); });
} }
});
for (const status of chk.chunk) { for (const status of chk.chunk) {
const node = untrack(() => lookup.get(status.id))!; const node = untrack(() => lookup.get(status.id))!;
if (status.inReplyToId) { const parent = untrack(() =>
const parent = lookup.get(status.inReplyToId); status.inReplyToId ? lookup.get(status.inReplyToId) : undefined,
);
if (parent) { if (parent) {
const children = parent.children ?? []; const children = parent.children ?? [];
if (!children.find((x) => x.value.id == status.id)) { if (!children.find((x) => x.value.id == status.id)) {
@ -296,7 +302,6 @@ export function createTimeline<
node.parent = parent; node.parent = parent;
} }
} }
}
const nThreadIds = chk.chunk const nThreadIds = chk.chunk
.filter((x, i) => !existence[i]) .filter((x, i) => !existence[i])

View file

@ -58,8 +58,9 @@ const TootBottomSheet: Component = (props) => {
}, },
); );
const toot = () => catchError(remoteToot, (error) => { const toot = () =>
console.error(error) catchError(remoteToot, (error) => {
console.error(error);
}) ?? getCache(acctText(), params.id); }) ?? getCache(acctText(), params.id);
createEffect((lastTootId?: string) => { createEffect((lastTootId?: string) => {

View file

@ -20,6 +20,8 @@ import RegularToot, {
findRootToot, findRootToot,
} from "./RegularToot"; } from "./RegularToot";
import cardStyle from "../material/cards.module.css"; import cardStyle from "../material/cards.module.css";
import type { ReactiveMap } from "@solid-primitives/map";
import type { ThreadNode } from "../masto/timelines";
function positionTootInThread(index: number, threadLength: number) { function positionTootInThread(index: number, threadLength: number) {
if (index === 0) { if (index === 0) {
@ -34,7 +36,7 @@ const TootList: Component<{
ref?: Ref<HTMLDivElement>; ref?: Ref<HTMLDivElement>;
id?: string; id?: string;
threads: readonly string[]; threads: readonly string[];
onUnknownThread: (id: string) => { value: mastodon.v1.Status }[] | undefined; onUnknownThread: (id: string) => ThreadNode[] | undefined;
onChangeToot: (id: string, value: mastodon.v1.Status) => void; onChangeToot: (id: string, value: mastodon.v1.Status) => void;
}> = (props) => { }> = (props) => {
const session = useDefaultSession(); const session = useDefaultSession();
@ -71,7 +73,7 @@ const TootList: Component<{
}); });
} }
const result = reblogged /* const result = reblogged
? await client.v1.statuses.$select(status.id).unreblog() ? await client.v1.statuses.$select(status.id).unreblog()
: (await client.v1.statuses.$select(status.id).reblog()).reblog!; : (await client.v1.statuses.$select(status.id).reblog()).reblog!;
@ -82,13 +84,15 @@ const TootList: Component<{
}); });
} else { } else {
props.onChangeToot(status.id, result); props.onChangeToot(status.id, result);
} } */
}; };
const toggleFavourite = async (status: mastodon.v1.Status) => { const toggleFavourite = async (status: mastodon.v1.Status) => {
const client = session()?.client; const client = session()?.client;
if (!client) return; if (!client) return;
const ovalue = status.favourited; const ovalue = status.favourited;
props.onChangeToot(status.id, { ...status, favourited: !ovalue });
const result = ovalue const result = ovalue
? await client.v1.statuses.$select(status.id).unfavourite() ? await client.v1.statuses.$select(status.id).unfavourite()
: await client.v1.statuses.$select(status.id).favourite(); : await client.v1.statuses.$select(status.id).favourite();
@ -170,11 +174,12 @@ const TootList: Component<{
const checkIsExpended = (status: mastodon.v1.Status) => const checkIsExpended = (status: mastodon.v1.Status) =>
checkIsExpendedId(status.id); checkIsExpendedId(status.id);
const getPath = (itemId: string) => { const reply = (
return props status: mastodon.v1.Status,
.onUnknownThread(itemId)! event: { currentTarget: HTMLElement },
.reverse() ) => {
.map((x) => x.value); const element = findRootToot(event.currentTarget);
openFullScreenToot(status, element, true);
}; };
return ( return (
@ -184,19 +189,29 @@ const TootList: Component<{
}} }}
> >
<div ref={props.ref} id={props.id} class="toot-list"> <div ref={props.ref} id={props.id} class="toot-list">
<For each={props.threads}> <Index each={props.threads}>
{(itemId) => { {(threadId, threadIdx) => {
const toots = createMemo(() => getPath(itemId)); const thread = createMemo(() =>
props.onUnknownThread(threadId())?.reverse(),
);
const threadLength = () => thread()?.length ?? 0;
return (
<Index each={thread()}>
{(threadNode, index) => {
const status = () => threadNode().value;
return ( return (
<Index each={toots()}>
{(status, index) => (
<RegularToot <RegularToot
data-status-id={status().id} data-status-id={status().id}
data-thread={threadIdx}
data-thread-len={threadLength()}
data-thread-sort={index} data-thread-sort={index}
status={status()} status={status()}
thread={ thread={
toots().length > 1 threadLength() > 1
? positionTootInThread(index, toots().length) ? positionTootInThread(index, threadLength())
: undefined : undefined
} }
class={cardStyle.card} class={cardStyle.card}
@ -205,17 +220,15 @@ const TootList: Component<{
onBookmark={onBookmark} onBookmark={onBookmark}
onRetoot={toggleBoost} onRetoot={toggleBoost}
onFavourite={toggleFavourite} onFavourite={toggleFavourite}
onReply={(status, event) => { onReply={reply}
const element = findRootToot(event.currentTarget);
openFullScreenToot(status, element, true);
}}
onClick={[onItemClick, status()]} onClick={[onItemClick, status()]}
/> />
)} );
}}
</Index> </Index>
); );
}} }}
</For> </Index>
</div> </div>
</ErrorBoundary> </ErrorBoundary>
); );

View file

@ -1,18 +1,14 @@
import { import {
Component, Component,
For,
createSignal, createSignal,
Match, Match,
Switch as JsSwitch, Switch as JsSwitch,
ErrorBoundary, ErrorBoundary,
createSelector,
} from "solid-js"; } from "solid-js";
import { type mastodon } from "masto"; import { type mastodon } from "masto";
import { Button } from "@suid/material"; import { Button } from "@suid/material";
import { createTimelineSnapshot } from "../masto/timelines.js"; import { createTimelineSnapshot } from "../masto/timelines.js";
import { vibrate } from "../platform/hardware.js";
import PullDownToRefresh from "./PullDownToRefresh.jsx"; import PullDownToRefresh from "./PullDownToRefresh.jsx";
import Thread from "./Thread.jsx";
import TootList from "./TootList.jsx"; import TootList from "./TootList.jsx";
const TrendTimelinePanel: Component<{ const TrendTimelinePanel: Component<{
@ -25,8 +21,7 @@ const TrendTimelinePanel: Component<{
) => void; ) => void;
}> = (props) => { }> = (props) => {
const [scrollLinked, setScrollLinked] = createSignal<HTMLElement>(); const [scrollLinked, setScrollLinked] = createSignal<HTMLElement>();
const [timeline, snapshot, { refetch: refetchTimeline }] = const [tl, snapshot, { refetch: refetchTimeline }] = createTimelineSnapshot(
createTimelineSnapshot(
() => props.client.v1.trends.statuses, () => props.client.v1.trends.statuses,
() => ({ limit: 120 }), () => ({ limit: 120 }),
); );
@ -50,9 +45,9 @@ const TrendTimelinePanel: Component<{
} }
> >
<TootList <TootList
threads={timeline.list} threads={tl.list}
onUnknownThread={timeline.getPath} onUnknownThread={tl.getPath}
onChangeToot={timeline.set} onChangeToot={tl.set}
/> />
</div> </div>
<div <div

View file

@ -5,8 +5,12 @@
margin-block: 0; margin-block: 0;
position: relative; position: relative;
contain: content; contain: content;
&:not(.expanded) {
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
}
&.toot { &.toot {
/* fix composition ordering: I think the css module processor should aware the overriding and behaves, but no */ /* fix composition ordering: I think the css module processor should aware the overriding and behaves, but no */