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.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. import {useCallback, useContext, useMemo} from 'react';
    
  12. import {SettingsModalContext} from './SettingsModalContext';
    
  13. import Button from '../Button';
    
  14. import ButtonIcon from '../ButtonIcon';
    
  15. import {StoreContext} from '../context';
    
  16. import {useSubscription} from '../hooks';
    
  17. 
    
  18. export default function SettingsModalContextToggle(): React.Node {
    
  19.   const {setIsModalShowing} = useContext(SettingsModalContext);
    
  20.   const store = useContext(StoreContext);
    
  21.   const {profilerStore} = store;
    
  22. 
    
  23.   const showFilterModal = useCallback(
    
  24.     () => setIsModalShowing(true),
    
  25.     [setIsModalShowing],
    
  26.   );
    
  27. 
    
  28.   // Updating preferences while profiling is in progress could break things (e.g. filtering)
    
  29.   // Explicitly disallow it for now.
    
  30.   const isProfilingSubscription = useMemo(
    
  31.     () => ({
    
  32.       getCurrentValue: () => profilerStore.isProfiling,
    
  33.       subscribe: (callback: Function) => {
    
  34.         profilerStore.addListener('isProfiling', callback);
    
  35.         return () => profilerStore.removeListener('isProfiling', callback);
    
  36.       },
    
  37.     }),
    
  38.     [profilerStore],
    
  39.   );
    
  40.   const isProfiling = useSubscription<boolean>(isProfilingSubscription);
    
  41. 
    
  42.   return (
    
  43.     <Button
    
  44.       disabled={isProfiling}
    
  45.       onClick={showFilterModal}
    
  46.       title="View settings">
    
  47.       <ButtonIcon type="settings" />
    
  48.     </Button>
    
  49.   );
    
  50. }