Compare commits
No commits in common. "481930264e6c2f80a924ca79ce210025514cea83" and "acde7609ba69e1e0d6d437b917a1aa7cae45b59a" have entirely different histories.
481930264e
...
acde7609ba
3 changed files with 74 additions and 96 deletions
|
@ -18,30 +18,6 @@ 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(
|
|
||||||
lookup: ReactiveMap<string, TreeNode<mastodon.v1.Status>>,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
get(id: string) {
|
|
||||||
return lookup.get(id);
|
|
||||||
},
|
|
||||||
getPath(id: string) {
|
|
||||||
const node = lookup.get(id);
|
|
||||||
if (!node) return;
|
|
||||||
const path = collectPath(node);
|
|
||||||
for (const sym of path) {
|
|
||||||
lookup.get(sym.value.id); // Track every node on the path
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
},
|
|
||||||
set(id: string, value: mastodon.v1.Status) {
|
|
||||||
const node = untrack(() => lookup.get(id));
|
|
||||||
if (!node) return;
|
|
||||||
lookup.set(id, {...node, value});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createTimelineControlsForArray(
|
export function createTimelineControlsForArray(
|
||||||
status: () => mastodon.v1.Status[] | undefined,
|
status: () => mastodon.v1.Status[] | undefined,
|
||||||
): TimelineControls {
|
): TimelineControls {
|
||||||
|
@ -92,7 +68,20 @@ export function createTimelineControlsForArray(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list: threads,
|
list: threads,
|
||||||
...createControlsForLookup(lookup),
|
get(id: string) {
|
||||||
|
return lookup.get(id);
|
||||||
|
},
|
||||||
|
getPath(id: string) {
|
||||||
|
const node = lookup.get(id);
|
||||||
|
if (!node) return;
|
||||||
|
return collectPath(node);
|
||||||
|
},
|
||||||
|
set(id: string, value: mastodon.v1.Status) {
|
||||||
|
const node = untrack(() => lookup.get(id));
|
||||||
|
if (!node) return;
|
||||||
|
node.value = value;
|
||||||
|
lookup.set(id, node);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +307,20 @@ export function createTimeline<
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
list: threads,
|
list: threads,
|
||||||
...createControlsForLookup(lookup),
|
get(id: string) {
|
||||||
|
return lookup.get(id);
|
||||||
|
},
|
||||||
|
getPath(id: string) {
|
||||||
|
const node = lookup.get(id);
|
||||||
|
if (!node) return;
|
||||||
|
return collectPath(node);
|
||||||
|
},
|
||||||
|
set(id: string, value: mastodon.v1.Status) {
|
||||||
|
const node = untrack(() => lookup.get(id));
|
||||||
|
if (!node) return;
|
||||||
|
node.value = value;
|
||||||
|
lookup.set(id, node);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
chunk,
|
chunk,
|
||||||
{ refetch },
|
{ refetch },
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import type { mastodon } from "masto";
|
import type { mastodon } from "masto";
|
||||||
import { Index, type Component, type Ref } from "solid-js";
|
import {
|
||||||
|
For,
|
||||||
|
type Component,
|
||||||
|
type Ref,
|
||||||
|
} from "solid-js";
|
||||||
import RegularToot, { findRootToot } from "./RegularToot";
|
import RegularToot, { findRootToot } from "./RegularToot";
|
||||||
import cardStyle from "../material/cards.module.css";
|
import cardStyle from "../material/cards.module.css";
|
||||||
import { css } from "solid-styled";
|
import { css } from "solid-styled";
|
||||||
|
@ -13,7 +17,6 @@ type TootActions = {
|
||||||
onBoost(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
|
onBoost(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
|
||||||
onBookmark(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
|
onBookmark(client: mastodon.rest.Client, status: mastodon.v1.Status): void;
|
||||||
onReply(target: TootActionTarget, element: HTMLElement): void;
|
onReply(target: TootActionTarget, element: HTMLElement): void;
|
||||||
onFavourite(status: mastodon.v1.Status): void
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ThreadProps = {
|
type ThreadProps = {
|
||||||
|
@ -42,47 +45,41 @@ const Thread: Component<ThreadProps> = (props) => {
|
||||||
props.onReply({ client: props.client, status }, element);
|
props.onReply({ client: props.client, status }, element);
|
||||||
};
|
};
|
||||||
|
|
||||||
const threading = () => props.toots.length > 1;
|
|
||||||
|
|
||||||
const posThread = (index: number) => {
|
|
||||||
if (!threading()) return;
|
|
||||||
|
|
||||||
if (index === 0) {
|
|
||||||
return "top";
|
|
||||||
} else if (index === props.toots.length - 1) {
|
|
||||||
return "bottom";
|
|
||||||
}
|
|
||||||
return "middle";
|
|
||||||
};
|
|
||||||
|
|
||||||
css`
|
css`
|
||||||
.thread {
|
.thread {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
`;
|
`
|
||||||
return (
|
return (
|
||||||
<article ref={props.ref} class="thread" aria-setsize={props.toots.length}>
|
<article ref={props.ref} class="thread" aria-setsize={props.toots.length}>
|
||||||
<Index each={props.toots}>
|
<For each={props.toots}>
|
||||||
{(status, index) => {
|
{(status, index) => {
|
||||||
|
const useThread = props.toots.length > 1;
|
||||||
|
const threadPosition = useThread
|
||||||
|
? index() === 0
|
||||||
|
? "top"
|
||||||
|
: index() === props.toots.length - 1
|
||||||
|
? "bottom"
|
||||||
|
: "middle"
|
||||||
|
: undefined;
|
||||||
return (
|
return (
|
||||||
<RegularToot
|
<RegularToot
|
||||||
data-status-id={status().id}
|
data-status-id={status.id}
|
||||||
data-thread-sort={index}
|
data-thread-sort={index()}
|
||||||
status={status()}
|
status={status}
|
||||||
thread={posThread(index)}
|
thread={threadPosition}
|
||||||
class={cardStyle.card}
|
class={cardStyle.card}
|
||||||
evaluated={props.isExpended(status())}
|
evaluated={props.isExpended(status)}
|
||||||
actionable={props.isExpended(status())}
|
actionable={props.isExpended(status)}
|
||||||
onBookmark={(s) => bookmark(s)}
|
onBookmark={(s) => bookmark(s)}
|
||||||
onRetoot={(s) => boost(s)}
|
onRetoot={(s) => boost(s)}
|
||||||
onFavourite={props.onFavourite}
|
|
||||||
onReply={reply}
|
onReply={reply}
|
||||||
onClick={[props.onItemClick, status()]}
|
onClick={[props.onItemClick, status]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</Index>
|
</For>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,7 @@ const TootList: Component<{
|
||||||
props.onChangeToot(result.id, result);
|
props.onChangeToot(result.id, result);
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleBoost = async (
|
const onBoost = async (
|
||||||
client: mastodon.rest.Client,
|
client: mastodon.rest.Client,
|
||||||
status: mastodon.v1.Status,
|
status: mastodon.v1.Status,
|
||||||
) => {
|
) => {
|
||||||
|
@ -46,39 +46,23 @@ const TootList: Component<{
|
||||||
const rootStatus = status.reblog ? status.reblog : status;
|
const rootStatus = status.reblog ? status.reblog : status;
|
||||||
const reblogged = rootStatus.reblogged;
|
const reblogged = rootStatus.reblogged;
|
||||||
if (status.reblog) {
|
if (status.reblog) {
|
||||||
props.onChangeToot(status.id, {
|
status.reblog = { ...status.reblog, reblogged: !reblogged };
|
||||||
...status,
|
props.onChangeToot(status.id, status);
|
||||||
reblog: { ...status.reblog, reblogged: !reblogged },
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
props.onChangeToot(status.id, {
|
props.onChangeToot(
|
||||||
...status,
|
status.id,
|
||||||
reblogged: !reblogged,
|
Object.assign(status, {
|
||||||
});
|
reblogged: !reblogged,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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!;
|
||||||
|
props.onChangeToot(
|
||||||
if (status.reblog) {
|
status.id,
|
||||||
props.onChangeToot(status.id, {
|
Object.assign(status.reblog ?? status, result.reblog),
|
||||||
...status,
|
);
|
||||||
reblog: result,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
props.onChangeToot(status.id, result);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleFavourite = async (status: mastodon.v1.Status) => {
|
|
||||||
const client = session()?.client;
|
|
||||||
if (!client) return;
|
|
||||||
const ovalue = status.favourited;
|
|
||||||
const result = ovalue
|
|
||||||
? await client.v1.statuses.$select(status.id).unfavourite()
|
|
||||||
: await client.v1.statuses.$select(status.id).favourite();
|
|
||||||
props.onChangeToot(status.id, result);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const openFullScreenToot = (
|
const openFullScreenToot = (
|
||||||
|
@ -160,13 +144,6 @@ const TootList: Component<{
|
||||||
openFullScreenToot(status, element, true);
|
openFullScreenToot(status, element, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPath = (itemId: string) => {
|
|
||||||
return props
|
|
||||||
.onUnknownThread(itemId)!
|
|
||||||
.reverse()
|
|
||||||
.map((x) => x.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary
|
<ErrorBoundary
|
||||||
fallback={(err, reset) => {
|
fallback={(err, reset) => {
|
||||||
|
@ -175,14 +152,16 @@ 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}>
|
<For each={props.threads}>
|
||||||
{(itemId) => {
|
{(itemId, index) => {
|
||||||
|
const path = props.onUnknownThread(itemId)!;
|
||||||
|
const toots = path.reverse().map((x) => x.value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Thread
|
<Thread
|
||||||
toots={getPath(itemId)}
|
toots={toots}
|
||||||
onBoost={toggleBoost}
|
onBoost={onBoost}
|
||||||
onBookmark={onBookmark}
|
onBookmark={onBookmark}
|
||||||
onReply={onReply}
|
onReply={onReply}
|
||||||
onFavourite={toggleFavourite}
|
|
||||||
client={session()?.client!}
|
client={session()?.client!}
|
||||||
isExpended={checkIsExpended}
|
isExpended={checkIsExpended}
|
||||||
onItemClick={onItemClick}
|
onItemClick={onItemClick}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue