| 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 type {Hash} from '../types'; |
| 9 | |
| 10 | import {atom} from 'jotai'; |
| 11 | import {latestCommits} from '../serverAPIState'; |
| 12 | import {allDiffSummaries, codeReviewProvider} from './CodeReviewInfo'; |
| 13 | |
| 14 | export enum SyncStatus { |
| 15 | InSync = 'inSync', |
| 16 | LocalIsNewer = 'localIsNewer', |
| 17 | RemoteIsNewer = 'remoteIsNewer', |
| 18 | BothChanged = 'bothChanged', |
| 19 | } |
| 20 | |
| 21 | const emptyMap = new Map<Hash, SyncStatus>(); |
| 22 | |
| 23 | export 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 | |