TootList: mentions in toot links to profile page
All checks were successful
/ depoly (push) Successful in 1m17s

- bug: main toot in TootBottomSheet does not link
  profile
This commit is contained in:
thislight 2024-10-30 19:25:58 +08:00
parent 92cc451811
commit 31b27237cd
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
5 changed files with 165 additions and 91 deletions

View file

@ -9,12 +9,29 @@ import {
import { type mastodon } from "masto";
import { vibrate } from "../platform/hardware";
import Thread from "./Thread.jsx";
import { useDefaultSession } from "../masto/clients";
import { makeAcctText, useDefaultSession } from "../masto/clients";
import { useHeroSource } from "../platform/anim";
import { HERO as BOTTOM_SHEET_HERO } from "../material/BottomSheet";
import { setCache as setTootBottomSheetCache } from "./TootBottomSheet";
import { useNavigate } from "@solidjs/router";
/**
* find bottom-to-top the element with `data-rel`.
*/
function findElementActionable(
element: HTMLElement,
top: HTMLElement,
): HTMLElement | undefined {
let current = element;
while (!current.dataset.rel) {
if (!current.parentElement || current.parentElement === top) {
return undefined;
}
current = current.parentElement;
}
return current;
}
const TootList: Component<{
ref?: Ref<HTMLDivElement>;
threads: string[];
@ -90,11 +107,35 @@ const TootList: Component<{
});
};
const onItemClick = (status: mastodon.v1.Status, event: MouseEvent) => {
if (status.id !== expandedThreadId()) {
setExpandedThreadId((x) => (x ? undefined : status.id));
const onItemClick = (
status: mastodon.v1.Status,
event: MouseEvent & { target: HTMLElement; currentTarget: HTMLElement },
) => {
const actionableElement = findElementActionable(
event.target,
event.currentTarget,
);
if (actionableElement) {
if (actionableElement.dataset.rel === "acct") {
event.stopPropagation();
const target = actionableElement as HTMLAnchorElement;
const acct =
encodeURIComponent(target.dataset.client ||
`@${new URL(target.href).origin}`);
navigate(`/${acct}/profile/${target.dataset.acctId}`);
} else {
console.warn("unknown action", actionableElement.dataset.rel);
}
} else {
openFullScreenToot(status, event.currentTarget as HTMLElement);
if (status.id !== expandedThreadId()) {
setExpandedThreadId((x) => (x ? undefined : status.id));
} else {
openFullScreenToot(status, event.currentTarget as HTMLElement);
}
}
};