diff --git a/src/pages/homepage/components/Search/Search.tsx b/src/pages/homepage/components/Search/Search.tsx index b5ab434..720b9a9 100644 --- a/src/pages/homepage/components/Search/Search.tsx +++ b/src/pages/homepage/components/Search/Search.tsx @@ -70,6 +70,10 @@ export default function Search({ open(`${url}${item.option.searchTerm}`, '_self'); }; + const handleAppSearchItem = (item: any) => { + open(`https://${item.option.url}`, '_self'); + }; + const handleKeyPress = (item: any) => { let option = ''; let subtext = ''; @@ -134,7 +138,9 @@ export default function Search({ setListIndex(0); openDropdown(); setPlaceholderValue( - searchHistory.length > 0 ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` : '', + searchHistory.length > 0 + ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` + : '', ); } if (!providerLabel.startsWith('Invalid')) { @@ -156,7 +162,9 @@ export default function Search({ } } else if (item.code === 'ArrowRight' || item.code === 'Tab') { setSearchValue( - searchHistory.length > 0 ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` : '', + searchHistory.length > 0 + ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` + : '', ); setValue(searchHistory.length > 0 ? searchHistory[listIndex].id : 0); } @@ -232,6 +240,15 @@ export default function Search({ const optionsFilter: OptionsFilter = ({ options, search }) => { const splittedSearch = search.toLowerCase().trim().split(' '); + if (splittedSearch[0] === '!') { + return apps.map((app: any) => { + return { + label: app.name, + value: app.baseUrl, + ...app, + }; + }); + } return options .filter((option: any) => { const words = option.value.toLowerCase().trim().split(' '); @@ -244,13 +261,80 @@ export default function Search({ function RenderOption(item: any) { const [showFillButton, setShowFillButton] = useState(false); - const m = new Date(item.option.dateTimeStamp); - const dateString = `${m.getUTCFullYear()}/${`0${m.getUTCMonth() + 1}`.slice(-2)}/${`0${m.getUTCDate()}`.slice(-2)} ${`0${m.getUTCHours()}`.slice(-2)}:${`0${m.getUTCMinutes()}`.slice(-2)}:${`0${m.getUTCSeconds()}`.slice(-2)}`; + if (item.option.searchTerm) { + const m = new Date(item.option.dateTimeStamp); + const dateString = `${m.getUTCFullYear()}/${`0${m.getUTCMonth() + 1}`.slice(-2)}/${`0${m.getUTCDate()}`.slice(-2)} ${`0${m.getUTCHours()}`.slice(-2)}:${`0${m.getUTCMinutes()}`.slice(-2)}:${`0${m.getUTCSeconds()}`.slice(-2)}`; + return ( + { + handleSearchHistoryItem(item); + }} + onMouseEnter={() => { + setShowFillButton(true); + }} + onMouseLeave={() => { + setShowFillButton(false); + }} + > + + + {item.option.provider} + + {showFillButton && ( + { + e.stopPropagation(); + setSearchValue(`${item.option.prefix} ${item.option.searchTerm}`); + }} + > + + + )} + + + {item.option.searchTerm} + + {dateString} + + + {showFillButton && ( + { + e.stopPropagation(); + deleteHistoryItem({ + method: 'DELETE', + endpoint: 'api/searchHistory', + body: { id: item.option.id }, + }); + }} + > + + + )} + + ); + } return ( { - handleSearchHistoryItem(item); + handleAppSearchItem(item); }} onMouseEnter={() => { setShowFillButton(true); @@ -268,20 +352,8 @@ export default function Search({ padding: '5px', }} > - {item.option.provider} + {item.option.label} - {showFillButton && ( - { - e.stopPropagation(); - setSearchValue(`${item.option.prefix} ${item.option.searchTerm}`); - }} - > - - - )} {item.option.searchTerm} @@ -290,25 +362,9 @@ export default function Search({ color: `${theme.primaryColor}55`, }} > - {dateString} + {item.option.value} - {showFillButton && ( - { - e.stopPropagation(); - deleteHistoryItem({ - method: 'DELETE', - endpoint: 'api/searchHistory', - body: { id: item.option.id }, - }); - }} - > - - - )} ); } @@ -337,7 +393,9 @@ export default function Search({ useEffect(() => { if (dropdownOpened) { setPlaceholderValue( - searchHistory.length > 0 ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` : '', + searchHistory.length > 0 + ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` + : '', ); } }, [listIndex, dropdownOpened]); @@ -412,6 +470,7 @@ export default function Search({ />