1- import React , { useEffect , useState } from 'react'
1+ import React , { useState } from 'react'
22
33import { Dialog , ErrorMessage , LoadingEllipses } from '@jbrowse/core/ui'
44import { getSession } from '@jbrowse/core/util'
5- import { Button , DialogActions , DialogContent , TextField } from '@mui/material'
5+ import {
6+ Button ,
7+ DialogActions ,
8+ DialogContent ,
9+ TextField ,
10+ ToggleButton ,
11+ ToggleButtonGroup ,
12+ Typography ,
13+ } from '@mui/material'
614import { observer } from 'mobx-react'
715import { makeStyles } from 'tss-react/mui'
816
9- import { fetchSequences } from '../../../util/fetchSequences'
17+ import { useSequences } from '../../../util/useSequences'
18+
1019import type { LinearMafDisplayModel } from '../../stateModel'
1120
1221const useStyles = makeStyles ( ) ( {
1322 dialogContent : {
1423 width : '80em' ,
1524 } ,
1625 textAreaInput : {
17- fontFamily : 'Courier New ' ,
26+ fontFamily : 'monospace ' ,
1827 whiteSpace : 'pre' ,
1928 overflowX : 'auto' ,
2029 } ,
@@ -23,7 +32,7 @@ const useStyles = makeStyles()({
2332 } ,
2433} )
2534
26- const SequenceDialog = observer ( function ( {
35+ const GetSequenceDialog = observer ( function ( {
2736 onClose,
2837 model,
2938 selectionCoords,
@@ -35,37 +44,40 @@ const SequenceDialog = observer(function ({
3544 dragEndX : number
3645 }
3746} ) {
38- const [ sequence , setSequence ] = useState < string > ( '' )
39- const [ loading , setLoading ] = useState ( true )
40- const [ error , setError ] = useState < unknown > ( )
41- const sequenceTooLarge = sequence ? sequence . length > 1_000_000 : false
47+ const [ showAllLetters , setShowAllLetters ] = useState ( true )
4248 const { classes } = useStyles ( )
43-
44- useEffect ( ( ) => {
45- // eslint-disable-next-line @typescript-eslint/no-floating-promises
46- ; ( async ( ) => {
47- if ( ! selectionCoords ) {
48- setLoading ( false )
49- return
50- }
51-
52- try {
53- setLoading ( true )
54- setError ( undefined )
55-
56- setSequence ( await fetchSequences ( { model, selectionCoords } ) )
57- } catch ( e ) {
58- console . error ( e )
59- setError ( e )
60- } finally {
61- setLoading ( false )
62- }
63- } ) ( )
64- } , [ model , selectionCoords ] )
49+ const { sequence, loading, error } = useSequences ( {
50+ model,
51+ selectionCoords,
52+ showAllLetters,
53+ } )
54+ const sequenceTooLarge = sequence ? sequence . length > 1_000_000 : false
6555
6656 return (
6757 < Dialog open onClose = { onClose } title = "Subsequence Data" maxWidth = "xl" >
6858 < DialogContent >
59+ < div
60+ style = { {
61+ display : 'flex' ,
62+ alignItems : 'center' ,
63+ marginBottom : '16px' ,
64+ } }
65+ >
66+ < ToggleButtonGroup
67+ value = { showAllLetters }
68+ exclusive
69+ size = "small"
70+ onChange = { ( _event , newDisplayMode ) => {
71+ if ( newDisplayMode !== null ) {
72+ setShowAllLetters ( newDisplayMode )
73+ }
74+ } }
75+ >
76+ < ToggleButton value = { true } > Show All Letters</ ToggleButton >
77+ < ToggleButton value = { false } > Show Only Differences</ ToggleButton >
78+ </ ToggleButtonGroup >
79+ </ div >
80+
6981 { error ? (
7082 < ErrorMessage error = { error } />
7183 ) : (
@@ -156,4 +168,4 @@ const SequenceDialog = observer(function ({
156168 )
157169} )
158170
159- export default SequenceDialog
171+ export default GetSequenceDialog
0 commit comments