| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import serverAPI from '../ClientToServerAPI'; |
| 9 | import {atomFamilyWeak, atomLoadableWithRefresh} from '../jotaiUtils'; |
| 10 | import type {DiffId} from '../types'; |
| 11 | |
| 12 | export const diffCommentData = atomFamilyWeak((diffId: DiffId) => |
| 13 | atomLoadableWithRefresh(async () => { |
| 14 | serverAPI.postMessage({ |
| 15 | type: 'fetchDiffComments', |
| 16 | diffId, |
| 17 | }); |
| 18 | |
| 19 | const result = await serverAPI.nextMessageMatching( |
| 20 | 'fetchedDiffComments', |
| 21 | msg => msg.diffId === diffId, |
| 22 | ); |
| 23 | if (result.comments.error != null) { |
| 24 | throw new Error(result.comments.error.toString()); |
| 25 | } |
| 26 | return result.comments.value; |
| 27 | }), |
| 28 | ); |
| 29 | |