| 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 {ComparisonMode} from './atoms'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {Icon} from 'isl-components/Icon'; |
| b69ab31 | | | 11 | import {useAtomValue} from 'jotai'; |
| b69ab31 | | | 12 | import {lazy, Suspense} from 'react'; |
| b69ab31 | | | 13 | import {ComparisonType} from 'shared/Comparison'; |
| b69ab31 | | | 14 | import {useCommand} from '../ISLShortcuts'; |
| b69ab31 | | | 15 | import {Modal} from '../Modal'; |
| b69ab31 | | | 16 | import {currentComparisonMode, dismissComparison, showComparison} from './atoms'; |
| b69ab31 | | | 17 | |
| b69ab31 | | | 18 | import './ComparisonView.css'; |
| b69ab31 | | | 19 | |
| b69ab31 | | | 20 | const ComparisonView = lazy(() => import('./ComparisonView')); |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | function useComparisonView(): ComparisonMode { |
| b69ab31 | | | 23 | const mode = useAtomValue(currentComparisonMode); |
| b69ab31 | | | 24 | |
| b69ab31 | | | 25 | useCommand('Escape', () => { |
| b69ab31 | | | 26 | dismissComparison(); |
| b69ab31 | | | 27 | }); |
| b69ab31 | | | 28 | useCommand('OpenUncommittedChangesComparisonView', () => { |
| b69ab31 | | | 29 | showComparison({type: ComparisonType.UncommittedChanges}); |
| b69ab31 | | | 30 | }); |
| b69ab31 | | | 31 | useCommand('OpenHeadChangesComparisonView', () => { |
| b69ab31 | | | 32 | showComparison({type: ComparisonType.HeadChanges}); |
| b69ab31 | | | 33 | }); |
| b69ab31 | | | 34 | |
| b69ab31 | | | 35 | return mode; |
| b69ab31 | | | 36 | } |
| b69ab31 | | | 37 | |
| b69ab31 | | | 38 | export function ComparisonViewModal() { |
| b69ab31 | | | 39 | const mode = useComparisonView(); |
| b69ab31 | | | 40 | |
| b69ab31 | | | 41 | if (!mode.visible) { |
| b69ab31 | | | 42 | return null; |
| b69ab31 | | | 43 | } |
| b69ab31 | | | 44 | |
| b69ab31 | | | 45 | return ( |
| b69ab31 | | | 46 | <Modal className="comparison-view-modal" height="" width=""> |
| b69ab31 | | | 47 | <Suspense fallback={<Icon icon="loading" />}> |
| b69ab31 | | | 48 | <ComparisonView comparison={mode.comparison} dismiss={dismissComparison} /> |
| b69ab31 | | | 49 | </Suspense> |
| b69ab31 | | | 50 | </Modal> |
| b69ab31 | | | 51 | ); |
| b69ab31 | | | 52 | } |
| b69ab31 | | | 53 | |
| b69ab31 | | | 54 | export function ComparisonViewApp() { |
| b69ab31 | | | 55 | const mode = useComparisonView(); |
| b69ab31 | | | 56 | |
| b69ab31 | | | 57 | if (!mode.visible) { |
| b69ab31 | | | 58 | return null; |
| b69ab31 | | | 59 | } |
| b69ab31 | | | 60 | |
| b69ab31 | | | 61 | return ( |
| b69ab31 | | | 62 | <div className="comparison-view-root"> |
| b69ab31 | | | 63 | <Suspense fallback={<Icon icon="loading" />}> |
| b69ab31 | | | 64 | <ComparisonView comparison={mode.comparison} /> |
| b69ab31 | | | 65 | </Suspense> |
| b69ab31 | | | 66 | </div> |
| b69ab31 | | | 67 | ); |
| b69ab31 | | | 68 | } |