File tree Expand file tree Collapse file tree
packages/shared/src/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type {
1010 TranslateablePostField ,
1111} from '../../graphql/posts' ;
1212import { PostType } from '../../graphql/posts' ;
13+ import { getFeedApiItemPost } from '../../graphql/feed' ;
1314import {
1415 updateCachedPagePost ,
1516 findIndexOfPostInData ,
@@ -173,11 +174,19 @@ export const useTranslation: UseTranslation = ({
173174 true ,
174175 ) ;
175176 if ( index > - 1 ) {
177+ const post = getFeedApiItemPost (
178+ feedData . pages [ pageIndex ] . page . edges [ index ] . node ,
179+ ) ;
180+
181+ if ( ! post ) {
182+ return ;
183+ }
184+
176185 updatePost (
177186 pageIndex ,
178187 index ,
179188 updateTranslation ( {
180- post : feedData . pages [ pageIndex ] . page . edges [ index ] . node ,
189+ post,
181190 translation : translatedPost ,
182191 } ) ,
183192 ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
22import type { InfiniteData } from '@tanstack/react-query' ;
33import { useMutation , useQueryClient } from '@tanstack/react-query' ;
44import type { Ad , FeedData , Post } from '../graphql/posts' ;
5+ import { getFeedApiItemPost } from '../graphql/feed' ;
56import { votePoll } from '../graphql/posts' ;
67import {
78 findIndexOfPostInData ,
@@ -67,12 +68,16 @@ const usePoll = ({ post }: { post: Post }) => {
6768 ) ;
6869
6970 if ( pageIndex > - 1 && index > - 1 ) {
70- const currentPost = feedData . pages [ pageIndex ] . page . edges [ index ] . node ;
71- const updatedPost = {
72- ...currentPost ,
73- ...postUpdate ,
74- } ;
75- updateFeed ( pageIndex , index , updatedPost ) ;
71+ const currentPost = getFeedApiItemPost (
72+ feedData . pages [ pageIndex ] . page . edges [ index ] . node ,
73+ ) ;
74+
75+ if ( currentPost ) {
76+ updateFeed ( pageIndex , index , {
77+ ...currentPost ,
78+ ...postUpdate ,
79+ } ) ;
80+ }
7681 }
7782 }
7883
You can’t perform that action at this time.
0 commit comments