TootList: mentions in toot links to profile page
All checks were successful
/ depoly (push) Successful in 1m17s
All checks were successful
/ depoly (push) Successful in 1m17s
- bug: main toot in TootBottomSheet does not link profile
This commit is contained in:
parent
92cc451811
commit
31b27237cd
5 changed files with 165 additions and 91 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue