This commit is contained in:
parent
ad729f4f34
commit
481930264e
2 changed files with 70 additions and 46 deletions
|
@ -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…
Reference in a new issue