Skip to content

Commit

Permalink
added chromosome viewer to routed views
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw committed Oct 17, 2024
1 parent f7b7ead commit 9e0b738
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
20 changes: 18 additions & 2 deletions Eplant/views/ChromosomeViewer/ChromosomeView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { debounce } from 'lodash'
import { useOutletContext, useSearchParams } from 'react-router-dom'
import { Space } from 'react-zoomable-ui'

import GeneticElement from '@eplant/GeneticElement'
import { ViewContext } from '@eplant/UI/Layout/ViewContainer/types'
import { flattenState } from '@eplant/util/router'
import { Box, CircularProgress, Snackbar, SnackbarContent } from '@mui/material'
import { useQuery } from '@tanstack/react-query'

Expand All @@ -26,7 +28,7 @@ export const ChromosomeView = () => {
setMessageOpen(false)
}
const { data, isLoading, isError, error } = useQuery<ChromosomeViewerData>({
queryKey: [`chromosome-${geneticElement?.id}`],
queryKey: [`chromosome`],
queryFn: async () => {
if (!geneticElement) {
throw Error('No gene')
Expand All @@ -45,6 +47,20 @@ export const ChromosomeView = () => {
},
})

const debouncedUpdateSearchParams = useCallback(
debounce((updatedState) => {
setSearchParams(new URLSearchParams(flattenState(updatedState)))
}, 200), // 200ms delay before updating the URL
[setSearchParams]
)

useEffect(() => {
debouncedUpdateSearchParams(viewState)
return () => {
debouncedUpdateSearchParams.cancel()
}
}, [viewState, debouncedUpdateSearchParams])

if (isLoading || isError || !data) return <></>
return (
<Box>
Expand Down
1 change: 0 additions & 1 deletion Eplant/views/ChromosomeViewer/Viewer/GeneList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ListItemIcon from '@mui/material/ListItemIcon'
import ListItemText from '@mui/material/ListItemText'
import useTheme from '@mui/material/styles/useTheme'

import { GeneIcon } from '../icons'
import { GeneItem } from '../types'

import GeneInfoPopup from './GeneInfoPopup'
Expand Down
1 change: 0 additions & 1 deletion Eplant/views/ChromosomeViewer/Viewer/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface ViewerProps {
// COMPONENT
//----------
const ChromosomeViewer = ({ chromosomes, scale }: ViewerProps) => {
console.log(chromosomes)
return (
<div
style={{
Expand Down

0 comments on commit 9e0b738

Please sign in to comment.