1
1
import { addLogMessageAtom } from "@/state/log"
2
2
import { osmWorkerAtom } from "@/state/worker"
3
3
import * as Comlink from "comlink"
4
- import { useAtomValue , useSetAtom } from "jotai"
4
+ import { useAtom , useAtomValue , useSetAtom } from "jotai"
5
5
import { Osm } from "osm.ts"
6
6
import { useEffect , useMemo , useState } from "react"
7
7
import useStartTask from "./log"
8
8
import { useFitBoundsOnChange } from "./map"
9
+ import { osmAtomFamily } from "@/state/osm"
9
10
10
11
export function useOsmWorker ( ) {
11
12
const osmWorker = useAtomValue ( osmWorkerAtom )
@@ -20,8 +21,8 @@ export function useOsmWorker() {
20
21
return osmWorker
21
22
}
22
23
23
- export function useOsmFile ( file : File | null , id ?: string ) {
24
- const [ osm , setOsm ] = useState < Osm | null > ( null )
24
+ export function useOsmFile ( id : string , file : File | null ) {
25
+ const [ osm , setOsm ] = useAtom ( osmAtomFamily ( id ) )
25
26
const [ isLoading , setIsLoading ] = useState ( false )
26
27
const osmWorker = useOsmWorker ( )
27
28
const startTask = useStartTask ( )
@@ -49,7 +50,7 @@ export function useOsmFile(file: File | null, id?: string) {
49
50
. finally ( ( ) => {
50
51
setIsLoading ( false )
51
52
} )
52
- } , [ file , id , osmWorker , startTask ] )
53
+ } , [ file , id , osmWorker , setOsm , startTask ] )
53
54
54
55
return { osm, setOsm, isLoading }
55
56
}
0 commit comments