Contexts: component TypeScript fixes

This commit is contained in:
Alex Gleason 2022-05-13 15:02:20 -05:00
parent 0329cc4d04
commit b80571437a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 12 additions and 9 deletions

View file

@ -11,11 +11,12 @@ interface IThreadStatus {
focusedStatusId: string, focusedStatusId: string,
} }
/** Status with reply-connector in threads. */
const ThreadStatus: React.FC<IThreadStatus> = (props): JSX.Element => { const ThreadStatus: React.FC<IThreadStatus> = (props): JSX.Element => {
const { id, focusedStatusId } = props; const { id, focusedStatusId } = props;
const replyToId = useAppSelector(state => state.contexts.getIn(['inReplyTos', id])); const replyToId = useAppSelector(state => state.contexts.inReplyTos.get(id));
const replyCount = useAppSelector(state => state.contexts.getIn(['replies', id], ImmutableOrderedSet()).size); const replyCount = useAppSelector(state => state.contexts.replies.get(id, ImmutableOrderedSet()).size);
const isLoaded = useAppSelector(state => Boolean(state.statuses.get(id))); const isLoaded = useAppSelector(state => Boolean(state.statuses.get(id)));
const renderConnector = (): JSX.Element | null => { const renderConnector = (): JSX.Element | null => {

View file

@ -97,11 +97,11 @@ const makeMapStateToProps = () => {
const getStatus = makeGetStatus(); const getStatus = makeGetStatus();
const getAncestorsIds = createSelector([ const getAncestorsIds = createSelector([
(_: RootState, statusId: string) => statusId, (_: RootState, statusId: string | undefined) => statusId,
(state: RootState) => state.contexts.get('inReplyTos'), (state: RootState) => state.contexts.inReplyTos,
], (statusId, inReplyTos) => { ], (statusId, inReplyTos) => {
let ancestorsIds = ImmutableOrderedSet(); let ancestorsIds = ImmutableOrderedSet<string>();
let id = statusId; let id: string | undefined = statusId;
while (id && !ancestorsIds.includes(id)) { while (id && !ancestorsIds.includes(id)) {
ancestorsIds = ImmutableOrderedSet([id]).union(ancestorsIds); ancestorsIds = ImmutableOrderedSet([id]).union(ancestorsIds);
@ -113,13 +113,15 @@ const makeMapStateToProps = () => {
const getDescendantsIds = createSelector([ const getDescendantsIds = createSelector([
(_: RootState, statusId: string) => statusId, (_: RootState, statusId: string) => statusId,
(state: RootState) => state.contexts.get('replies'), (state: RootState) => state.contexts.replies,
], (statusId, contextReplies) => { ], (statusId, contextReplies) => {
let descendantsIds = ImmutableOrderedSet(); let descendantsIds = ImmutableOrderedSet();
const ids = [statusId]; const ids = [statusId];
while (ids.length > 0) { while (ids.length > 0) {
const id = ids.shift(); const id = ids.shift();
if (!id) break;
const replies = contextReplies.get(id); const replies = contextReplies.get(id);
if (descendantsIds.includes(id)) { if (descendantsIds.includes(id)) {
@ -147,7 +149,7 @@ const makeMapStateToProps = () => {
if (status) { if (status) {
const statusId = status.id; const statusId = status.id;
ancestorsIds = getAncestorsIds(state, state.contexts.getIn(['inReplyTos', statusId])); ancestorsIds = getAncestorsIds(state, state.contexts.inReplyTos.get(statusId));
descendantsIds = getDescendantsIds(state, statusId); descendantsIds = getDescendantsIds(state, statusId);
ancestorsIds = ancestorsIds.delete(statusId).subtract(descendantsIds); ancestorsIds = ancestorsIds.delete(statusId).subtract(descendantsIds);
descendantsIds = descendantsIds.delete(statusId).subtract(ancestorsIds); descendantsIds = descendantsIds.delete(statusId).subtract(ancestorsIds);