statuses links
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
1805dec968
commit
724fe8b765
3 changed files with 26 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
import api from '../api';
|
||||
|
||||
import { importFetchedStatuses } from './importer';
|
||||
|
||||
import type { AxiosError } from 'axios';
|
||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||
import type { APIEntity } from 'soapbox/types/entities';
|
||||
|
@ -34,6 +36,7 @@ export const fetchAnnouncements = (done = noOp) =>
|
|||
|
||||
return api(getState).get('/api/v1/announcements').then(response => {
|
||||
dispatch(fetchAnnouncementsSuccess(response.data));
|
||||
dispatch(importFetchedStatuses(response.data.map(({ statuses }: APIEntity) => statuses)));
|
||||
}).catch(error => {
|
||||
dispatch(fetchAnnouncementsFail(error));
|
||||
}).finally(() => {
|
||||
|
|
|
@ -34,12 +34,12 @@ const AnnouncementContent: React.FC<IAnnouncementContent> = ({ announcement }) =
|
|||
}
|
||||
};
|
||||
|
||||
// const onStatusClick = (status, e: MouseEvent) => {
|
||||
// if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
||||
// e.preventDefault();
|
||||
// history.push(`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`);
|
||||
// }
|
||||
// };
|
||||
const onStatusClick = (status: string, e: MouseEvent) => {
|
||||
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault();
|
||||
history.push(status);
|
||||
}
|
||||
};
|
||||
|
||||
const updateLinks = () => {
|
||||
if (!node.current) return;
|
||||
|
@ -63,13 +63,13 @@ const AnnouncementContent: React.FC<IAnnouncementContent> = ({ announcement }) =
|
|||
link.setAttribute('title', mention.acct);
|
||||
} else if (link.textContent?.charAt(0) === '#' || (link.previousSibling?.textContent?.charAt(link.previousSibling.textContent.length - 1) === '#')) {
|
||||
link.addEventListener('click', onHashtagClick.bind(link, link.text), false);
|
||||
// } else {
|
||||
// const status = announcement.statuses.find(item => link.href === item.get('url'));
|
||||
// if (status) {
|
||||
// link.addEventListener('click', onStatusClick.bind(this, status), false);
|
||||
// }
|
||||
// link.setAttribute('title', link.href);
|
||||
// link.classList.add('unhandled-link');
|
||||
} else {
|
||||
const status = announcement.statuses.get(link.href);
|
||||
if (status) {
|
||||
link.addEventListener('click', onStatusClick.bind(this, status), false);
|
||||
}
|
||||
link.setAttribute('title', link.href);
|
||||
link.classList.add('unhandled-link');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ export const AnnouncementRecord = ImmutableRecord({
|
|||
read: false,
|
||||
published_at: Date,
|
||||
reactions: ImmutableList<AnnouncementReaction>(),
|
||||
// statuses,
|
||||
statuses: ImmutableMap<string, string>(),
|
||||
mentions: ImmutableList<Mention>(),
|
||||
tags: ImmutableList<ImmutableMap<string, any>>(),
|
||||
emojis: ImmutableList<Emoji>(),
|
||||
|
@ -66,6 +66,14 @@ const normalizeContent = (announcement: ImmutableMap<string, any>) => {
|
|||
return announcement.set('contentHtml', contentHtml);
|
||||
};
|
||||
|
||||
const normalizeStatuses = (announcement: ImmutableMap<string, any>) => {
|
||||
const statuses = announcement
|
||||
.get('statuses', ImmutableList())
|
||||
.reduce((acc: ImmutableMap<string, string>, curr: ImmutableMap<string, any>) => acc.set(curr.get('url'), `/@${curr.getIn(['account', 'acct'])}/${curr.get('id')}`), ImmutableMap());
|
||||
|
||||
return announcement.set('statuses', statuses);
|
||||
};
|
||||
|
||||
export const normalizeAnnouncement = (announcement: Record<string, any>) => {
|
||||
return AnnouncementRecord(
|
||||
ImmutableMap(fromJS(announcement)).withMutations(announcement => {
|
||||
|
@ -73,6 +81,7 @@ export const normalizeAnnouncement = (announcement: Record<string, any>) => {
|
|||
normalizeReactions(announcement);
|
||||
normalizeEmojis(announcement);
|
||||
normalizeContent(announcement);
|
||||
normalizeStatuses(announcement);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue