phanpy/src/components/status.jsx

2496 lines
73 KiB
React
Raw Normal View History

2022-12-10 09:14:48 +00:00
import './status.css';
import '@justinribeiro/lite-youtube';
2023-03-02 07:15:49 +00:00
import {
ControlledMenu,
Menu,
MenuDivider,
MenuHeader,
MenuItem,
} from '@szhsin/react-menu';
import { decodeBlurHash, getBlurHashAverageColor } from 'fast-blurhash';
2024-01-06 04:31:25 +00:00
import { shallowEqual } from 'fast-equals';
import { memo } from 'preact/compat';
2023-06-14 03:14:49 +00:00
import {
useCallback,
useContext,
2023-06-14 03:14:49 +00:00
useEffect,
useMemo,
useRef,
useState,
} from 'preact/hooks';
2023-09-08 07:32:55 +00:00
import { useHotkeys } from 'react-hotkeys-hook';
2023-03-07 16:01:51 +00:00
import { useLongPress } from 'use-long-press';
2022-12-10 09:14:48 +00:00
import { useSnapshot } from 'valtio';
2023-04-06 14:51:48 +00:00
import AccountBlock from '../components/account-block';
import EmojiText from '../components/emoji-text';
import Loader from '../components/loader';
import Menu2 from '../components/menu2';
import MenuConfirm from '../components/menu-confirm';
2022-12-10 09:14:48 +00:00
import Modal from '../components/modal';
import NameText from '../components/name-text';
2023-04-22 16:55:47 +00:00
import Poll from '../components/poll';
import { api } from '../utils/api';
import emojifyText from '../utils/emojify-text';
2022-12-10 09:14:48 +00:00
import enhanceContent from '../utils/enhance-content';
import FilterContext from '../utils/filter-context';
import { isFiltered } from '../utils/filters';
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
2023-03-28 17:12:59 +00:00
import getHTMLText from '../utils/getHTMLText';
import handleContentLinks from '../utils/handle-content-links';
import htmlContentLength from '../utils/html-content-length';
2023-04-22 16:55:47 +00:00
import isMastodonLinkMaybe from '../utils/isMastodonLinkMaybe';
import localeMatch from '../utils/locale-match';
2023-03-01 12:07:22 +00:00
import niceDateTime from '../utils/nice-date-time';
import openCompose from '../utils/open-compose';
2023-10-14 12:33:40 +00:00
import pmem from '../utils/pmem';
2023-06-13 09:46:37 +00:00
import safeBoundingBoxPadding from '../utils/safe-bounding-box-padding';
2022-12-10 09:14:48 +00:00
import shortenNumber from '../utils/shorten-number';
import showToast from '../utils/show-toast';
2023-12-24 13:06:26 +00:00
import { speak, supportsTTS } from '../utils/speech';
2023-03-17 09:14:54 +00:00
import states, { getStatus, saveStatus, statusKey } from '../utils/states';
2023-03-21 16:09:36 +00:00
import statusPeek from '../utils/status-peek';
import store from '../utils/store';
import unfurlMastodonLink from '../utils/unfurl-link';
import useTruncated from '../utils/useTruncated';
2022-12-10 09:14:48 +00:00
import visibilityIconsMap from '../utils/visibility-icons-map';
import Avatar from './avatar';
import Icon from './icon';
import Link from './link';
import Media from './media';
import { isMediaCaptionLong } from './media';
2023-03-28 07:59:20 +00:00
import MenuLink from './menu-link';
import RelativeTime from './relative-time';
import TranslationBlock from './translation-block';
2022-12-10 09:14:48 +00:00
const SHOW_COMMENT_COUNT_LIMIT = 280;
2023-07-21 14:52:53 +00:00
const INLINE_TRANSLATE_LIMIT = 140;
function fetchAccount(id, masto) {
2023-10-14 12:33:40 +00:00
return masto.v1.accounts.$select(id).fetch();
2022-12-18 13:10:05 +00:00
}
2023-10-14 12:33:40 +00:00
const memFetchAccount = pmem(fetchAccount);
2022-12-10 09:14:48 +00:00
const visibilityText = {
public: 'Public',
unlisted: 'Unlisted',
private: 'Followers only',
2023-04-06 10:21:56 +00:00
direct: 'Private mention',
};
2023-11-04 11:05:14 +00:00
const isIOS =
window.ontouchstart !== undefined &&
/iPad|iPhone|iPod/.test(navigator.userAgent);
2023-12-20 05:55:56 +00:00
const REACTIONS_LIMIT = 80;
2023-12-21 10:17:14 +00:00
function getPollText(poll) {
if (!poll?.options?.length) return '';
return `📊:\n${poll.options
.map(
(option) =>
`- ${option.title}${
option.votesCount >= 0 ? ` (${option.votesCount})` : ''
}`,
)
.join('\n')}`;
}
function getPostText(status) {
const { spoilerText, content, poll } = status;
return (
(spoilerText ? `${spoilerText}\n\n` : '') +
getHTMLText(content) +
getPollText(poll)
);
}
2022-12-18 13:10:05 +00:00
function Status({
statusID,
status,
instance: propInstance,
2022-12-18 13:10:05 +00:00
size = 'm',
contentTextWeight,
2023-12-14 17:58:29 +00:00
readOnly,
enableCommentHint,
withinContext,
skeleton,
enableTranslate,
forceTranslate: _forceTranslate,
2023-03-16 05:02:46 +00:00
previewMode,
// allowFilters,
onMediaClick,
2023-04-22 16:55:47 +00:00
quoted,
onStatusLinkClick = () => {},
2023-12-14 17:58:29 +00:00
showFollowedTags,
allowContextMenu,
2022-12-18 13:10:05 +00:00
}) {
if (skeleton) {
2022-12-10 09:14:48 +00:00
return (
2022-12-18 13:10:05 +00:00
<div class="status skeleton">
<Avatar size="xxl" />
2022-12-18 13:10:05 +00:00
<div class="container">
2023-02-11 13:09:36 +00:00
<div class="meta"> </div>
2022-12-18 13:10:05 +00:00
<div class="content-container">
<div class="content">
2023-02-11 13:09:36 +00:00
<p> </p>
2022-12-18 13:10:05 +00:00
</div>
</div>
</div>
2022-12-10 09:14:48 +00:00
</div>
);
}
2023-02-19 06:49:53 +00:00
const { masto, instance, authenticated } = api({ instance: propInstance });
const { instance: currentInstance } = api();
const sameInstance = instance === currentInstance;
2022-12-10 09:14:48 +00:00
2023-12-29 00:25:41 +00:00
let sKey = statusKey(statusID || status?.id, instance);
2022-12-18 13:10:05 +00:00
const snapStates = useSnapshot(states);
if (!status) {
2023-02-11 10:55:21 +00:00
status = snapStates.statuses[sKey] || snapStates.statuses[statusID];
2023-05-19 17:06:16 +00:00
sKey = statusKey(status?.id, instance);
2022-12-18 13:10:05 +00:00
}
if (!status) {
return null;
}
2022-12-10 09:14:48 +00:00
const {
2022-12-18 13:10:05 +00:00
account: {
acct,
avatar,
avatarStatic,
id: accountId,
2023-02-21 06:29:25 +00:00
url: accountURL,
2022-12-18 13:10:05 +00:00
displayName,
username,
emojis: accountEmojis,
2023-04-10 16:26:43 +00:00
bot,
group,
2022-12-18 13:10:05 +00:00
},
id,
repliesCount,
reblogged,
reblogsCount,
favourited,
favouritesCount,
bookmarked,
poll,
muted,
sensitive,
spoilerText,
visibility, // public, unlisted, private, direct
language,
editedAt,
filtered,
card,
createdAt,
inReplyToId,
2022-12-18 13:10:05 +00:00
inReplyToAccountId,
content,
mentions,
mediaAttachments,
reblog,
uri,
2023-02-21 06:29:25 +00:00
url,
2022-12-18 13:10:05 +00:00
emojis,
2023-12-14 17:58:29 +00:00
tags,
2023-02-17 02:12:59 +00:00
// Non-API props
_deleted,
2023-02-17 02:12:59 +00:00
_pinned,
// _filtered,
2022-12-18 13:10:05 +00:00
} = status;
2022-12-10 09:14:48 +00:00
const currentAccount = useMemo(() => {
return store.session.get('currentAccount');
}, []);
const isSelf = useMemo(() => {
return currentAccount && currentAccount === accountId;
}, [accountId, currentAccount]);
const filterContext = useContext(FilterContext);
const filterInfo =
!isSelf && !readOnly && !previewMode && isFiltered(filtered, filterContext);
if (filterInfo?.action === 'hide') {
return null;
}
console.debug('RENDER Status', id, status?.account.displayName, quoted);
2023-03-23 13:48:29 +00:00
const debugHover = (e) => {
if (e.shiftKey) {
2023-07-31 12:30:29 +00:00
console.log({
...status,
});
2023-03-23 13:48:29 +00:00
}
};
if (/*allowFilters && */ size !== 'l' && filterInfo) {
2023-03-21 16:09:36 +00:00
return (
<FilteredStatus
status={status}
filterInfo={filterInfo}
2023-03-21 16:09:36 +00:00
instance={instance}
2023-03-23 13:48:29 +00:00
containerProps={{
onMouseEnter: debugHover,
}}
2023-12-14 17:58:29 +00:00
showFollowedTags
2023-03-21 16:09:36 +00:00
/>
);
}
2022-12-18 13:10:05 +00:00
const createdAtDate = new Date(createdAt);
const editedAtDate = new Date(editedAt);
2022-12-10 09:14:48 +00:00
2022-12-18 13:10:05 +00:00
let inReplyToAccountRef = mentions?.find(
(mention) => mention.id === inReplyToAccountId,
);
if (!inReplyToAccountRef && inReplyToAccountId === id) {
2023-02-21 06:29:25 +00:00
inReplyToAccountRef = { url: accountURL, username, displayName };
2022-12-18 13:10:05 +00:00
}
const [inReplyToAccount, setInReplyToAccount] = useState(inReplyToAccountRef);
if (!withinContext && !inReplyToAccount && inReplyToAccountId) {
const account = states.accounts[inReplyToAccountId];
2022-12-18 13:10:05 +00:00
if (account) {
setInReplyToAccount(account);
} else {
memFetchAccount(inReplyToAccountId, masto)
2022-12-18 13:10:05 +00:00
.then((account) => {
setInReplyToAccount(account);
states.accounts[account.id] = account;
2022-12-18 13:10:05 +00:00
})
.catch((e) => {});
}
2022-12-10 09:14:48 +00:00
}
2023-04-09 16:30:32 +00:00
const mentionSelf =
inReplyToAccountId === currentAccount ||
mentions?.find((mention) => mention.id === currentAccount);
2022-12-10 09:14:48 +00:00
const readingExpandSpoilers = useMemo(() => {
const prefs = store.account.get('preferences') || {};
return !!prefs['reading:expand:spoilers'];
}, []);
const readingExpandMedia = useMemo(() => {
// default | show_all | hide_all
// Ignore hide_all because it means hide *ALL* media including non-sensitive ones
const prefs = store.account.get('preferences') || {};
return prefs['reading:expand:media'] || 'default';
}, []);
// FOR TESTING:
// const readingExpandSpoilers = true;
// const readingExpandMedia = 'show_all';
const showSpoiler =
previewMode || readingExpandSpoilers || !!snapStates.spoilers[id];
const showSpoilerMedia =
previewMode ||
readingExpandMedia === 'show_all' ||
!!snapStates.spoilersMedia[id];
2022-12-10 09:14:48 +00:00
2022-12-18 13:10:05 +00:00
if (reblog) {
2023-03-21 16:09:36 +00:00
// If has statusID, means useItemID (cached in states)
if (group) {
return (
2023-11-05 00:21:43 +00:00
<div
data-state-post-id={sKey}
class="status-group"
onMouseEnter={debugHover}
>
<div class="status-pre-meta">
<Icon icon="group" size="l" alt="Group" />{' '}
<NameText account={status.account} instance={instance} showAvatar />
</div>
<Status
status={statusID ? null : reblog}
statusID={statusID ? reblog.id : null}
instance={instance}
size={size}
contentTextWeight={contentTextWeight}
readOnly={readOnly}
/>
</div>
);
}
2022-12-18 13:10:05 +00:00
return (
2023-11-05 00:21:43 +00:00
<div
data-state-post-id={sKey}
class="status-reblog"
onMouseEnter={debugHover}
>
2022-12-18 13:10:05 +00:00
<div class="status-pre-meta">
<Icon icon="rocket" size="l" />{' '}
<NameText account={status.account} instance={instance} showAvatar />{' '}
2023-04-06 05:21:53 +00:00
<span>boosted</span>
2022-12-18 13:10:05 +00:00
</div>
<Status
2023-03-21 16:09:36 +00:00
status={statusID ? null : reblog}
statusID={statusID ? reblog.id : null}
instance={instance}
size={size}
contentTextWeight={contentTextWeight}
readOnly={readOnly}
2023-11-14 14:45:13 +00:00
enableCommentHint
/>
2022-12-18 13:10:05 +00:00
</div>
);
}
2022-12-10 09:14:48 +00:00
2023-12-14 17:58:29 +00:00
// Check followedTags
if (showFollowedTags && !!snapStates.statusFollowedTags[sKey]?.length) {
return (
<div
data-state-post-id={sKey}
class="status-followed-tags"
onMouseEnter={debugHover}
>
<div class="status-pre-meta">
<Icon icon="hashtag" size="l" />{' '}
{snapStates.statusFollowedTags[sKey].slice(0, 3).map((tag) => (
<Link
key={tag}
to={instance ? `/${instance}/t/${tag}` : `/t/${tag}`}
class="status-followed-tag-item"
>
{tag}
</Link>
))}
</div>
<Status
status={statusID ? null : status}
statusID={statusID ? status.id : null}
instance={instance}
size={size}
contentTextWeight={contentTextWeight}
readOnly={readOnly}
enableCommentHint
/>
</div>
);
}
const isSizeLarge = size === 'l';
const [forceTranslate, setForceTranslate] = useState(_forceTranslate);
const targetLanguage = getTranslateTargetLanguage(true);
const contentTranslationHideLanguages =
snapStates.settings.contentTranslationHideLanguages || [];
const { contentTranslation, contentTranslationAutoInline } =
snapStates.settings;
if (!contentTranslation) enableTranslate = false;
const inlineTranslate = useMemo(() => {
if (
!contentTranslation ||
!contentTranslationAutoInline ||
readOnly ||
(withinContext && !isSizeLarge) ||
previewMode ||
spoilerText ||
sensitive ||
poll ||
card ||
mediaAttachments?.length
) {
return false;
}
const contentLength = htmlContentLength(content);
return contentLength > 0 && contentLength <= INLINE_TRANSLATE_LIMIT;
2023-07-21 14:52:53 +00:00
}, [
contentTranslation,
contentTranslationAutoInline,
2023-07-21 14:52:53 +00:00
readOnly,
withinContext,
isSizeLarge,
previewMode,
2023-07-21 14:52:53 +00:00
spoilerText,
sensitive,
2023-07-21 14:52:53 +00:00
poll,
card,
2023-07-21 14:52:53 +00:00
mediaAttachments,
content,
]);
2022-12-18 13:10:05 +00:00
const [showEdited, setShowEdited] = useState(false);
const spoilerContentRef = useTruncated();
const contentRef = useTruncated();
2023-09-20 09:27:54 +00:00
const mediaContainerRef = useTruncated();
2022-12-18 13:10:05 +00:00
const readMoreText = 'Read more →';
2022-12-10 09:14:48 +00:00
2022-12-30 12:37:57 +00:00
const statusRef = useRef(null);
2023-04-29 14:22:07 +00:00
const unauthInteractionErrorMessage = `Sorry, your current logged-in instance can't interact with this post from another instance.`;
2023-06-14 03:14:49 +00:00
const textWeight = useCallback(
() =>
Math.max(
Math.round((spoilerText.length + htmlContentLength(content)) / 140) ||
1,
1,
),
[spoilerText, content],
);
2023-03-01 12:07:22 +00:00
const createdDateText = niceDateTime(createdAtDate);
const editedDateText = editedAt && niceDateTime(editedAtDate);
// Can boost if:
// - authenticated AND
// - visibility != direct OR
// - visibility = private AND isSelf
let canBoost =
authenticated && visibility !== 'direct' && visibility !== 'private';
if (visibility === 'private' && isSelf) {
canBoost = true;
}
const replyStatus = (e) => {
if (!sameInstance || !authenticated) {
return alert(unauthInteractionErrorMessage);
}
// syntheticEvent comes from MenuItem
if (e?.shiftKey || e?.syntheticEvent?.shiftKey) {
const newWin = openCompose({
replyToStatus: status,
});
if (newWin) return;
}
states.showCompose = {
replyToStatus: status,
};
};
// Check if media has no descriptions
const mediaNoDesc = useMemo(() => {
return mediaAttachments.some(
(attachment) => !attachment.description?.trim?.(),
);
}, [mediaAttachments]);
const boostStatus = async () => {
if (!sameInstance || !authenticated) {
alert(unauthInteractionErrorMessage);
return false;
}
try {
if (!reblogged) {
let confirmText = 'Boost this post?';
if (mediaNoDesc) {
confirmText += '\n\n⚠ Some media have no descriptions.';
}
const yes = confirm(confirmText);
if (!yes) {
return false;
}
}
// Optimistic
states.statuses[sKey] = {
...status,
reblogged: !reblogged,
reblogsCount: reblogsCount + (reblogged ? -1 : 1),
};
if (reblogged) {
const newStatus = await masto.v1.statuses.$select(id).unreblog();
saveStatus(newStatus, instance);
return true;
} else {
const newStatus = await masto.v1.statuses.$select(id).reblog();
saveStatus(newStatus, instance);
return true;
}
} catch (e) {
console.error(e);
// Revert optimistism
states.statuses[sKey] = status;
return false;
}
};
const confirmBoostStatus = async () => {
if (!sameInstance || !authenticated) {
alert(unauthInteractionErrorMessage);
return false;
}
try {
// Optimistic
states.statuses[sKey] = {
...status,
reblogged: !reblogged,
reblogsCount: reblogsCount + (reblogged ? -1 : 1),
};
if (reblogged) {
const newStatus = await masto.v1.statuses.$select(id).unreblog();
saveStatus(newStatus, instance);
return true;
} else {
const newStatus = await masto.v1.statuses.$select(id).reblog();
saveStatus(newStatus, instance);
return true;
}
} catch (e) {
console.error(e);
// Revert optimistism
states.statuses[sKey] = status;
return false;
}
};
const favouriteStatus = async () => {
if (!sameInstance || !authenticated) {
return alert(unauthInteractionErrorMessage);
}
try {
// Optimistic
states.statuses[sKey] = {
...status,
favourited: !favourited,
favouritesCount: favouritesCount + (favourited ? -1 : 1),
};
if (favourited) {
const newStatus = await masto.v1.statuses.$select(id).unfavourite();
saveStatus(newStatus, instance);
} else {
const newStatus = await masto.v1.statuses.$select(id).favourite();
saveStatus(newStatus, instance);
}
} catch (e) {
console.error(e);
// Revert optimistism
states.statuses[sKey] = status;
}
};
const bookmarkStatus = async () => {
if (!sameInstance || !authenticated) {
return alert(unauthInteractionErrorMessage);
}
try {
// Optimistic
states.statuses[sKey] = {
...status,
bookmarked: !bookmarked,
};
if (bookmarked) {
const newStatus = await masto.v1.statuses.$select(id).unbookmark();
saveStatus(newStatus, instance);
} else {
const newStatus = await masto.v1.statuses.$select(id).bookmark();
saveStatus(newStatus, instance);
}
} catch (e) {
console.error(e);
// Revert optimistism
states.statuses[sKey] = status;
}
};
const differentLanguage =
!!language &&
language !== targetLanguage &&
!localeMatch([language], [targetLanguage]) &&
!contentTranslationHideLanguages.find(
(l) => language === l || localeMatch([language], [l]),
);
2023-12-20 05:55:56 +00:00
const reblogIterator = useRef();
const favouriteIterator = useRef();
async function fetchBoostedLikedByAccounts(firstLoad) {
if (firstLoad) {
reblogIterator.current = masto.v1.statuses
.$select(statusID)
.rebloggedBy.list({
limit: REACTIONS_LIMIT,
});
favouriteIterator.current = masto.v1.statuses
.$select(statusID)
.favouritedBy.list({
limit: REACTIONS_LIMIT,
});
}
const [{ value: reblogResults }, { value: favouriteResults }] =
await Promise.allSettled([
reblogIterator.current.next(),
favouriteIterator.current.next(),
]);
if (reblogResults.value?.length || favouriteResults.value?.length) {
const accounts = [];
if (reblogResults.value?.length) {
accounts.push(
...reblogResults.value.map((a) => {
a._types = ['reblog'];
return a;
}),
);
}
if (favouriteResults.value?.length) {
accounts.push(
...favouriteResults.value.map((a) => {
a._types = ['favourite'];
return a;
}),
);
}
return {
value: accounts,
done: reblogResults.done && favouriteResults.done,
};
}
return {
value: [],
done: true,
};
}
const menuInstanceRef = useRef();
const StatusMenuItems = (
<>
{!isSizeLarge && (
<>
<MenuHeader>
<span class="ib">
<Icon icon={visibilityIconsMap[visibility]} size="s" />{' '}
<span>{visibilityText[visibility]}</span>
</span>{' '}
<span class="ib">
{repliesCount > 0 && (
<span>
2023-11-14 08:52:47 +00:00
<Icon icon="comment2" alt="Replies" size="s" />{' '}
<span>{shortenNumber(repliesCount)}</span>
</span>
)}{' '}
{reblogsCount > 0 && (
<span>
<Icon icon="rocket" alt="Boosts" size="s" />{' '}
<span>{shortenNumber(reblogsCount)}</span>
</span>
)}{' '}
{favouritesCount > 0 && (
<span>
<Icon icon="heart" alt="Likes" size="s" />{' '}
<span>{shortenNumber(favouritesCount)}</span>
</span>
)}
</span>
<br />
{createdDateText}
</MenuHeader>
<MenuLink
to={instance ? `/${instance}/s/${id}` : `/s/${id}`}
onClick={(e) => {
onStatusLinkClick(e, status);
}}
>
<Icon icon="arrow-right" />
2023-03-09 13:51:50 +00:00
<span>View post by @{username || acct}</span>
</MenuLink>
</>
)}
{!!editedAt && (
<MenuItem
onClick={() => {
setShowEdited(id);
}}
>
<Icon icon="history" />
<span>
Show Edit History
<br />
<small class="more-insignificant">Edited: {editedDateText}</small>
</span>
</MenuItem>
)}
{(!isSizeLarge || !!editedAt) && <MenuDivider />}
2023-04-06 14:51:48 +00:00
{isSizeLarge && (
2023-12-20 05:55:56 +00:00
<MenuItem
onClick={() => {
states.showGenericAccounts = {
heading: 'Boosted/Liked by…',
fetchAccounts: fetchBoostedLikedByAccounts,
instance,
showReactions: true,
};
}}
>
2023-04-06 14:51:48 +00:00
<Icon icon="react" />
<span>
Boosted/Liked by<span class="more-insignificant"></span>
2023-04-06 14:51:48 +00:00
</span>
</MenuItem>
)}
{!isSizeLarge && sameInstance && (
<>
2023-04-09 17:21:02 +00:00
<div class="menu-horizontal">
<MenuConfirm
subMenu
confirmLabel={
<>
<Icon icon="rocket" />
2023-07-18 10:45:38 +00:00
<span>{reblogged ? 'Unboost?' : 'Boost to everyone?'}</span>
</>
}
menuFooter={
mediaNoDesc &&
!reblogged && (
<div class="footer">
<Icon icon="alert" />
Some media have no descriptions.
</div>
)
}
2023-04-09 17:21:02 +00:00
disabled={!canBoost}
onClick={async () => {
try {
const done = await confirmBoostStatus();
if (!isSizeLarge && done) {
2023-10-19 12:02:31 +00:00
showToast(
reblogged
? `Unboosted @${username || acct}'s post`
: `Boosted @${username || acct}'s post`,
);
}
} catch (e) {}
}}
>
2023-03-09 13:51:50 +00:00
<Icon
icon="rocket"
style={{
color: reblogged && 'var(--reblog-color)',
}}
/>
<span>{reblogged ? 'Unboost' : 'Boost…'}</span>
</MenuConfirm>
2023-04-09 17:21:02 +00:00
<MenuItem
onClick={() => {
try {
favouriteStatus();
2023-09-08 07:32:55 +00:00
if (!isSizeLarge) {
2023-10-19 12:02:31 +00:00
showToast(
favourited
? `Unliked @${username || acct}'s post`
: `Liked @${username || acct}'s post`,
2023-10-19 12:02:31 +00:00
);
2023-09-08 07:32:55 +00:00
}
2023-04-09 17:21:02 +00:00
} catch (e) {}
2023-03-09 13:51:50 +00:00
}}
2023-04-09 17:21:02 +00:00
>
<Icon
icon="heart"
style={{
color: favourited && 'var(--favourite-color)',
}}
/>
<span>{favourited ? 'Unlike' : 'Like'}</span>
2023-04-09 17:21:02 +00:00
</MenuItem>
</div>
<div class="menu-horizontal">
<MenuItem onClick={replyStatus}>
<Icon icon="reply" />
<span>Reply</span>
</MenuItem>
2023-04-09 17:21:02 +00:00
<MenuItem
onClick={() => {
try {
bookmarkStatus();
2023-09-08 07:32:55 +00:00
if (!isSizeLarge) {
2023-10-19 12:02:31 +00:00
showToast(
bookmarked
? `Unbookmarked @${username || acct}'s post`
: `Bookmarked @${username || acct}'s post`,
);
2023-09-08 07:32:55 +00:00
}
2023-04-09 17:21:02 +00:00
} catch (e) {}
2023-03-09 13:51:50 +00:00
}}
2023-04-09 17:21:02 +00:00
>
<Icon
icon="bookmark"
style={{
color: bookmarked && 'var(--link-color)',
}}
/>
<span>{bookmarked ? 'Unbookmark' : 'Bookmark'}</span>
</MenuItem>
</div>
</>
)}
{enableTranslate ? (
2023-12-21 10:17:14 +00:00
<div class={supportsTTS ? 'menu-horizontal' : ''}>
<MenuItem
disabled={forceTranslate}
onClick={() => {
setForceTranslate(true);
}}
>
<Icon icon="translate" />
<span>Translate</span>
2023-12-21 10:17:14 +00:00
</MenuItem>
{supportsTTS && (
<MenuItem
onClick={() => {
const postText = getPostText(status);
if (postText) {
speak(postText, language);
}
}}
>
<Icon icon="speak" />
<span>Speak</span>
</MenuItem>
)}
</div>
) : (
(!language || differentLanguage) && (
<div class={supportsTTS ? 'menu-horizontal' : ''}>
<MenuLink
to={`${instance ? `/${instance}` : ''}/s/${id}?translate=1`}
>
<Icon icon="translate" />
<span>Translate</span>
</MenuLink>
{supportsTTS && (
<MenuItem
onClick={() => {
const postText = getPostText(status);
if (postText) {
speak(postText, language);
}
}}
>
<Icon icon="speak" />
<span>Speak</span>
</MenuItem>
)}
</div>
)
)}
{((!isSizeLarge && sameInstance) || enableTranslate) && <MenuDivider />}
<MenuItem href={url} target="_blank">
<Icon icon="external" />
2023-03-09 13:51:50 +00:00
<small class="menu-double-lines">{nicePostURL(url)}</small>
</MenuItem>
2023-03-09 13:51:50 +00:00
<div class="menu-horizontal">
<MenuItem
onClick={() => {
2023-03-09 13:51:50 +00:00
// Copy url to clipboard
try {
navigator.clipboard.writeText(url);
showToast('Link copied');
} catch (e) {
console.error(e);
showToast('Unable to copy link');
}
}}
>
2023-03-09 13:51:50 +00:00
<Icon icon="link" />
<span>Copy</span>
</MenuItem>
2023-03-09 13:51:50 +00:00
{navigator?.share &&
navigator?.canShare?.({
url,
}) && (
<MenuItem
onClick={() => {
try {
navigator.share({
url,
});
} catch (e) {
console.error(e);
alert("Sharing doesn't seem to work.");
}
}}
>
<Icon icon="share" />
<span>Share</span>
</MenuItem>
)}
</div>
2023-04-09 16:30:32 +00:00
{(isSelf || mentionSelf) && <MenuDivider />}
{(isSelf || mentionSelf) && (
<MenuItem
onClick={async () => {
try {
const newStatus = await masto.v1.statuses
.$select(id)
[muted ? 'unmute' : 'mute']();
2023-04-09 16:30:32 +00:00
saveStatus(newStatus, instance);
showToast(muted ? 'Conversation unmuted' : 'Conversation muted');
} catch (e) {
console.error(e);
showToast(
muted
? 'Unable to unmute conversation'
: 'Unable to mute conversation',
);
}
}}
>
{muted ? (
<>
<Icon icon="unmute" />
<span>Unmute conversation</span>
</>
) : (
<>
<Icon icon="mute" />
<span>Mute conversation</span>
</>
)}
</MenuItem>
)}
{isSelf && (
2023-04-09 17:21:02 +00:00
<div class="menu-horizontal">
<MenuItem
onClick={() => {
states.showCompose = {
editStatus: status,
};
}}
>
<Icon icon="pencil" />
<span>Edit</span>
</MenuItem>
2023-03-17 09:14:54 +00:00
{isSizeLarge && (
<MenuConfirm
subMenu
confirmLabel={
<>
<Icon icon="trash" />
<span>Delete this post?</span>
</>
}
menuItemClassName="danger"
2023-03-17 09:14:54 +00:00
onClick={() => {
// const yes = confirm('Delete this post?');
// if (yes) {
(async () => {
try {
await masto.v1.statuses.$select(id).remove();
const cachedStatus = getStatus(id, instance);
cachedStatus._deleted = true;
showToast('Deleted');
} catch (e) {
console.error(e);
showToast('Unable to delete');
}
})();
// }
2023-03-17 09:14:54 +00:00
}}
>
<Icon icon="trash" />
<span>Delete</span>
</MenuConfirm>
2023-03-17 09:14:54 +00:00
)}
2023-04-09 17:21:02 +00:00
</div>
)}
</>
);
2023-03-07 16:01:51 +00:00
const contextMenuRef = useRef();
2023-03-02 07:15:49 +00:00
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
const [contextMenuProps, setContextMenuProps] = useState({});
const showContextMenu =
allowContextMenu || (!isSizeLarge && !previewMode && !_deleted && !quoted);
2023-10-01 09:14:32 +00:00
// Only iOS/iPadOS browsers don't support contextmenu
// Some comments report iPadOS might support contextmenu if a mouse is connected
const bindLongPressContext = useLongPress(
isIOS && showContextMenu
2023-10-01 09:14:32 +00:00
? (e) => {
if (e.pointerType === 'mouse') return;
// There's 'pen' too, but not sure if contextmenu event would trigger from a pen
const { clientX, clientY } = e.touches?.[0] || e;
// link detection copied from onContextMenu because here it works
const link = e.target.closest('a');
if (link && /^https?:\/\//.test(link.getAttribute('href'))) return;
e.preventDefault();
setContextMenuProps({
anchorPoint: {
x: clientX,
y: clientY,
},
direction: 'right',
2023-10-01 09:14:32 +00:00
});
setIsContextMenuOpen(true);
}
: null,
2023-03-07 16:01:51 +00:00
{
2023-04-24 13:36:03 +00:00
threshold: 600,
2023-03-07 16:01:51 +00:00
captureEvent: true,
detect: 'touch',
2023-09-29 16:26:51 +00:00
cancelOnMovement: 2, // true allows movement of up to 25 pixels
2023-03-07 16:01:51 +00:00
},
);
2023-03-02 07:15:49 +00:00
2023-12-29 10:16:08 +00:00
const hotkeysEnabled = !readOnly && !previewMode && !quoted;
const rRef = useHotkeys('r, shift+r', replyStatus, {
2023-09-08 07:32:55 +00:00
enabled: hotkeysEnabled,
});
const fRef = useHotkeys(
'f, l',
2023-09-08 07:32:55 +00:00
() => {
try {
favouriteStatus();
if (!isSizeLarge) {
2023-10-19 12:02:31 +00:00
showToast(
favourited
? `Unliked @${username || acct}'s post`
: `Liked @${username || acct}'s post`,
2023-10-19 12:02:31 +00:00
);
2023-09-08 07:32:55 +00:00
}
} catch (e) {}
},
{
enabled: hotkeysEnabled,
},
);
const dRef = useHotkeys(
'd',
() => {
try {
bookmarkStatus();
if (!isSizeLarge) {
2023-10-19 12:02:31 +00:00
showToast(
bookmarked
? `Unbookmarked @${username || acct}'s post`
: `Bookmarked @${username || acct}'s post`,
);
2023-09-08 07:32:55 +00:00
}
} catch (e) {}
},
{
enabled: hotkeysEnabled,
},
);
const bRef = useHotkeys(
'shift+b',
() => {
(async () => {
try {
const done = await confirmBoostStatus();
if (!isSizeLarge && done) {
2023-10-19 12:02:31 +00:00
showToast(
reblogged
? `Unboosted @${username || acct}'s post`
: `Boosted @${username || acct}'s post`,
);
2023-09-08 07:32:55 +00:00
}
} catch (e) {}
})();
},
{
enabled: hotkeysEnabled && canBoost,
},
);
2023-12-20 08:42:36 +00:00
const xRef = useHotkeys('x', (e) => {
const activeStatus = document.activeElement.closest(
'.status-link, .status-focus',
);
if (activeStatus) {
const spoilerButton = activeStatus.querySelector(
'.spoiler-button:not(.spoiling)',
2023-12-20 08:42:36 +00:00
);
if (spoilerButton) {
e.stopPropagation();
spoilerButton.click();
} else {
const spoilerMediaButton = activeStatus.querySelector(
'.spoiler-media-button:not(.spoiling)',
);
if (spoilerMediaButton) {
e.stopPropagation();
spoilerMediaButton.click();
}
2023-12-20 08:42:36 +00:00
}
}
});
2023-09-08 07:32:55 +00:00
const displayedMediaAttachments = mediaAttachments.slice(
0,
isSizeLarge ? undefined : 4,
);
2023-10-07 01:41:38 +00:00
const showMultipleMediaCaptions =
mediaAttachments.length > 1 &&
displayedMediaAttachments.some(
(media) => !!media.description && !isMediaCaptionLong(media.description),
);
const captionChildren = useMemo(() => {
if (!showMultipleMediaCaptions) return null;
const attachments = [];
displayedMediaAttachments.forEach((media, i) => {
if (!media.description) return;
const index = attachments.findIndex(
(attachment) => attachment.media.description === media.description,
);
if (index === -1) {
attachments.push({
media,
indices: [i],
});
} else {
attachments[index].indices.push(i);
}
});
return attachments.map(({ media, indices }) => (
<div
key={media.id}
data-caption-index={indices.map((i) => i + 1).join(' ')}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
states.showMediaAlt = {
alt: media.description,
lang: language,
};
}}
title={media.description}
>
<sup>{indices.map((i) => i + 1).join(' ')}</sup> {media.description}
</div>
));
// return displayedMediaAttachments.map(
// (media, i) =>
// !!media.description && (
// <div
// key={media.id}
// data-caption-index={i + 1}
// onClick={(e) => {
// e.preventDefault();
// e.stopPropagation();
// states.showMediaAlt = {
// alt: media.description,
// lang: language,
// };
// }}
// title={media.description}
// >
// <sup>{i + 1}</sup> {media.description}
// </div>
// ),
// );
}, [showMultipleMediaCaptions, displayedMediaAttachments, language]);
2023-11-14 08:52:47 +00:00
const isThread = useMemo(() => {
return (
(!!inReplyToId && inReplyToAccountId === status.account?.id) ||
!!snapStates.statusThreadNumber[sKey]
);
2023-11-14 14:45:13 +00:00
}, [
inReplyToId,
inReplyToAccountId,
status.account?.id,
snapStates.statusThreadNumber[sKey],
]);
2023-11-14 08:52:47 +00:00
const showCommentHint = useMemo(() => {
return (
2023-11-14 14:45:13 +00:00
enableCommentHint &&
2023-11-14 08:52:47 +00:00
!isThread &&
!withinContext &&
!inReplyToId &&
visibility === 'public' &&
repliesCount > 0
);
2023-11-14 14:45:13 +00:00
}, [
enableCommentHint,
isThread,
withinContext,
inReplyToId,
repliesCount,
visibility,
]);
const showCommentCount = useMemo(() => {
if (
card ||
poll ||
sensitive ||
spoilerText ||
mediaAttachments?.length ||
isThread ||
withinContext ||
inReplyToId ||
repliesCount <= 0
) {
return false;
}
const questionRegex = /[???︖❓❔⁇⁈⁉¿‽؟]/;
const containsQuestion = questionRegex.test(content);
if (!containsQuestion) return false;
const contentLength = htmlContentLength(content);
if (contentLength > 0 && contentLength <= SHOW_COMMENT_COUNT_LIMIT) {
return true;
}
}, [
card,
poll,
sensitive,
spoilerText,
mediaAttachments,
reblog,
isThread,
withinContext,
inReplyToId,
repliesCount,
content,
]);
2023-11-14 08:52:47 +00:00
2022-12-10 09:14:48 +00:00
return (
2022-12-29 08:12:09 +00:00
<article
2023-11-04 11:18:12 +00:00
data-state-post-id={sKey}
2023-09-08 07:32:55 +00:00
ref={(node) => {
statusRef.current = node;
// Use parent node if it's in focus
// Use case: <a><status /></a>
// When navigating (j/k), the <a> is focused instead of <status />
// Hotkey binding doesn't bubble up thus this hack
const nodeRef =
node?.closest?.(
'.timeline-item, .timeline-item-alt, .status-link, .status-focus',
) || node;
rRef.current = nodeRef;
fRef.current = nodeRef;
dRef.current = nodeRef;
bRef.current = nodeRef;
2023-12-20 08:42:36 +00:00
xRef.current = nodeRef;
2023-09-08 07:32:55 +00:00
}}
2022-12-30 12:37:57 +00:00
tabindex="-1"
2022-12-18 13:10:05 +00:00
class={`status ${
!withinContext && inReplyToId && inReplyToAccount
? 'status-reply-to'
: ''
2023-02-17 02:12:59 +00:00
} visibility-${visibility} ${_pinned ? 'status-pinned' : ''} ${
2022-12-18 13:10:05 +00:00
{
s: 'small',
m: 'medium',
l: 'large',
}[size]
2023-04-22 16:55:47 +00:00
} ${_deleted ? 'status-deleted' : ''} ${quoted ? 'status-card' : ''}`}
2022-12-18 13:10:05 +00:00
onMouseEnter={debugHover}
2023-03-02 07:15:49 +00:00
onContextMenu={(e) => {
// FIXME: this code isn't getting called on Chrome at all?
if (!showContextMenu) return;
2023-03-02 07:15:49 +00:00
if (e.metaKey) return;
// console.log('context menu', e);
2023-03-09 13:51:50 +00:00
const link = e.target.closest('a');
if (link && /^https?:\/\//.test(link.getAttribute('href'))) return;
2023-03-02 07:15:49 +00:00
e.preventDefault();
setContextMenuProps({
anchorPoint: {
x: e.clientX,
y: e.clientY,
},
direction: 'right',
2023-03-02 07:15:49 +00:00
});
setIsContextMenuOpen(true);
}}
{...(showContextMenu ? bindLongPressContext() : {})}
2022-12-18 13:10:05 +00:00
>
{showContextMenu && (
<ControlledMenu
2023-03-07 16:01:51 +00:00
ref={contextMenuRef}
state={isContextMenuOpen ? 'open' : undefined}
{...contextMenuProps}
2023-08-06 08:54:13 +00:00
onClose={(e) => {
setIsContextMenuOpen(false);
// statusRef.current?.focus?.();
2023-08-06 08:54:13 +00:00
if (e?.reason === 'click') {
statusRef.current?.closest('[tabindex]')?.focus?.();
}
}}
portal={{
target: document.body,
}}
containerProps={{
style: {
// Higher than the backdrop
zIndex: 1001,
},
2023-03-07 16:01:51 +00:00
onClick: () => {
contextMenuRef.current?.closeMenu?.();
},
}}
overflow="auto"
boundingBoxPadding={safeBoundingBoxPadding()}
unmountOnClose
>
{StatusMenuItems}
</ControlledMenu>
)}
2022-12-20 12:17:38 +00:00
{size !== 'l' && (
<div class="status-badge">
{reblogged && <Icon class="reblog" icon="rocket" size="s" />}
{favourited && <Icon class="favourite" icon="heart" size="s" />}
{bookmarked && <Icon class="bookmark" icon="bookmark" size="s" />}
2023-02-17 02:12:59 +00:00
{_pinned && <Icon class="pin" icon="pin" size="s" />}
2022-12-20 12:17:38 +00:00
</div>
)}
2022-12-18 13:10:05 +00:00
{size !== 's' && (
<a
2023-02-21 06:29:25 +00:00
href={accountURL}
2022-12-29 08:11:58 +00:00
tabindex="-1"
2022-12-18 13:10:05 +00:00
// target="_blank"
title={`@${acct}`}
onClick={(e) => {
2022-12-10 09:14:48 +00:00
e.preventDefault();
2022-12-18 13:10:05 +00:00
e.stopPropagation();
states.showAccount = {
account: status.account,
instance,
};
2022-12-10 09:14:48 +00:00
}}
>
2023-04-10 16:26:43 +00:00
<Avatar url={avatarStatic || avatar} size="xxl" squircle={bot} />
2022-12-18 13:10:05 +00:00
</a>
2022-12-10 09:14:48 +00:00
)}
2022-12-18 13:10:05 +00:00
<div class="container">
<div class="meta">
<span class="meta-name">
<NameText
account={status.account}
instance={instance}
showAvatar={size === 's'}
showAcct={isSizeLarge}
/>
</span>
{/* {inReplyToAccount && !withinContext && size !== 's' && (
2022-12-18 13:10:05 +00:00
<>
{' '}
<span class="ib">
<Icon icon="arrow-right" class="arrow" />{' '}
<NameText account={inReplyToAccount} instance={instance} short />
2022-12-18 13:10:05 +00:00
</span>
</>
)} */}
{/* </span> */}{' '}
2022-12-18 13:10:05 +00:00
{size !== 'l' &&
2023-03-17 09:14:54 +00:00
(_deleted ? (
<span class="status-deleted-tag">Deleted</span>
) : url && !previewMode && !quoted ? (
<Link
to={instance ? `/${instance}/s/${id}` : `/s/${id}`}
onClick={(e) => {
if (
e.metaKey ||
e.ctrlKey ||
e.shiftKey ||
e.altKey ||
e.which === 2
) {
return;
}
e.preventDefault();
e.stopPropagation();
onStatusLinkClick?.(e, status);
setContextMenuProps({
anchorRef: {
current: e.currentTarget,
},
align: 'end',
direction: 'bottom',
gap: 4,
});
setIsContextMenuOpen(true);
}}
class={`time ${
isContextMenuOpen && contextMenuProps?.anchorRef
? 'is-open'
: ''
}`}
>
{showCommentHint && !showCommentCount ? (
2023-11-14 08:52:47 +00:00
<Icon
icon="comment2"
size="s"
alt={`${repliesCount} ${
repliesCount === 1 ? 'reply' : 'replies'
}`}
/>
) : (
<Icon
icon={visibilityIconsMap[visibility]}
alt={visibilityText[visibility]}
size="s"
/>
)}{' '}
<RelativeTime datetime={createdAtDate} format="micro" />
{!previewMode && <Icon icon="more2" class="more" />}
</Link>
2022-12-18 13:10:05 +00:00
) : (
// <Menu
// instanceRef={menuInstanceRef}
// portal={{
// target: document.body,
// }}
// containerProps={{
// style: {
// // Higher than the backdrop
// zIndex: 1001,
// },
// onClick: (e) => {
// if (e.target === e.currentTarget)
// menuInstanceRef.current?.closeMenu?.();
// },
// }}
// align="end"
// gap={4}
// overflow="auto"
// viewScroll="close"
// boundingBoxPadding="8 8 8 8"
// unmountOnClose
// menuButton={({ open }) => (
// <Link
// to={instance ? `/${instance}/s/${id}` : `/s/${id}`}
// onClick={(e) => {
// e.preventDefault();
// e.stopPropagation();
// onStatusLinkClick?.(e, status);
// }}
// class={`time ${open ? 'is-open' : ''}`}
// >
// <Icon
// icon={visibilityIconsMap[visibility]}
// alt={visibilityText[visibility]}
// size="s"
// />{' '}
// <RelativeTime datetime={createdAtDate} format="micro" />
// </Link>
// )}
// >
// {StatusMenuItems}
// </Menu>
2022-12-18 13:10:05 +00:00
<span class="time">
<Icon
icon={visibilityIconsMap[visibility]}
alt={visibilityText[visibility]}
2022-12-18 13:10:05 +00:00
size="s"
/>{' '}
<RelativeTime datetime={createdAtDate} format="micro" />
2022-12-18 13:10:05 +00:00
</span>
))}
</div>
2023-04-06 10:21:56 +00:00
{visibility === 'direct' && (
<>
<div class="status-direct-badge">Private mention</div>{' '}
</>
)}
{!withinContext && (
2023-01-10 11:59:02 +00:00
<>
2023-11-14 08:52:47 +00:00
{isThread ? (
2023-01-10 11:59:02 +00:00
<div class="status-thread-badge">
<Icon icon="thread" size="s" />
Thread
{snapStates.statusThreadNumber[sKey]
? ` ${snapStates.statusThreadNumber[sKey]}/X`
2023-01-10 11:59:02 +00:00
: ''}
</div>
) : (
!!inReplyToId &&
!!inReplyToAccount &&
(!!spoilerText ||
!mentions.find((mention) => {
return mention.id === inReplyToAccountId;
})) && (
<div class="status-reply-badge">
<Icon icon="reply" />{' '}
<NameText
account={inReplyToAccount}
instance={instance}
short
/>
</div>
2023-01-10 11:59:02 +00:00
)
)}
</>
)}
2022-12-18 13:10:05 +00:00
<div
2023-02-07 04:56:26 +00:00
class={`content-container ${
spoilerText || sensitive ? 'has-spoiler' : ''
} ${showSpoiler ? 'show-spoiler' : ''} ${
showSpoilerMedia ? 'show-media' : ''
}`}
data-content-text-weight={contentTextWeight ? textWeight() : null}
2022-12-18 13:10:05 +00:00
style={
(isSizeLarge || contentTextWeight) && {
'--content-text-weight': textWeight(),
2022-12-18 13:10:05 +00:00
}
}
>
{!!spoilerText && (
2022-12-14 13:48:17 +00:00
<>
2022-12-18 13:10:05 +00:00
<div
2023-08-23 10:34:11 +00:00
class="content spoiler-content"
2022-12-18 13:10:05 +00:00
lang={language}
2023-04-10 12:23:40 +00:00
dir="auto"
2022-12-18 13:10:05 +00:00
ref={spoilerContentRef}
data-read-more={readMoreText}
>
<p>
<EmojiText text={spoilerText} emojis={emojis} />
</p>
2022-12-18 13:10:05 +00:00
</div>
{readingExpandSpoilers || previewMode ? (
<div class="spoiler-divider">
<Icon icon="eye-open" /> Content warning
</div>
) : (
<button
class={`light spoiler-button ${
showSpoiler ? 'spoiling' : ''
}`}
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (showSpoiler) {
delete states.spoilers[id];
if (!readingExpandSpoilers) {
delete states.spoilersMedia[id];
}
} else {
states.spoilers[id] = true;
if (!readingExpandSpoilers) {
states.spoilersMedia[id] = true;
}
}
}}
>
<Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} />{' '}
{showSpoiler ? 'Show less' : 'Show content'}
</button>
)}
2022-12-10 09:14:48 +00:00
</>
)}
2023-12-03 12:26:42 +00:00
{!!content && (
<div class="content" ref={contentRef} data-read-more={readMoreText}>
<div
lang={language}
dir="auto"
class="inner-content"
onClick={handleContentLinks({
mentions,
instance,
previewMode,
statusURL: url,
})}
dangerouslySetInnerHTML={{
__html: enhanceContent(content, {
emojis,
postEnhanceDOM: (dom) => {
// Remove target="_blank" from links
dom
.querySelectorAll('a.u-url[target="_blank"]')
.forEach((a) => {
if (!/http/i.test(a.innerText.trim())) {
a.removeAttribute('target');
2023-12-03 12:26:42 +00:00
}
});
// if (previewMode) return;
2023-12-03 12:26:42 +00:00
// Unfurl Mastodon links
// Array.from(
// dom.querySelectorAll(
// 'a[href]:not(.u-url):not(.mention):not(.hashtag)',
// ),
// )
// .filter((a) => {
// const url = a.href;
// const isPostItself =
// url === status.url || url === status.uri;
// return !isPostItself && isMastodonLinkMaybe(url);
// })
// .forEach((a, i) => {
// unfurlMastodonLink(currentInstance, a.href).then(
// (result) => {
// if (!result) return;
// a.removeAttribute('target');
// if (!sKey) return;
// if (!Array.isArray(states.statusQuotes[sKey])) {
// states.statusQuotes[sKey] = [];
// }
// if (!states.statusQuotes[sKey][i]) {
// states.statusQuotes[sKey].splice(i, 0, result);
// }
// },
// );
// });
2023-12-03 12:26:42 +00:00
},
}),
}}
/>
<QuoteStatuses id={id} instance={instance} level={quoted} />
</div>
)}
2022-12-21 11:29:37 +00:00
{!!poll && (
<Poll
lang={language}
2022-12-21 11:29:37 +00:00
poll={poll}
2023-02-19 06:49:53 +00:00
readOnly={readOnly || !sameInstance || !authenticated}
2022-12-21 11:29:37 +00:00
onUpdate={(newPoll) => {
states.statuses[sKey].poll = newPoll;
2022-12-21 11:29:37 +00:00
}}
refresh={() => {
return masto.v1.polls
.$select(poll.id)
.fetch()
.then((pollResponse) => {
states.statuses[sKey].poll = pollResponse;
})
.catch((e) => {}); // Silently fail
}}
votePoll={(choices) => {
return masto.v1.polls
.$select(poll.id)
.votes.create({
choices,
})
.then((pollResponse) => {
states.statuses[sKey].poll = pollResponse;
})
.catch((e) => {}); // Silently fail
}}
2022-12-21 11:29:37 +00:00
/>
)}
2023-07-31 12:30:29 +00:00
{(((enableTranslate || inlineTranslate) &&
!!content.trim() &&
!!getHTMLText(emojifyText(content, emojis)) &&
2023-07-31 12:30:29 +00:00
differentLanguage) ||
forceTranslate) && (
<TranslationBlock
forceTranslate={forceTranslate || inlineTranslate}
2023-07-21 16:06:15 +00:00
mini={!isSizeLarge && !withinContext}
sourceLanguage={language}
2023-12-21 10:17:14 +00:00
text={getPostText(status)}
/>
)}
{!previewMode &&
sensitive &&
!!mediaAttachments.length &&
readingExpandMedia !== 'show_all' && (
<button
class={`plain spoiler-media-button ${
showSpoilerMedia ? 'spoiling' : ''
}`}
type="button"
hidden={!readingExpandSpoilers && !!spoilerText}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (showSpoilerMedia) {
delete states.spoilersMedia[id];
} else {
states.spoilersMedia[id] = true;
}
}}
>
<Icon icon={showSpoilerMedia ? 'eye-open' : 'eye-close'} />{' '}
{showSpoilerMedia ? 'Show less' : 'Show media'}
</button>
)}
{!!mediaAttachments.length && (
<MultipleMediaFigure
lang={language}
2023-10-07 01:41:38 +00:00
enabled={showMultipleMediaCaptions}
captionChildren={captionChildren}
>
<div
ref={mediaContainerRef}
class={`media-container media-eq${mediaAttachments.length} ${
mediaAttachments.length > 2 ? 'media-gt2' : ''
} ${mediaAttachments.length > 4 ? 'media-gt4' : ''}`}
>
{displayedMediaAttachments.map((media, i) => (
<Media
key={media.id}
media={media}
autoAnimate={isSizeLarge}
showCaption={mediaAttachments.length === 1}
lang={language}
altIndex={
2023-10-07 01:41:38 +00:00
showMultipleMediaCaptions && !!media.description && i + 1
}
to={`/${instance}/s/${id}?${
withinContext ? 'media' : 'media-only'
}=${i + 1}`}
onClick={
onMediaClick
? (e) => {
onMediaClick(e, i, media, status);
}
: undefined
}
/>
))}
</div>
</MultipleMediaFigure>
2022-12-10 09:14:48 +00:00
)}
{!!card &&
/^https/i.test(card?.url) &&
!sensitive &&
!spoilerText &&
!poll &&
2023-04-23 11:29:25 +00:00
!mediaAttachments.length &&
!snapStates.statusQuotes[sKey] && (
<Card
card={card}
selfReferential={
card?.url === status.url || card?.url === status.uri
}
instance={currentInstance}
/>
)}
2022-12-10 09:14:48 +00:00
</div>
{!isSizeLarge && showCommentCount && (
<div class="content-comment-hint insignificant">
<Icon icon="comment2" alt="Replies" /> {repliesCount}
</div>
)}
{isSizeLarge && (
<>
<div class="extra-meta">
2023-03-17 09:14:54 +00:00
{_deleted ? (
<span class="status-deleted-tag">Deleted</span>
) : (
2022-12-10 09:14:48 +00:00
<>
2023-03-17 09:14:54 +00:00
<Icon
icon={visibilityIconsMap[visibility]}
2023-05-20 11:43:32 +00:00
alt={visibilityText[visibility]}
2023-03-17 09:14:54 +00:00
/>{' '}
2023-09-26 02:55:36 +00:00
<a href={url} target="_blank" rel="noopener noreferrer">
2023-03-17 09:14:54 +00:00
<time
class="created"
datetime={createdAtDate.toISOString()}
2023-12-15 15:30:09 +00:00
title={createdAtDate.toLocaleString()}
2023-03-17 09:14:54 +00:00
>
{createdDateText}
</time>
</a>
{editedAt && (
<>
{' '}
&bull; <Icon icon="pencil" alt="Edited" />{' '}
<time
2023-11-02 02:50:21 +00:00
tabIndex="0"
2023-03-17 09:14:54 +00:00
class="edited"
datetime={editedAtDate.toISOString()}
onClick={() => {
setShowEdited(id);
}}
>
{editedDateText}
</time>
</>
)}
2022-12-10 09:14:48 +00:00
</>
)}
</div>
2023-03-17 09:14:54 +00:00
<div class={`actions ${_deleted ? 'disabled' : ''}`}>
2022-12-19 05:38:16 +00:00
<div class="action has-count">
<StatusButton
title="Reply"
alt="Comments"
class="reply-button"
icon="comment"
count={repliesCount}
onClick={replyStatus}
2022-12-19 05:38:16 +00:00
/>
</div>
{/* <div class="action has-count">
<StatusButton
checked={reblogged}
title={['Boost', 'Unboost']}
alt={['Boost', 'Boosted']}
class="reblog-button"
icon="rocket"
count={reblogsCount}
onClick={boostStatus}
disabled={!canBoost}
/>
</div> */}
2023-07-18 10:45:38 +00:00
<MenuConfirm
disabled={!canBoost}
onClick={confirmBoostStatus}
confirmLabel={
<>
<Icon icon="rocket" />
<span>{reblogged ? 'Unboost?' : 'Boost to everyone?'}</span>
</>
}
menuFooter={
mediaNoDesc &&
!reblogged && (
<div class="footer">
<Icon icon="alert" />
Some media have no descriptions.
</div>
)
}
>
2023-07-18 10:45:38 +00:00
<div class="action has-count">
<StatusButton
checked={reblogged}
title={['Boost', 'Unboost']}
alt={['Boost', 'Boosted']}
class="reblog-button"
icon="rocket"
count={reblogsCount}
// onClick={boostStatus}
disabled={!canBoost}
/>
</div>
</MenuConfirm>
2022-12-19 05:38:16 +00:00
<div class="action has-count">
<StatusButton
2022-12-19 05:38:16 +00:00
checked={favourited}
title={['Like', 'Unlike']}
alt={['Like', 'Liked']}
2022-12-19 05:38:16 +00:00
class="favourite-button"
icon="heart"
count={favouritesCount}
onClick={favouriteStatus}
/>
2022-12-19 05:38:16 +00:00
</div>
<div class="action">
<StatusButton
checked={bookmarked}
title={['Bookmark', 'Unbookmark']}
alt={['Bookmark', 'Bookmarked']}
class="bookmark-button"
icon="bookmark"
onClick={bookmarkStatus}
2022-12-19 05:38:16 +00:00
/>
</div>
<Menu2
portal={{
target:
document.querySelector('.status-deck') || document.body,
}}
align="end"
2023-06-13 09:46:37 +00:00
gap={4}
overflow="auto"
viewScroll="close"
menuButton={
<div class="action">
<button
type="button"
title="More"
class="plain more-button"
>
<Icon icon="more" size="l" alt="More" />
</button>
</div>
}
>
{StatusMenuItems}
</Menu2>
</div>
</>
2022-12-10 09:14:48 +00:00
)}
</div>
2022-12-18 13:10:05 +00:00
{!!showEdited && (
<Modal
2023-11-02 02:49:52 +00:00
class="light"
2022-12-18 13:10:05 +00:00
onClick={(e) => {
if (e.target === e.currentTarget) {
setShowEdited(false);
2023-11-02 02:50:01 +00:00
// statusRef.current?.focus();
2022-12-18 13:10:05 +00:00
}
}}
>
<EditedAtModal
statusID={showEdited}
instance={instance}
fetchStatusHistory={() => {
return masto.v1.statuses.$select(showEdited).history.list();
}}
2022-12-18 13:10:05 +00:00
onClose={() => {
setShowEdited(false);
2022-12-30 12:37:57 +00:00
statusRef.current?.focus();
2022-12-18 13:10:05 +00:00
}}
/>
</Modal>
)}
2022-12-29 08:12:09 +00:00
</article>
2022-12-18 13:10:05 +00:00
);
}
function MultipleMediaFigure(props) {
const { enabled, children, lang, captionChildren } = props;
if (!enabled || !captionChildren) return children;
return (
<figure class="media-figure-multiple">
{children}
<figcaption lang={lang} dir="auto">
{captionChildren}
</figcaption>
</figure>
);
}
function Card({ card, selfReferential, instance }) {
2023-04-22 16:55:47 +00:00
const snapStates = useSnapshot(states);
2022-12-18 13:10:05 +00:00
const {
blurhash,
title,
description,
html,
providerName,
providerUrl,
2022-12-18 13:10:05 +00:00
authorName,
authorUrl,
2022-12-18 13:10:05 +00:00
width,
height,
image,
imageDescription,
2022-12-18 13:10:05 +00:00
url,
type,
embedUrl,
language,
publishedAt,
2022-12-18 13:10:05 +00:00
} = card;
/* type
link = Link OEmbed
photo = Photo OEmbed
video = Video OEmbed
rich = iframe OEmbed. Not currently accepted, so wont show up in practice.
*/
const hasText = title || providerName || authorName;
const isLandscape = width / height >= 1.2;
const size = isLandscape ? 'large' : '';
2022-12-18 13:10:05 +00:00
const [cardStatusURL, setCardStatusURL] = useState(null);
// const [cardStatusID, setCardStatusID] = useState(null);
useEffect(() => {
if (hasText && image && !selfReferential && isMastodonLinkMaybe(url)) {
unfurlMastodonLink(instance, url).then((result) => {
if (!result) return;
const { id, url } = result;
setCardStatusURL('#' + url);
// NOTE: This is for quote post
// (async () => {
// const { masto } = api({ instance });
// const status = await masto.v1.statuses.$select(id).fetch();
// saveStatus(status, instance);
// setCardStatusID(id);
// })();
});
}
}, [hasText, image, selfReferential]);
// if (cardStatusID) {
// return (
// <Status statusID={cardStatusID} instance={instance} size="s" readOnly />
// );
// }
2023-04-22 16:55:47 +00:00
if (snapStates.unfurledLinks[url]) return null;
2024-01-06 08:46:45 +00:00
const hasIframeHTML = /<iframe/i.test(html);
const handleClick = useCallback(
(e) => {
if (hasIframeHTML) {
e.preventDefault();
states.showEmbedModal = {
html,
url: url || embedUrl,
};
}
},
[hasIframeHTML],
);
2023-08-04 16:16:18 +00:00
if (hasText && (image || (type === 'photo' && blurhash))) {
2023-11-04 07:35:28 +00:00
const domain = new URL(url).hostname
.replace(/^www\./, '')
.replace(/\/$/, '');
let blurhashImage;
const rgbAverageColor =
image && blurhash ? getBlurHashAverageColor(blurhash) : null;
if (!image) {
const w = 44;
const h = 44;
const blurhashPixels = decodeBlurHash(blurhash, w, h);
const canvas = document.createElement('canvas');
canvas.width = w;
canvas.height = h;
const ctx = canvas.getContext('2d');
const imageData = ctx.createImageData(w, h);
imageData.data.set(blurhashPixels);
ctx.putImageData(imageData, 0, 0);
blurhashImage = canvas.toDataURL();
}
2022-12-18 13:10:05 +00:00
return (
<a
href={cardStatusURL || url}
target={cardStatusURL ? null : '_blank'}
2022-12-18 13:10:05 +00:00
rel="nofollow noopener noreferrer"
class={`card link ${blurhashImage ? '' : size}`}
lang={language}
2023-09-23 04:58:12 +00:00
dir="auto"
style={{
'--average-color':
rgbAverageColor && `rgb(${rgbAverageColor.join(',')})`,
}}
2024-01-06 08:46:45 +00:00
onClick={handleClick}
2022-12-18 13:10:05 +00:00
>
2023-01-07 12:25:13 +00:00
<div class="card-image">
<img
src={image || blurhashImage}
2023-01-07 12:25:13 +00:00
width={width}
height={height}
loading="lazy"
alt={imageDescription || ''}
2023-01-07 12:25:13 +00:00
onError={(e) => {
try {
e.target.style.display = 'none';
} catch (e) {}
}}
/>
</div>
2022-12-18 13:10:05 +00:00
<div class="meta-container">
2023-09-23 04:58:12 +00:00
<p class="meta domain" dir="auto">
{domain}
</p>
<p class="title" dir="auto">
{title}
</p>
<p class="meta" dir="auto">
{description ||
(!!publishedAt && (
<RelativeTime datetime={publishedAt} format="micro" />
))}
2023-09-23 04:58:12 +00:00
</p>
2022-12-18 13:10:05 +00:00
</div>
</a>
);
} else if (type === 'photo') {
return (
<a
href={url}
target="_blank"
rel="nofollow noopener noreferrer"
class="card photo"
2024-01-06 08:46:45 +00:00
onClick={handleClick}
2022-12-18 13:10:05 +00:00
>
<img
src={embedUrl}
width={width}
height={height}
alt={title || description}
loading="lazy"
style={{
height: 'auto',
aspectRatio: `${width}/${height}`,
}}
/>
</a>
);
2024-01-06 08:46:45 +00:00
} else {
if (type === 'video') {
if (/youtube/i.test(providerName)) {
// Get ID from e.g. https://www.youtube.com/watch?v=[VIDEO_ID]
const videoID = url.match(/watch\?v=([^&]+)/)?.[1];
if (videoID) {
return <lite-youtube videoid={videoID} nocookie></lite-youtube>;
}
}
2024-01-06 08:46:45 +00:00
// return (
// <div
// class="card video"
// style={{
// aspectRatio: `${width}/${height}`,
// }}
// dangerouslySetInnerHTML={{ __html: html }}
// />
// );
}
if (hasText && !image) {
const domain = new URL(url).hostname.replace(/^www\./, '');
return (
<a
href={cardStatusURL || url}
target={cardStatusURL ? null : '_blank'}
rel="nofollow noopener noreferrer"
class={`card link no-image`}
lang={language}
onClick={handleClick}
>
<div class="meta-container">
<p class="meta domain">
<Icon icon="link" size="s" /> <span>{domain}</span>
</p>
<p class="title">{title}</p>
<p class="meta">{description || providerName || authorName}</p>
</div>
</a>
);
}
2022-12-18 13:10:05 +00:00
}
}
function EditedAtModal({
statusID,
instance,
fetchStatusHistory = () => {},
2023-04-20 08:10:57 +00:00
onClose,
}) {
2022-12-18 13:10:05 +00:00
const [uiState, setUIState] = useState('default');
const [editHistory, setEditHistory] = useState([]);
useEffect(() => {
setUIState('loading');
(async () => {
try {
const editHistory = await fetchStatusHistory();
2022-12-18 13:10:05 +00:00
console.log(editHistory);
setEditHistory(editHistory);
setUIState('default');
} catch (e) {
console.error(e);
setUIState('error');
}
})();
}, []);
return (
2022-12-30 12:37:57 +00:00
<div id="edit-history" class="sheet">
2023-04-20 08:10:57 +00:00
{!!onClose && (
<button type="button" class="sheet-close" onClick={onClose}>
<Icon icon="x" />
</button>
)}
<header>
<h2>Edit History</h2>
{uiState === 'error' && <p>Failed to load history</p>}
{uiState === 'loading' && (
<p>
<Loader abrupt /> Loading&hellip;
</p>
)}
</header>
2022-12-30 12:37:57 +00:00
<main tabIndex="-1">
{editHistory.length > 0 && (
<ol>
{editHistory.map((status) => {
const { createdAt } = status;
const createdAtDate = new Date(createdAt);
return (
<li key={createdAt} class="history-item">
<h3>
<time>
{niceDateTime(createdAtDate, {
formatOpts: {
weekday: 'short',
second: 'numeric',
},
})}
</time>
</h3>
<Status
status={status}
instance={instance}
size="s"
withinContext
readOnly
previewMode
/>
</li>
);
})}
</ol>
)}
</main>
2022-12-10 09:14:48 +00:00
</div>
);
2023-04-06 14:51:48 +00:00
}
function StatusButton({
checked,
count,
class: className,
title,
alt,
icon,
onClick,
...props
}) {
if (typeof title === 'string') {
title = [title, title];
}
if (typeof alt === 'string') {
alt = [alt, alt];
}
const [buttonTitle, setButtonTitle] = useState(title[0] || '');
const [iconAlt, setIconAlt] = useState(alt[0] || '');
useEffect(() => {
if (checked) {
setButtonTitle(title[1] || '');
setIconAlt(alt[1] || '');
} else {
setButtonTitle(title[0] || '');
setIconAlt(alt[0] || '');
}
}, [checked, title, alt]);
return (
<button
type="button"
title={buttonTitle}
class={`plain ${className} ${checked ? 'checked' : ''}`}
onClick={(e) => {
if (!onClick) return;
e.preventDefault();
e.stopPropagation();
onClick(e);
}}
{...props}
>
<Icon icon={icon} size="l" alt={iconAlt} />
{!!count && (
<>
{' '}
2022-12-17 16:13:56 +00:00
<small title={count}>{shortenNumber(count)}</small>
</>
)}
</button>
);
}
export function formatDuration(time) {
if (!time) return;
let hours = Math.floor(time / 3600);
let minutes = Math.floor((time % 3600) / 60);
let seconds = Math.round(time % 60);
if (hours === 0) {
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
} else {
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds
.toString()
.padStart(2, '0')}`;
}
}
2023-03-09 13:51:50 +00:00
function nicePostURL(url) {
if (!url) return;
2023-03-09 13:51:50 +00:00
const urlObj = new URL(url);
const { host, pathname } = urlObj;
const path = pathname.replace(/\/$/, '');
// split only first slash
const [_, username, restPath] = path.match(/\/(@[^\/]+)\/(.*)/) || [];
return (
<>
{host}
{username ? (
<>
/{username}
2023-03-10 11:34:04 +00:00
<wbr />
2023-03-09 13:51:50 +00:00
<span class="more-insignificant">/{restPath}</span>
</>
) : (
<span class="more-insignificant">{path}</span>
)}
</>
);
}
2023-12-14 17:58:29 +00:00
function FilteredStatus({
status,
filterInfo,
instance,
containerProps = {},
showFollowedTags,
}) {
const snapStates = useSnapshot(states);
2023-03-21 16:09:36 +00:00
const {
id: statusID,
account: { avatar, avatarStatic, bot, group },
2023-03-21 16:09:36 +00:00
createdAt,
visibility,
reblog,
2023-03-21 16:09:36 +00:00
} = status;
const isReblog = !!reblog;
2023-03-21 16:09:36 +00:00
const filterTitleStr = filterInfo?.titlesStr || '';
const createdAtDate = new Date(createdAt);
const statusPeekText = statusPeek(status.reblog || status);
2023-03-21 16:09:36 +00:00
const [showPeek, setShowPeek] = useState(false);
const bindLongPressPeek = useLongPress(
2023-03-21 16:09:36 +00:00
() => {
setShowPeek(true);
},
{
2023-04-24 13:36:03 +00:00
threshold: 600,
2023-03-21 16:09:36 +00:00
captureEvent: true,
detect: 'touch',
2023-09-29 16:26:51 +00:00
cancelOnMovement: 2, // true allows movement of up to 25 pixels
2023-03-21 16:09:36 +00:00
},
);
const statusPeekRef = useTruncated();
2023-12-14 17:58:29 +00:00
const sKey = statusKey(status.id, instance);
const ssKey =
2023-11-05 00:21:43 +00:00
statusKey(status.id, instance) +
' ' +
(statusKey(reblog?.id, instance) || '');
const actualStatusID = reblog?.id || statusID;
const url = instance
? `/${instance}/s/${actualStatusID}`
: `/s/${actualStatusID}`;
2023-12-14 17:58:29 +00:00
const isFollowedTags =
showFollowedTags && !!snapStates.statusFollowedTags[sKey]?.length;
2023-03-21 16:09:36 +00:00
return (
<div
2023-12-14 17:58:29 +00:00
class={
isReblog
? group
? 'status-group'
: 'status-reblog'
: isFollowedTags
? 'status-followed-tags'
: ''
}
2023-03-23 13:48:29 +00:00
{...containerProps}
2023-03-21 16:09:36 +00:00
title={statusPeekText}
onContextMenu={(e) => {
e.preventDefault();
setShowPeek(true);
}}
{...bindLongPressPeek()}
2023-03-21 16:09:36 +00:00
>
2023-12-14 17:58:29 +00:00
<article data-state-post-id={ssKey} class="status filtered" tabindex="-1">
2023-03-21 16:09:36 +00:00
<b
2023-03-22 04:26:28 +00:00
class="status-filtered-badge clickable badge-meta"
2023-03-21 16:09:36 +00:00
title={filterTitleStr}
onClick={(e) => {
e.preventDefault();
setShowPeek(true);
}}
>
2023-03-22 04:26:28 +00:00
<span>Filtered</span>
<span>{filterTitleStr}</span>
2023-03-21 16:09:36 +00:00
</b>{' '}
2023-04-10 16:26:43 +00:00
<Avatar url={avatarStatic || avatar} squircle={bot} />
2023-03-21 16:09:36 +00:00
<span class="status-filtered-info">
<span class="status-filtered-info-1">
<NameText account={status.account} instance={instance} />{' '}
<Icon
icon={visibilityIconsMap[visibility]}
alt={visibilityText[visibility]}
size="s"
/>{' '}
{isReblog ? (
'boosted'
2023-12-14 17:58:29 +00:00
) : isFollowedTags ? (
<span>
{snapStates.statusFollowedTags[sKey].slice(0, 3).map((tag) => (
<span key={tag} class="status-followed-tag-item">
#{tag}
</span>
))}
</span>
) : (
<RelativeTime datetime={createdAtDate} format="micro" />
)}
</span>
<span class="status-filtered-info-2">
{isReblog && (
<>
<Avatar
url={reblog.account.avatarStatic || reblog.account.avatar}
2023-04-10 16:26:43 +00:00
squircle={bot}
/>{' '}
</>
)}
{statusPeekText}
2023-03-21 16:09:36 +00:00
</span>
</span>
</article>
{!!showPeek && (
<Modal
class="light"
onClick={(e) => {
if (e.target === e.currentTarget) {
setShowPeek(false);
}
}}
>
<div id="filtered-status-peek" class="sheet">
2023-04-20 08:10:57 +00:00
<button
type="button"
class="sheet-close"
onClick={() => setShowPeek(false)}
>
<Icon icon="x" />
</button>
<header>
<b class="status-filtered-badge">Filtered</b> {filterTitleStr}
</header>
2023-03-21 16:09:36 +00:00
<main tabIndex="-1">
<Link
ref={statusPeekRef}
2023-03-21 16:09:36 +00:00
class="status-link"
to={url}
2023-03-21 16:09:36 +00:00
onClick={() => {
setShowPeek(false);
}}
data-read-more="Read more →"
2023-03-21 16:09:36 +00:00
>
<Status status={status} instance={instance} size="s" readOnly />
</Link>
</main>
</div>
</Modal>
)}
</div>
);
}
const QuoteStatuses = memo(({ id, instance, level = 0 }) => {
2023-05-19 17:06:16 +00:00
if (!id || !instance) return;
2023-04-22 16:55:47 +00:00
const snapStates = useSnapshot(states);
const sKey = statusKey(id, instance);
const quotes = snapStates.statusQuotes[sKey];
2023-05-17 08:13:49 +00:00
const uniqueQuotes = quotes?.filter(
(q, i, arr) => arr.findIndex((q2) => q2.url === q.url) === i,
);
2023-04-22 16:55:47 +00:00
2023-05-17 08:13:49 +00:00
if (!uniqueQuotes?.length) return;
if (level > 2) return;
2023-04-22 16:55:47 +00:00
2023-05-17 08:13:49 +00:00
return uniqueQuotes.map((q) => {
2023-04-22 16:55:47 +00:00
return (
<Link
key={q.instance + q.id}
2023-04-22 16:55:47 +00:00
to={`${q.instance ? `/${q.instance}` : ''}/s/${q.id}`}
class="status-card-link"
2023-09-20 09:27:54 +00:00
data-read-more="Read more →"
2023-04-22 16:55:47 +00:00
>
<Status
statusID={q.id}
instance={q.instance}
size="s"
quoted={level + 1}
2023-11-14 14:45:13 +00:00
enableCommentHint
2023-04-22 16:55:47 +00:00
/>
</Link>
);
});
});
2024-01-06 04:31:25 +00:00
export default memo(Status, (oldProps, newProps) => {
// Shallow equal all props except 'status'
// This will be pure static until status ID changes
const { status, ...restOldProps } = oldProps;
const { status: newStatus, ...restNewProps } = newProps;
return (
status?.id === newStatus?.id && shallowEqual(restOldProps, restNewProps)
);
});