1
1
import React from "react" ;
2
2
import { Button , Dropdown , Space , message , MenuProps } from "antd" ;
3
3
import { DownOutlined } from "@ant-design/icons" ;
4
- import { useCallback , useMemo , useState } from "react" ;
4
+ import { useCallback , useMemo } from "react" ;
5
5
import useAppStore from "../store/store" ;
6
6
import { shallow } from "zustand/shallow" ;
7
7
import { useStoreWithEqualityFn } from "zustand/traditional" ;
8
8
9
- const SampleDropdown = React . memo ( function SampleDropdown ( {
9
+ const SampleDropdown = function SampleDropdown ( {
10
10
setLoading,
11
11
} : {
12
12
setLoading : React . Dispatch < React . SetStateAction < boolean > > ;
13
13
} ) : JSX . Element {
14
- const { samples, loadSample } = useStoreWithEqualityFn (
14
+ const { samples, loadSample, sampleName } = useStoreWithEqualityFn (
15
15
useAppStore ,
16
16
( state ) => ( {
17
17
samples : state . samples ,
18
18
loadSample : state . loadSample as ( key : string ) => Promise < void > ,
19
+ sampleName : state . sampleName
19
20
} ) ,
20
21
shallow
21
22
) ;
22
23
23
- const [ selectedSample , setSelectedSample ] = useState < string | null > ( null ) ;
24
+
24
25
25
26
const items : MenuProps [ "items" ] = useMemo (
26
27
( ) =>
@@ -38,7 +39,7 @@ const SampleDropdown = React.memo(function SampleDropdown({
38
39
try {
39
40
await loadSample ( e . key ) ;
40
41
void message . info ( `Loaded ${ e . key } sample` ) ;
41
- setSelectedSample ( e . key ) ;
42
+
42
43
} catch ( error ) {
43
44
void message . error ( "Failed to load sample" ) ;
44
45
} finally {
@@ -55,11 +56,11 @@ const SampleDropdown = React.memo(function SampleDropdown({
55
56
< Dropdown menu = { { items, onClick : ( e ) => void handleMenuClick ( e ) } } trigger = { [ "click" ] } >
56
57
< div className = "samples-element" >
57
58
< Button aria-label = "Load sample dropdown" >
58
- { selectedSample ? selectedSample : "Load Sample" } < DownOutlined />
59
+ { sampleName || "Load Sample" } < DownOutlined />
59
60
</ Button >
60
61
</ div >
61
62
</ Dropdown >
62
63
</ Space >
63
64
) ;
64
- } )
65
+ }
65
66
export default SampleDropdown ;
0 commit comments