Skip to content

Commit d0b28ad

Browse files
committed
improve jrbowse logic
1 parent 3ee9691 commit d0b28ad

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

front/app/jbrowse/page.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ interface ChromosomeInterface {
2020
}
2121

2222
function JBrowseContent() {
23-
const [accession, setAccession] = useState<string>('')
23+
const [accession, setAccession] = useState<string | null>(null)
2424
const [annotationId, setAnnotationId] = useState<string>('')
2525
const [assembly, setAssembly] = useState<AssemblyRecord | null>(null)
2626
const [annotations, setAnnotations] = useState<AnnotationRecord[]>([])
2727
const [selectedAnnotationId, setSelectedAnnotationId] = useState<string | undefined>()
2828
const [selectedChromosome, setSelectedChromosome] = useState<ChromosomeInterface | null>(null)
2929
const [isDetailsExpanded, setIsDetailsExpanded] = useState(true)
3030
const [isLoading, setIsLoading] = useState(true)
31+
const [isInitialized, setIsInitialized] = useState(false)
3132

3233
// Read URL parameters on client side
3334
useEffect(() => {
@@ -36,11 +37,12 @@ function JBrowseContent() {
3637
const accessionParam = urlParams.get('accession')
3738
const annotationIdParam = urlParams.get('annotationId')
3839

39-
if (accessionParam) setAccession(accessionParam)
40+
setAccession(accessionParam)
4041
if (annotationIdParam) {
4142
setAnnotationId(annotationIdParam)
4243
setSelectedAnnotationId(annotationIdParam)
4344
}
45+
setIsInitialized(true)
4446
}
4547
}, [])
4648

@@ -67,18 +69,28 @@ function JBrowseContent() {
6769
fetchData()
6870
}, [accession])
6971

72+
// Show loading while initializing
73+
if (!isInitialized) {
74+
return (
75+
<div className="min-h-screen flex items-center justify-center">
76+
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary"></div>
77+
</div>
78+
)
79+
}
80+
81+
// Show error only after initialization and if no accession
7082
if (!accession) {
7183
return (
7284
<div className="min-h-screen flex items-center justify-center">
7385
<div className="text-center">
7486
<h1 className="text-2xl font-bold text-red-600 mb-4">Invalid Accession</h1>
7587
<p className="text-gray-600 mb-4">No assembly accession provided in URL parameters.</p>
76-
<a
77-
href="/"
78-
className="inline-flex items-center px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
79-
>
80-
← Back to Home
81-
</a>
88+
<Link href="/">
89+
<Button variant="default" className="gap-2">
90+
<ArrowLeft className="h-4 w-4" />
91+
Back to Home
92+
</Button>
93+
</Link>
8294
</div>
8395
</div>
8496
)

front/components/annotation-actions.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Download, Eye, Activity, MoreVertical, FileText } from "lucide-react"
1313
import { StreamIntervalDialog } from "@/components/stream-interval-dialog"
1414
import { FileOverviewDialog } from "@/components/file-overview-dialog"
1515
import type { Annotation } from "@/lib/types"
16+
import { useRouter } from "next/navigation"
1617

1718
interface AnnotationActionsProps {
1819
annotation: Annotation
@@ -23,9 +24,10 @@ export function AnnotationActions({ annotation, onJBrowseChange }: AnnotationAct
2324
const [streamDialogOpen, setStreamDialogOpen] = useState(false)
2425
const [overviewDialogOpen, setOverviewDialogOpen] = useState(false)
2526
const [downloadDialogOpen, setDownloadDialogOpen] = useState(false)
27+
const router = useRouter()
2628

2729
const handleDownload = () => {
28-
// Create a temporary anchor element to trigger download
30+
// Create a temporary anchor element to trigger download
2931
const link = document.createElement('a')
3032
link.href = `https://genome.crg.es/annotrieve/files/${annotation.indexed_file_info.bgzipped_path}`
3133
link.download = '' // optional: set a filename if needed
@@ -41,7 +43,8 @@ export function AnnotationActions({ annotation, onJBrowseChange }: AnnotationAct
4143
}
4244

4345
const handleViewInBrowser = () => {
44-
onJBrowseChange?.(annotation.assembly_accession, annotation.annotation_id)
46+
// Use URL navigation instead of bubbling up params
47+
router.push(`/jbrowse/?accession=${annotation.assembly_accession}&annotationId=${annotation.annotation_id}`)
4548
}
4649

4750
return (

front/components/assembly-detail-view.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AssemblyRecord } from "@/lib/api/types"
55
import { ChromosomeViewer } from "./chromosome-viewer"
66
import { useState } from "react"
77
import { Button } from "@/components/ui/button"
8+
import { useRouter } from "next/navigation"
89

910
interface AssemblyDetailViewProps {
1011
assemblyDetails: AssemblyRecord
@@ -13,25 +14,27 @@ interface AssemblyDetailViewProps {
1314

1415
export function AssemblyDetailView({ assemblyDetails, onJBrowseChange }: AssemblyDetailViewProps) {
1516
const [showMoreStatistics, setShowMoreStatistics] = useState(false)
17+
const router = useRouter()
1618

1719
const handleDownload = () => {
18-
// Create a temporary anchor element to trigger download
19-
const link = document.createElement('a')
20-
link.href = assemblyDetails.download_url as string
21-
link.download = '' // optional: set a filename if needed
22-
link.target = '_blank' // open in a new tab if preferred
23-
link.rel = 'noopener noreferrer'
20+
// Create a temporary anchor element to trigger download
21+
const link = document.createElement('a')
22+
link.href = assemblyDetails.download_url as string
23+
link.download = '' // optional: set a filename if needed
24+
link.target = '_blank' // open in a new tab if preferred
25+
link.rel = 'noopener noreferrer'
2426

25-
// Append to body and simulate click
26-
document.body.appendChild(link)
27-
link.click()
27+
// Append to body and simulate click
28+
document.body.appendChild(link)
29+
link.click()
2830

29-
// Clean up
30-
document.body.removeChild(link)
31+
// Clean up
32+
document.body.removeChild(link)
3133
}
34+
3235
const handleViewInBrowser = () => {
33-
onJBrowseChange?.(assemblyDetails.assembly_accession)
34-
// In real implementation, this would open the genome browser
36+
// Use URL navigation instead of bubbling up params
37+
router.push(`/jbrowse/?accession=${assemblyDetails.assembly_accession}`)
3538
}
3639

3740
const formatNumber = (num: string | number) => {

0 commit comments

Comments
 (0)