916 B35 lines
Blame
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
8import type {Hash} from '../types';
9
10import {atom} from 'jotai';
11import {latestCommits} from '../serverAPIState';
12import {allDiffSummaries, codeReviewProvider} from './CodeReviewInfo';
13
14export enum SyncStatus {
15 InSync = 'inSync',
16 LocalIsNewer = 'localIsNewer',
17 RemoteIsNewer = 'remoteIsNewer',
18 BothChanged = 'bothChanged',
19}
20
21const emptyMap = new Map<Hash, SyncStatus>();
22
23export const syncStatusAtom = atom(get => {
24 const provider = get(codeReviewProvider);
25 if (provider == null) {
26 return emptyMap;
27 }
28 const commits = get(latestCommits);
29 const summaries = get(allDiffSummaries);
30 if (summaries.value == null) {
31 return emptyMap;
32 }
33 return provider.getSyncStatuses(commits, summaries.value);
34});
35