File tree 2 files changed +44
-26
lines changed
2 files changed +44
-26
lines changed Original file line number Diff line number Diff line change @@ -77,13 +77,38 @@ export function HomePageFeedUpdate({
77
77
} )
78
78
} ,
79
79
{
80
- onSuccess : ( ) => {
80
+ onSuccess : ( data , variables , context ) => {
81
81
toast . success ( 'Deleted your update!!' , {
82
82
id : toastId . current ,
83
83
icon : < Trash className = "text-danger-400" /> ,
84
84
} )
85
- queryClient . refetchQueries ( '/api/fauna/all-updates' )
86
- queryClient . refetchQueries ( [ '/api/fauna/recent-updates' , goal . id ] )
85
+
86
+ if ( queryClient . getQueryState ( '/api/fauna/all-updates' ) ) {
87
+ queryClient . setQueryData < { updates : HomePageFeedUpdateType [ ] } > (
88
+ '/api/fauna/all-updates' ,
89
+ ( oldData ) => ( {
90
+ updates : oldData . updates . filter (
91
+ ( _update ) => _update . id !== update . id
92
+ ) ,
93
+ } )
94
+ )
95
+ }
96
+
97
+ if ( queryClient . getQueryState ( [ '/api/fauna/recent-updates' , goal . id ] ) ) {
98
+ queryClient . setQueryData < { response : GoalResponse } > (
99
+ [ '/api/fauna/recent-updates' , goal . id ] ,
100
+ ( oldData ) => ( {
101
+ response : {
102
+ ...oldData . response ,
103
+ updates : {
104
+ data : oldData . response . updates . data . filter (
105
+ ( _update ) => _update . id !== update . id
106
+ ) ,
107
+ } ,
108
+ } ,
109
+ } )
110
+ )
111
+ }
87
112
} ,
88
113
onError : ( ) => {
89
114
toast . error ( 'Something went wrong!!!' , {
Original file line number Diff line number Diff line change @@ -74,28 +74,21 @@ export default function NewUpdate({
74
74
)
75
75
76
76
if ( updateFromHomePage ) {
77
- queryClient . setQueryData < { updates : HomePageFeedUpdateType [ ] } > (
78
- '/api/fauna/all-updates' ,
79
- ( oldData ) => {
80
- if ( ! oldData ) {
81
- return oldData
82
- }
83
- return {
77
+ if ( queryClient . getQueryState ( '/api/fauna/all-updates' ) ) {
78
+ queryClient . setQueryData < { updates : HomePageFeedUpdateType [ ] } > (
79
+ '/api/fauna/all-updates' ,
80
+ ( oldData ) => ( {
84
81
updates : [ data . response , ...oldData . updates ] ,
85
- }
86
- }
87
- )
82
+ } )
83
+ )
84
+ }
88
85
89
- queryClient . setQueryData < { response : GoalResponse } > (
90
- [ '/api/fauna/recent-updates' , goal . id ] ,
91
- ( oldData ) => {
92
- // If the recent-updates panel is not opened yet
93
- // then this oldData will be undefined
94
- // since the corresponsing query is not execcuted even once
95
- if ( ! oldData ) {
96
- return oldData
97
- }
98
- return {
86
+ if (
87
+ queryClient . getQueryState ( [ '/api/fauna/recent-updates' , goal . id ] )
88
+ ) {
89
+ queryClient . setQueryData < { response : GoalResponse } > (
90
+ [ '/api/fauna/recent-updates' , goal . id ] ,
91
+ ( oldData ) => ( {
99
92
response : {
100
93
...oldData . response ,
101
94
updates : {
@@ -110,9 +103,9 @@ export default function NewUpdate({
110
103
] ,
111
104
} ,
112
105
} ,
113
- }
114
- }
115
- )
106
+ } )
107
+ )
108
+ }
116
109
}
117
110
118
111
reset ( )
You can’t perform that action at this time.
0 commit comments