| 54 | const getProjectsPosts = apiClient.organizations.getProjectsPosts() |
| 55 | |
| 56 | const updatePageQueryData = (newComment: Comment) => (old: InfiniteData<CommentPage> | undefined) => { |
| 57 | if (!old) { |
| 58 | // if there was no page, insert a new one so comment lists update immediately |
| 59 | return { |
| 60 | pageParams: [], |
| 61 | pages: [ |
| 62 | { |
| 63 | data: [newComment], |
| 64 | total_count: 1 |
| 65 | } |
| 66 | ] |
| 67 | } |
| 68 | } else { |
| 69 | // insert the new comment at the top of the first page |
| 70 | const [firstPage, ...rest] = old.pages |
| 71 | |
| 72 | return { |
| 73 | ...old, |
| 74 | pages: [ |
| 75 | { |
| 76 | ...firstPage, |
| 77 | data: [newComment, ...firstPage.data] |
| 78 | }, |
| 79 | ...rest |
| 80 | ] |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | function replaceOptimisticComments(optimisticId: string, comments: Comment[], serverComment: Comment): Comment[] { |
| 86 | return comments.map((comment) => { |