[Glitch] Fixes collection notification urls
Port 6735902c1a6b409f58cfe7a494f1860b65a22fc3 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
17721fcf4c
commit
0741966d5f
@ -4,7 +4,6 @@ import type { ComponentProps, FC } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import type { ApiCollectionJSON } from '@/flavours/glitch/api_types/collections';
|
||||
import type { ApiMentionJSON } from '@/flavours/glitch/api_types/statuses';
|
||||
import { getCollectionPath } from '@/flavours/glitch/features/collections/utils';
|
||||
import { useAppSelector } from '@/flavours/glitch/store';
|
||||
@ -17,7 +16,7 @@ export interface HandledLinkProps {
|
||||
prevText?: string;
|
||||
hashtagAccountId?: string;
|
||||
mention?: Pick<ApiMentionJSON, 'id' | 'acct' | 'username'>;
|
||||
collection?: Pick<ApiCollectionJSON, 'id'>;
|
||||
collectionId?: string;
|
||||
}
|
||||
|
||||
const textMatchesTarget = (text: string, origin: string, host: string) => {
|
||||
@ -114,7 +113,7 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
||||
prevText,
|
||||
hashtagAccountId,
|
||||
mention,
|
||||
collection,
|
||||
collectionId,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
@ -184,11 +183,11 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
} else if (collection) {
|
||||
} else if (collectionId) {
|
||||
return (
|
||||
<Link
|
||||
className={classNames(className)}
|
||||
to={getCollectionPath(collection.id)}
|
||||
to={getCollectionPath(collectionId)}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
@ -222,15 +221,18 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
||||
|
||||
export const useElementHandledLink = ({
|
||||
hashtagAccountId,
|
||||
hrefToCollectionId: hrefToCollection,
|
||||
hrefToMention,
|
||||
}: {
|
||||
hashtagAccountId?: string;
|
||||
hrefToCollectionId?: (href: string) => string | undefined;
|
||||
hrefToMention?: (href: string) => ApiMentionJSON | undefined;
|
||||
} = {}) => {
|
||||
const onElement = useCallback<OnElementHandler>(
|
||||
(element, { key, ...props }, children) => {
|
||||
if (element instanceof HTMLAnchorElement) {
|
||||
const mention = hrefToMention?.(element.href);
|
||||
const collectionId = hrefToCollection?.(element.href);
|
||||
return (
|
||||
<HandledLink
|
||||
{...props}
|
||||
@ -240,6 +242,7 @@ export const useElementHandledLink = ({
|
||||
prevText={element.previousSibling?.textContent ?? undefined}
|
||||
hashtagAccountId={hashtagAccountId}
|
||||
mention={mention}
|
||||
collectionId={collectionId}
|
||||
>
|
||||
{children}
|
||||
</HandledLink>
|
||||
@ -247,7 +250,7 @@ export const useElementHandledLink = ({
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
[hashtagAccountId, hrefToMention],
|
||||
[hashtagAccountId, hrefToCollection, hrefToMention],
|
||||
);
|
||||
return { onElement };
|
||||
};
|
||||
|
||||
@ -170,7 +170,7 @@ class StatusContent extends PureComponent {
|
||||
text={element.innerText}
|
||||
hashtagAccountId={this.props.status.getIn(['account', 'id'])}
|
||||
mention={mention?.toJSON()}
|
||||
collection={taggedCollection?.toJSON()}
|
||||
collectionId={taggedCollection?.get('id')}
|
||||
key={key}
|
||||
>
|
||||
{children}
|
||||
|
||||
@ -24,11 +24,13 @@ import classes from './share_modal.module.scss';
|
||||
const messages = defineMessages({
|
||||
shareTextOwn: {
|
||||
id: 'collection.share_template_own',
|
||||
defaultMessage: 'Check out my new collection: {link}',
|
||||
defaultMessage: 'Check out my new collection:',
|
||||
description: 'Collection links are appended after a new line',
|
||||
},
|
||||
shareTextOther: {
|
||||
id: 'collection.share_template_other',
|
||||
defaultMessage: 'Check out this cool collection: {link}',
|
||||
defaultMessage: 'Check out this cool collection:',
|
||||
description: 'Collection links are appended after a new line',
|
||||
},
|
||||
});
|
||||
|
||||
@ -51,13 +53,10 @@ export const CollectionShareModal: React.FC<{
|
||||
}, [collectionLink]);
|
||||
|
||||
const handleShareViaPost = useCallback(() => {
|
||||
const shareMessage = isOwnCollection
|
||||
? intl.formatMessage(messages.shareTextOwn, {
|
||||
link: collectionLink,
|
||||
})
|
||||
: intl.formatMessage(messages.shareTextOther, {
|
||||
link: collectionLink,
|
||||
});
|
||||
let shareMessage = isOwnCollection
|
||||
? intl.formatMessage(messages.shareTextOwn)
|
||||
: intl.formatMessage(messages.shareTextOther);
|
||||
shareMessage += `\n\n${collectionLink}`;
|
||||
|
||||
onClose();
|
||||
dispatch(changeCompose(shareMessage));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import type { List } from 'immutable';
|
||||
import type { List, Map } from 'immutable';
|
||||
|
||||
import { EmojiHTML } from '@/flavours/glitch/components/emoji/html';
|
||||
import { useElementHandledLink } from '@/flavours/glitch/components/status/handled_link';
|
||||
@ -23,8 +23,19 @@ export const EmbeddedStatusContent: React.FC<{
|
||||
},
|
||||
[mentions],
|
||||
);
|
||||
const hrefToCollection = useCallback(
|
||||
(href: string) => {
|
||||
const collections = status.get('tagged_collections') as List<
|
||||
Map<'url' | 'id', string>
|
||||
>;
|
||||
const collection = collections.find((item) => item.get('url') === href);
|
||||
return collection?.get('id');
|
||||
},
|
||||
[status],
|
||||
);
|
||||
const htmlHandlers = useElementHandledLink({
|
||||
hashtagAccountId: status.get('account') as string | undefined,
|
||||
hrefToCollectionId: hrefToCollection,
|
||||
hrefToMention,
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user