| 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 {Comparison} from 'shared/Comparison'; |
| 9 | |
| 10 | import {atom} from 'jotai'; |
| 11 | import {ComparisonType} from 'shared/Comparison'; |
| 12 | import {writeAtom} from '../jotaiUtils'; |
| 13 | import platform from '../platform'; |
| 14 | |
| 15 | export type ComparisonMode = {comparison: Comparison; visible: boolean}; |
| 16 | export const currentComparisonMode = atom<ComparisonMode>( |
| 17 | window.islAppMode?.mode === 'comparison' |
| 18 | ? { |
| 19 | comparison: window.islAppMode.comparison, |
| 20 | visible: true, |
| 21 | } |
| 22 | : { |
| 23 | comparison: {type: ComparisonType.UncommittedChanges}, |
| 24 | visible: false, |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | /** Open Comparison View for a given comparison type */ |
| 29 | export async function showComparison(comparison: Comparison) { |
| 30 | if (await platform.openDedicatedComparison?.(comparison)) { |
| 31 | return; |
| 32 | } |
| 33 | writeAtom(currentComparisonMode, {comparison, visible: true}); |
| 34 | } |
| 35 | |
| 36 | export function dismissComparison() { |
| 37 | writeAtom(currentComparisonMode, last => ({...last, visible: false})); |
| 38 | } |
| 39 | |