Search bar app launch fix

This commit is contained in:
Sean Edmunds
2025-06-18 17:04:09 -05:00
parent a513c96042
commit 72a1ed8eb2
3 changed files with 56 additions and 11 deletions

View File

@@ -6,7 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"lint": "npx @biomejs/biome lint . --write --unsafe && npx @biomejs/biome format . --write && npx @biomejs/biome check . --write --unsafe && npx @biomejs/biome ci . --formatter-enabled=true --linter-enabled=true --organize-imports-enabled=true", "lint": "npx @biomejs/biome lint . --write --unsafe && npx @biomejs/biome format . --write && npx @biomejs/biome check . --write --unsafe && npx @biomejs/biome ci . --formatter-enabled=true --linter-enabled=true",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {

View File

@@ -1,8 +1,11 @@
import { type OptionsFilter, Select, Stack, Text } from '@mantine/core'; import { Group, type OptionsFilter, Select, Stack, Text } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { HelpModal, WeatherModal } from 'components'; import { HelpModal, WeatherModal } from 'components';
import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks'; import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import * as fa6 from 'react-icons/fa6';
import * as si from 'react-icons/si';
import * as vsc from 'react-icons/vsc';
import { selectClasses } from 'styles'; import { selectClasses } from 'styles';
import type { import type {
Application, Application,
@@ -11,7 +14,7 @@ import type {
Provider, Provider,
SearchHistoryItem, SearchHistoryItem,
} from 'types'; } from 'types';
import SearchSelectItem from './SearchHistoryItem'; import SearchSelectItem from './SearchSelectItem';
export default function Search({ export default function Search({
current, current,
@@ -26,6 +29,7 @@ export default function Search({
closeWeatherModal: () => void; closeWeatherModal: () => void;
openWeatherModal: () => void; openWeatherModal: () => void;
}) { }) {
const allIcons: any = { ...fa6, ...vsc, ...si };
const { data: providerData, isFetched: providerDataIsFetched } = useQueryAPI({ const { data: providerData, isFetched: providerDataIsFetched } = useQueryAPI({
endpoint: 'api/providers', endpoint: 'api/providers',
}); });
@@ -67,6 +71,14 @@ export default function Search({
open(`${url}${option.searchTerm}`, '_self'); open(`${url}${option.searchTerm}`, '_self');
}; };
const handleAppLaunchItem = ({ option }: { option: any }) => {
const validUrl =
option.url.startsWith('http://') || option.url.startsWith('https://')
? option.url
: `http://${option.url}`;
open(validUrl, '_self');
};
const handleKeyPress = (item: any) => { const handleKeyPress = (item: any) => {
let option = ''; let option = '';
let subtext = ''; let subtext = '';
@@ -286,7 +298,7 @@ export default function Search({
}, [historyData, historyDataIsFetched]); }, [historyData, historyDataIsFetched]);
useEffect(() => { useEffect(() => {
if (dropdownOpened) { if (dropdownOpened && listIndex >= 0) {
setPlaceholderValue( setPlaceholderValue(
searchHistory.length > 0 searchHistory.length > 0
? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}`
@@ -346,13 +358,46 @@ export default function Search({
autoFocus={!isMobile} autoFocus={!isMobile}
leftSection={providerLabel} leftSection={providerLabel}
rightSection={<Stack />} rightSection={<Stack />}
renderOption={(item: any) => ( renderOption={(item: any) => {
<SearchSelectItem const Icon = allIcons[item.option.icon];
item={item} return !searchValue.startsWith('!') ? (
handleSearchHistoryItem={handleSearchHistoryItem} <SearchSelectItem
searchEndpoint={searchEndpoint} item={item}
/> handleSearchHistoryItem={handleSearchHistoryItem}
)} searchEndpoint={searchEndpoint}
/>
) : (
<Group
pos={'relative'}
m={0}
p={0}
gap={0}
justify='center'
w={'100%'}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleAppLaunchItem(item);
}}
>
<Text pos={'absolute'} left={'1rem'} c={'var(--mantine-color-accent-0)'}>
Launch
</Text>
{Icon && (
<Icon
style={{
color: 'var(--mantine-color-primary-0)',
height: '2rem',
width: '2rem',
}}
/>
)}
<Text pos={'absolute'} right={'1rem'} c={'var(--mantine-color-accent-0)'}>
{item.option.name}
</Text>
</Group>
);
}}
onBlur={() => { onBlur={() => {
setPlaceholderValue(''); setPlaceholderValue('');
setListIndex(0); setListIndex(0);