Compare commits
2 commits
acde7609ba
...
481930264e
Author | SHA1 | Date | |
---|---|---|---|
|
481930264e | ||
|
ad729f4f34 |
3 changed files with 96 additions and 74 deletions
|
@ -18,6 +18,30 @@ 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 {
|
||||||
|
@ -68,20 +92,7 @@ export function createTimelineControlsForArray(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list: threads,
|
list: threads,
|
||||||
get(id: string) {
|
...createControlsForLookup(lookup),
|
||||||
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);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,20 +318,7 @@ export function createTimeline<
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
list: threads,
|
list: threads,
|
||||||
get(id: string) {
|
...createControlsForLookup(lookup),
|
||||||
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,9 +1,5 @@
|
||||||
import type { mastodon } from "masto";
|
import type { mastodon } from "masto";
|
||||||
import {
|
import { Index, type Component, type Ref } from "solid-js";
|
||||||
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";
|
||||||
|
@ -17,6 +13,7 @@ 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 = {
|
||||||
|
@ -45,41 +42,47 @@ 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}>
|
||||||
<For each={props.toots}>
|
<Index 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={threadPosition}
|
thread={posThread(index)}
|
||||||
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()]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</For>
|
</Index>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,7 @@ const TootList: Component<{
|
||||||
props.onChangeToot(result.id, result);
|
props.onChangeToot(result.id, result);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onBoost = async (
|
const toggleBoost = async (
|
||||||
client: mastodon.rest.Client,
|
client: mastodon.rest.Client,
|
||||||
status: mastodon.v1.Status,
|
status: mastodon.v1.Status,
|
||||||
) => {
|
) => {
|
||||||
|
@ -46,23 +46,39 @@ 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) {
|
||||||
status.reblog = { ...status.reblog, reblogged: !reblogged };
|
props.onChangeToot(status.id, {
|
||||||
props.onChangeToot(status.id, status);
|
...status,
|
||||||
|
reblog: { ...status.reblog, reblogged: !reblogged },
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
props.onChangeToot(
|
props.onChangeToot(status.id, {
|
||||||
status.id,
|
...status,
|
||||||
Object.assign(status, {
|
reblogged: !reblogged,
|
||||||
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(
|
|
||||||
status.id,
|
if (status.reblog) {
|
||||||
Object.assign(status.reblog ?? status, result.reblog),
|
props.onChangeToot(status.id, {
|
||||||
);
|
...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 = (
|
||||||
|
@ -144,6 +160,13 @@ 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) => {
|
||||||
|
@ -152,16 +175,14 @@ 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, index) => {
|
{(itemId) => {
|
||||||
const path = props.onUnknownThread(itemId)!;
|
|
||||||
const toots = path.reverse().map((x) => x.value);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Thread
|
<Thread
|
||||||
toots={toots}
|
toots={getPath(itemId)}
|
||||||
onBoost={onBoost}
|
onBoost={toggleBoost}
|
||||||
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