addons/isl/src/codeReview/syncStatus.tsxblame
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 type {Hash} from '../types';
b69ab319
b69ab3110import {atom} from 'jotai';
b69ab3111import {latestCommits} from '../serverAPIState';
b69ab3112import {allDiffSummaries, codeReviewProvider} from './CodeReviewInfo';
b69ab3113
b69ab3114export enum SyncStatus {
b69ab3115 InSync = 'inSync',
b69ab3116 LocalIsNewer = 'localIsNewer',
b69ab3117 RemoteIsNewer = 'remoteIsNewer',
b69ab3118 BothChanged = 'bothChanged',
b69ab3119}
b69ab3120
b69ab3121const emptyMap = new Map<Hash, SyncStatus>();
b69ab3122
b69ab3123export const syncStatusAtom = atom(get => {
b69ab3124 const provider = get(codeReviewProvider);
b69ab3125 if (provider == null) {
b69ab3126 return emptyMap;
b69ab3127 }
b69ab3128 const commits = get(latestCommits);
b69ab3129 const summaries = get(allDiffSummaries);
b69ab3130 if (summaries.value == null) {
b69ab3131 return emptyMap;
b69ab3132 }
b69ab3133 return provider.getSyncStatuses(commits, summaries.value);
b69ab3134});