( build: WorkspaceBuild, queryClient: QueryClient, )
| 417 | }; |
| 418 | |
| 419 | const updateWorkspaceBuild = async ( |
| 420 | build: WorkspaceBuild, |
| 421 | queryClient: QueryClient, |
| 422 | ) => { |
| 423 | const workspaceKey = workspaceByOwnerAndNameKey( |
| 424 | build.workspace_owner_name, |
| 425 | build.workspace_name, |
| 426 | ); |
| 427 | const previousData = queryClient.getQueryData<Workspace>(workspaceKey); |
| 428 | if (!previousData) { |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | // Check if the build returned is newer than the previous build that could be |
| 433 | // updated from web socket |
| 434 | const previousUpdate = new Date(previousData.latest_build.updated_at); |
| 435 | const newestUpdate = new Date(build.updated_at); |
| 436 | if (newestUpdate > previousUpdate) { |
| 437 | queryClient.setQueryData(workspaceKey, { |
| 438 | ...previousData, |
| 439 | latest_build: build, |
| 440 | }); |
| 441 | } |
| 442 | |
| 443 | await queryClient.invalidateQueries({ |
| 444 | queryKey: workspaceBuildsKey(build.workspace_id), |
| 445 | }); |
| 446 | }; |
| 447 | |
| 448 | export const toggleFavorite = ( |
| 449 | workspace: Workspace, |
no test coverage detected