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