| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {Hash} from '../types'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {atom} from 'jotai'; |
| b69ab31 | | | 11 | import {latestCommits} from '../serverAPIState'; |
| b69ab31 | | | 12 | import {allDiffSummaries, codeReviewProvider} from './CodeReviewInfo'; |
| b69ab31 | | | 13 | |
| b69ab31 | | | 14 | export enum SyncStatus { |
| b69ab31 | | | 15 | InSync = 'inSync', |
| b69ab31 | | | 16 | LocalIsNewer = 'localIsNewer', |
| b69ab31 | | | 17 | RemoteIsNewer = 'remoteIsNewer', |
| b69ab31 | | | 18 | BothChanged = 'bothChanged', |
| b69ab31 | | | 19 | } |
| b69ab31 | | | 20 | |
| b69ab31 | | | 21 | const emptyMap = new Map<Hash, SyncStatus>(); |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | export const syncStatusAtom = atom(get => { |
| b69ab31 | | | 24 | const provider = get(codeReviewProvider); |
| b69ab31 | | | 25 | if (provider == null) { |
| b69ab31 | | | 26 | return emptyMap; |
| b69ab31 | | | 27 | } |
| b69ab31 | | | 28 | const commits = get(latestCommits); |
| b69ab31 | | | 29 | const summaries = get(allDiffSummaries); |
| b69ab31 | | | 30 | if (summaries.value == null) { |
| b69ab31 | | | 31 | return emptyMap; |
| b69ab31 | | | 32 | } |
| b69ab31 | | | 33 | return provider.getSyncStatuses(commits, summaries.value); |
| b69ab31 | | | 34 | }); |