Skip to content

Commit 1de97b2

Browse files
committed
Fix bug - Feed was not updating properly when an update is edited. Seeing duplicate updates
1 parent 56202c8 commit 1de97b2

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/components/goals/EditUpdate.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ export default function EditUpdate({
6363
return oldData.map((goalResponse) => {
6464
if (goalResponse.id === goalId) {
6565
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+
}),
7577
}
7678
}
7779
return goalResponse
@@ -84,7 +86,12 @@ export default function EditUpdate({
8486
queryClient.setQueryData<{ updates: HomePageFeedUpdateType[] }>(
8587
'/api/fauna/all-updates',
8688
(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+
}),
8895
})
8996
)
9097
}
@@ -98,15 +105,17 @@ export default function EditUpdate({
98105
response: {
99106
...oldData.response,
100107
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+
}),
110119
},
111120
},
112121
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy