@@ -10,22 +10,24 @@ import './dictionary.css';
1010import Search from 'antd/es/input/Search' ;
1111import { Button } from 'antd' ;
1212import { CloseOutlined , DownloadOutlined } from '@ant-design/icons' ;
13- import { includes as lodashIncludes , filter as lodashFilter } from 'lodash' ;
13+ import { includes as lodashIncludes , filter as lodashFilter , lowerCase } from 'lodash' ;
1414const DictionaryPage = ( ) => {
1515 const [ keywords , setKeywords ] = useState ( '' ) ;
1616 const [ isLoading , setIsloading ] = useState ( false ) ;
1717 const contentRef = useRef < HTMLDivElement > ( null ) ;
1818
1919 const handleSearch = async ( ) => {
2020 setIsloading ( true ) ;
21+ const _key = lowerCase ( keywords ) . trim ( ) ;
2122 contentRef . current && ( contentRef . current . innerHTML = 'loading' ) ;
22- const dt = await getDbStorage ( keywords ) ;
23+ const dt = await getDbStorage ( _key ) ;
2324 if ( dt && dt !== 'None' ) {
2425 contentRef . current && ( contentRef . current . innerHTML = dt ) ;
26+ setIsloading ( false ) ;
2527 return ;
2628 }
2729
28- const steamUrl = `https://dictionary.cambridge.org/dictionary/english-vietnamese/${ keywords } ` ;
30+ const steamUrl = `https://dictionary.cambridge.org/dictionary/english-vietnamese/${ _key } ` ;
2931 const html = await fetch < string > ( steamUrl , {
3032 method : 'GET' ,
3133 responseType : ResponseType . Text ,
@@ -34,7 +36,7 @@ const DictionaryPage = () => {
3436 const dic = $ ( '.entry-body' ) . html ( ) || '' ;
3537 if ( dic ) {
3638 contentRef . current && ( contentRef . current . innerHTML = $ ( '.entry-body' ) . html ( ) || '' ) ;
37- await setDbStorage ( keywords , $ ( '.entry-body' ) . html ( ) || '' ) ;
39+ await setDbStorage ( _key , $ ( '.entry-body' ) . html ( ) || '' ) ;
3840 } else {
3941 contentRef . current && ( contentRef . current . innerHTML = 'Not found' ) ;
4042 }
@@ -48,7 +50,6 @@ const DictionaryPage = () => {
4850 if ( isLoading ) return ;
4951 ( async ( ) => {
5052 const keys = await getAllDbKeys ( ) ;
51- console . log ( '🚀 ~ file: index.tsx:44 ~ keys:' , keys ) ;
5253 setDbKeys ( keys ) ;
5354 setSearchKey ( keys ) ;
5455 } ) ( ) ;
@@ -85,7 +86,6 @@ const DictionaryPage = () => {
8586 < div className = "flex w-[300px] flex-col space-y-3 px-3" >
8687 < Search
8788 placeholder = "Search..."
88- loading = { isLoading }
8989 allowClear
9090 enterButton
9191 onChange = { ( e ) => handleSerachKey ( e . target . value ) }
0 commit comments