|
1 |
| -import { Button, Spin } from 'antd'; |
2 |
| -import { useEffect, useMemo, useState } from 'react'; |
3 |
| -import { loadable } from 'jotai/utils'; |
4 |
| -import { useAtomValue } from 'jotai'; |
5 |
| - |
6 | 1 | import { NexusImage } from './NexusImage';
|
7 |
| -import ImageViewComponent, { ImageCollection } from './ImageViewComponent'; |
8 |
| -import { ExperimentalTrace } from '@/types/explore-section/delta-experiment'; |
9 |
| -import createImageCollectionDataAtom from '@/components/explore-section/EphysViewerContainer/state/ImageCollectionDataAtom'; |
10 |
| - |
11 |
| -// Only fetch three traces at a time. |
12 |
| -const PAGINATION_OFFSET = 5; |
| 2 | +import ImageViewComponent from './ImageViewComponent'; |
| 3 | +import NWBTrace from './nwb-trace'; |
13 | 4 |
|
14 | 5 | interface ImageViewContainerProps {
|
15 |
| - resource: ExperimentalTrace; |
16 |
| - stimulusTypeMap: Map<string, number>; |
| 6 | + trace: NWBTrace; |
17 | 7 | stimulusType: string;
|
18 | 8 | onStimulusChange: (value: string) => void;
|
19 | 9 | onRepetitionClicked: (stimulusType: string, rep: string) => () => void;
|
20 | 10 | }
|
21 | 11 |
|
22 | 12 | function ImageViewContainer({
|
| 13 | + trace, |
23 | 14 | stimulusType,
|
24 |
| - resource, |
25 |
| - stimulusTypeMap, |
26 | 15 | onRepetitionClicked,
|
27 | 16 | onStimulusChange,
|
28 | 17 | }: ImageViewContainerProps) {
|
29 |
| - const [page, setPage] = useState<number>(0); |
30 |
| - const imageCollectionAtom = useMemo( |
31 |
| - () => loadable(createImageCollectionDataAtom(resource, page, stimulusType, stimulusTypeMap)), |
32 |
| - [page, resource, stimulusType, stimulusTypeMap] |
33 |
| - ); |
34 |
| - const imageCollectionData = useAtomValue(imageCollectionAtom); |
35 |
| - const [localImageCollectionData, setLocalImageCollectionData] = useState<ImageCollection>(); |
36 |
| - |
37 |
| - const isLastPage = useMemo(() => { |
38 |
| - if (stimulusType !== 'All') { |
39 |
| - return true; |
40 |
| - } |
41 |
| - if (imageCollectionData.state === 'hasData' && imageCollectionData.data) { |
42 |
| - const totalStimulus = Array.from(stimulusTypeMap.keys()).length; |
43 |
| - return totalStimulus - page * PAGINATION_OFFSET - PAGINATION_OFFSET <= 0; |
44 |
| - } |
45 |
| - return false; |
46 |
| - }, [page, stimulusType, stimulusTypeMap, imageCollectionData]); |
47 |
| - |
48 |
| - useEffect(() => { |
49 |
| - if (imageCollectionData.state !== 'hasData' || !imageCollectionData.data) return; |
50 |
| - |
51 |
| - setLocalImageCollectionData(imageCollectionData.data); |
52 |
| - }, [imageCollectionData]); |
53 |
| - |
54 |
| - const [projectLabel, orgLabel] = resource._project.split('/').reverse(); |
55 |
| - |
56 | 18 | return (
|
57 | 19 | <>
|
58 |
| - {localImageCollectionData && ( |
59 |
| - <ImageViewComponent |
60 |
| - {...{ |
61 |
| - stimulusTypeMap, |
62 |
| - stimulusType, |
63 |
| - imageCollectionData: localImageCollectionData, |
64 |
| - onStimulusChange, |
65 |
| - onRepetitionClicked, |
66 |
| - // eslint-disable-next-line react/no-unstable-nested-components |
67 |
| - imagePreview: ({ imageUrl }) => ( |
68 |
| - // We need to put this as a prop because it contains effects (container, not component) |
69 |
| - <NexusImage |
70 |
| - {...{ |
71 |
| - imageUrl, |
72 |
| - org: orgLabel, |
73 |
| - project: projectLabel, |
74 |
| - }} |
75 |
| - /> |
76 |
| - ), |
77 |
| - }} |
78 |
| - /> |
79 |
| - )} |
80 |
| - |
81 |
| - {!isLastPage && ( |
82 |
| - <Spin spinning={imageCollectionData.state === 'loading'}> |
83 |
| - <Button |
84 |
| - onClick={() => { |
85 |
| - setPage(page + 1); |
86 |
| - }} |
87 |
| - > |
88 |
| - Load More |
89 |
| - </Button> |
90 |
| - </Spin> |
91 |
| - )} |
| 20 | + <ImageViewComponent |
| 21 | + {...{ |
| 22 | + trace, |
| 23 | + stimulusType, |
| 24 | + onStimulusChange, |
| 25 | + onRepetitionClicked, |
| 26 | + // eslint-disable-next-line react/no-unstable-nested-components |
| 27 | + imagePreview: ({ imageUrl }) => ( |
| 28 | + // We need to put this as a prop because it contains effects (container, not component) |
| 29 | + <NexusImage |
| 30 | + {...{ |
| 31 | + imageUrl, |
| 32 | + org: orgLabel, |
| 33 | + project: projectLabel, |
| 34 | + }} |
| 35 | + /> |
| 36 | + ), |
| 37 | + }} |
| 38 | + /> |
92 | 39 | </>
|
93 | 40 | );
|
94 | 41 | }
|
|
0 commit comments