addons/isl/src/codeReview/codeReviewAtoms.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import serverAPI from '../ClientToServerAPI';
b69ab319import {atomFamilyWeak, atomLoadableWithRefresh} from '../jotaiUtils';
b69ab3110import type {DiffId} from '../types';
b69ab3111
b69ab3112export const diffCommentData = atomFamilyWeak((diffId: DiffId) =>
b69ab3113 atomLoadableWithRefresh(async () => {
b69ab3114 serverAPI.postMessage({
b69ab3115 type: 'fetchDiffComments',
b69ab3116 diffId,
b69ab3117 });
b69ab3118
b69ab3119 const result = await serverAPI.nextMessageMatching(
b69ab3120 'fetchedDiffComments',
b69ab3121 msg => msg.diffId === diffId,
b69ab3122 );
b69ab3123 if (result.comments.error != null) {
b69ab3124 throw new Error(result.comments.error.toString());
b69ab3125 }
b69ab3126 return result.comments.value;
b69ab3127 }),
b69ab3128);