@@ -63,15 +63,17 @@ export default function EditUpdate({
63
63
return oldData . map ( ( goalResponse ) => {
64
64
if ( goalResponse . id === goalId ) {
65
65
goalResponse . updates = {
66
- data : [
67
- ...goalResponse . updates . data ,
68
- {
69
- id : data . id ,
70
- description : data . description ,
71
- createdAt : data . createdAt ,
72
- postedBy : data . postedBy ,
73
- } ,
74
- ] ,
66
+ data : goalResponse . updates . data . map ( ( _update ) => {
67
+ if ( _update . id === update . id ) {
68
+ _update = {
69
+ id : data . id ,
70
+ description : data . description ,
71
+ createdAt : data . createdAt ,
72
+ postedBy : data . postedBy ,
73
+ }
74
+ }
75
+ return _update
76
+ } ) ,
75
77
}
76
78
}
77
79
return goalResponse
@@ -84,7 +86,12 @@ export default function EditUpdate({
84
86
queryClient . setQueryData < { updates : HomePageFeedUpdateType [ ] } > (
85
87
'/api/fauna/all-updates' ,
86
88
( oldData ) => ( {
87
- updates : [ data , ...oldData . updates ] ,
89
+ updates : oldData . updates . map ( ( _update ) => {
90
+ if ( _update . id === update . id ) {
91
+ _update = data
92
+ }
93
+ return _update
94
+ } ) ,
88
95
} )
89
96
)
90
97
}
@@ -98,15 +105,17 @@ export default function EditUpdate({
98
105
response : {
99
106
...oldData . response ,
100
107
updates : {
101
- data : [
102
- ...oldData . response . updates . data ,
103
- {
104
- id : data . id ,
105
- description : data . description ,
106
- createdAt : data . createdAt ,
107
- postedBy : data . postedBy ,
108
- } ,
109
- ] ,
108
+ data : oldData . response . updates . data . map ( ( _update ) => {
109
+ if ( _update . id === update . id ) {
110
+ _update = {
111
+ id : data . id ,
112
+ description : data . description ,
113
+ createdAt : data . createdAt ,
114
+ postedBy : data . postedBy ,
115
+ }
116
+ }
117
+ return _update
118
+ } ) ,
110
119
} ,
111
120
} ,
112
121
} )
0 commit comments