Bluesky app fork with some witchin' additions 💫

Remove dead code for optimistic updates (#2615)

authored by danabra.mov and committed by

GitHub 7f7b7492 e4622e87

+8 -138
+8 -138
src/state/queries/profile.ts
··· 149 149 if (shouldFollow) { 150 150 const {uri} = await followMutation.mutateAsync({ 151 151 did, 152 - skipOptimistic: true, 153 152 }) 154 153 return uri 155 154 } else { ··· 157 156 await unfollowMutation.mutateAsync({ 158 157 did, 159 158 followUri: prevFollowingUri, 160 - skipOptimistic: true, 161 159 }) 162 160 } 163 161 return undefined ··· 191 189 } 192 190 193 191 function useProfileFollowMutation() { 194 - return useMutation< 195 - {uri: string; cid: string}, 196 - Error, 197 - {did: string; skipOptimistic?: boolean} 198 - >({ 192 + return useMutation<{uri: string; cid: string}, Error, {did: string}>({ 199 193 mutationFn: async ({did}) => { 200 194 return await getAgent().follow(did) 201 195 }, 202 - onMutate(variables) { 203 - if (!variables.skipOptimistic) { 204 - // optimistically update 205 - updateProfileShadow(variables.did, { 206 - followingUri: 'pending', 207 - }) 208 - } 209 - }, 210 196 onSuccess(data, variables) { 211 - if (!variables.skipOptimistic) { 212 - // finalize 213 - updateProfileShadow(variables.did, { 214 - followingUri: data.uri, 215 - }) 216 - track('Profile:Follow', {username: variables.did}) 217 - } 218 - }, 219 - onError(error, variables) { 220 - if (!variables.skipOptimistic) { 221 - // revert the optimistic update 222 - updateProfileShadow(variables.did, { 223 - followingUri: undefined, 224 - }) 225 - } 197 + track('Profile:Follow', {username: variables.did}) 226 198 }, 227 199 }) 228 200 } 229 201 230 202 function useProfileUnfollowMutation() { 231 - return useMutation< 232 - void, 233 - Error, 234 - {did: string; followUri: string; skipOptimistic?: boolean} 235 - >({ 203 + return useMutation<void, Error, {did: string; followUri: string}>({ 236 204 mutationFn: async ({followUri}) => { 237 205 track('Profile:Unfollow', {username: followUri}) 238 206 return await getAgent().deleteFollow(followUri) 239 207 }, 240 - onMutate(variables) { 241 - if (!variables.skipOptimistic) { 242 - // optimistically update 243 - updateProfileShadow(variables.did, { 244 - followingUri: undefined, 245 - }) 246 - } 247 - }, 248 - onError(error, variables) { 249 - if (!variables.skipOptimistic) { 250 - // revert the optimistic update 251 - updateProfileShadow(variables.did, { 252 - followingUri: variables.followUri, 253 - }) 254 - } 255 - }, 256 208 }) 257 209 } 258 210 ··· 270 222 if (shouldMute) { 271 223 await muteMutation.mutateAsync({ 272 224 did, 273 - skipOptimistic: true, 274 225 }) 275 226 return true 276 227 } else { 277 228 await unmuteMutation.mutateAsync({ 278 229 did, 279 - skipOptimistic: true, 280 230 }) 281 231 return false 282 232 } ··· 308 258 309 259 function useProfileMuteMutation() { 310 260 const queryClient = useQueryClient() 311 - return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({ 261 + return useMutation<void, Error, {did: string}>({ 312 262 mutationFn: async ({did}) => { 313 263 await getAgent().mute(did) 314 264 }, 315 - onMutate(variables) { 316 - if (!variables.skipOptimistic) { 317 - // optimistically update 318 - updateProfileShadow(variables.did, { 319 - muted: true, 320 - }) 321 - } 322 - }, 323 265 onSuccess() { 324 266 queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()}) 325 267 }, 326 - onError(error, variables) { 327 - if (!variables.skipOptimistic) { 328 - // revert the optimistic update 329 - updateProfileShadow(variables.did, { 330 - muted: false, 331 - }) 332 - } 333 - }, 334 268 }) 335 269 } 336 270 337 271 function useProfileUnmuteMutation() { 338 272 const queryClient = useQueryClient() 339 - return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({ 273 + return useMutation<void, Error, {did: string}>({ 340 274 mutationFn: async ({did}) => { 341 275 await getAgent().unmute(did) 342 276 }, 343 - onMutate(variables) { 344 - if (!variables.skipOptimistic) { 345 - // optimistically update 346 - updateProfileShadow(variables.did, { 347 - muted: false, 348 - }) 349 - } 350 - }, 351 277 onSuccess() { 352 278 queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()}) 353 - }, 354 - onError(error, variables) { 355 - if (!variables.skipOptimistic) { 356 - // revert the optimistic update 357 - updateProfileShadow(variables.did, { 358 - muted: true, 359 - }) 360 - } 361 279 }, 362 280 }) 363 281 } ··· 376 294 if (shouldFollow) { 377 295 const {uri} = await blockMutation.mutateAsync({ 378 296 did, 379 - skipOptimistic: true, 380 297 }) 381 298 return uri 382 299 } else { ··· 384 301 await unblockMutation.mutateAsync({ 385 302 did, 386 303 blockUri: prevBlockUri, 387 - skipOptimistic: true, 388 304 }) 389 305 } 390 306 return undefined ··· 420 336 function useProfileBlockMutation() { 421 337 const {currentAccount} = useSession() 422 338 const queryClient = useQueryClient() 423 - return useMutation< 424 - {uri: string; cid: string}, 425 - Error, 426 - {did: string; skipOptimistic?: boolean} 427 - >({ 339 + return useMutation<{uri: string; cid: string}, Error, {did: string}>({ 428 340 mutationFn: async ({did}) => { 429 341 if (!currentAccount) { 430 342 throw new Error('Not signed in') ··· 434 346 {subject: did, createdAt: new Date().toISOString()}, 435 347 ) 436 348 }, 437 - onMutate(variables) { 438 - if (!variables.skipOptimistic) { 439 - // optimistically update 440 - updateProfileShadow(variables.did, { 441 - blockingUri: 'pending', 442 - }) 443 - } 444 - }, 445 - onSuccess(data, variables) { 446 - if (!variables.skipOptimistic) { 447 - // finalize 448 - updateProfileShadow(variables.did, { 449 - blockingUri: data.uri, 450 - }) 451 - } 349 + onSuccess() { 452 350 queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()}) 453 351 }, 454 - onError(error, variables) { 455 - if (!variables.skipOptimistic) { 456 - // revert the optimistic update 457 - updateProfileShadow(variables.did, { 458 - blockingUri: undefined, 459 - }) 460 - } 461 - }, 462 352 }) 463 353 } 464 354 465 355 function useProfileUnblockMutation() { 466 356 const {currentAccount} = useSession() 467 - return useMutation< 468 - void, 469 - Error, 470 - {did: string; blockUri: string; skipOptimistic?: boolean} 471 - >({ 357 + return useMutation<void, Error, {did: string; blockUri: string}>({ 472 358 mutationFn: async ({blockUri}) => { 473 359 if (!currentAccount) { 474 360 throw new Error('Not signed in') ··· 478 364 repo: currentAccount.did, 479 365 rkey, 480 366 }) 481 - }, 482 - onMutate(variables) { 483 - if (!variables.skipOptimistic) { 484 - // optimistically update 485 - updateProfileShadow(variables.did, { 486 - blockingUri: undefined, 487 - }) 488 - } 489 - }, 490 - onError(error, variables) { 491 - if (!variables.skipOptimistic) { 492 - // revert the optimistic update 493 - updateProfileShadow(variables.did, { 494 - blockingUri: variables.blockUri, 495 - }) 496 - } 497 367 }, 498 368 }) 499 369 }