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