From 7a41bea85ee455ae84c19271564ee349efda7115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 18 Oct 2024 18:49:31 +0200 Subject: [PATCH 1/2] improve search styles --- src/pages/dashboard/components/Search.tsx | 72 ++++++++++++++--------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/pages/dashboard/components/Search.tsx b/src/pages/dashboard/components/Search.tsx index 81baa6f55..089a0358f 100644 --- a/src/pages/dashboard/components/Search.tsx +++ b/src/pages/dashboard/components/Search.tsx @@ -24,6 +24,7 @@ import { useClickAway } from 'react-use'; import collect from 'collect.js'; import { usePreventNavigation } from '$app/common/hooks/usePreventNavigation'; import { debounce } from 'lodash'; +import { Spinner } from '$app/components/Spinner'; const ComboboxOption = styled(Combobox.Option)` color: ${(props) => props.theme.color}; @@ -41,25 +42,31 @@ export function Search$() { const comboboxRef = useRef(null); const inputRef = useRef(null); - const { data, refetch } = useQuery( + const { data, refetch, isFetching } = useQuery( ['/api/v1/search'], () => { - const $endpoint = query.length === 0 ? '/api/v1/search' : `/api/v1/search?search=${query}`; + const $endpoint = + query.length === 0 + ? '/api/v1/search' + : `/api/v1/search?search=${query}`; + return request('POST', endpoint($endpoint)).then( (response: AxiosResponse) => { const formatted: Entry[] = []; - Object.entries(response.data).forEach(([key, value]: [string, SearchRecord[]]) => { - value.forEach((record: SearchRecord) => { - formatted.push({ - id: v4(), - label: record.name, - value: record.id, - resource: record, - searchable: `${t(key)}: ${record.name}`, - eventType: 'external', + Object.entries(response.data).forEach( + ([key, value]: [string, SearchRecord[]]) => { + value.forEach((record: SearchRecord) => { + formatted.push({ + id: v4(), + label: record.name, + value: record.id, + resource: record, + searchable: `${t(key)}: ${record.name}`, + eventType: 'external', + }); }); - }); - }); + } + ); return formatted; } ); @@ -122,28 +129,39 @@ export function Search$() { ref={comboboxRef} >
- setIsVisible(true)} - placeholder={`${t('search')}... (Ctrl K)`} - style={{ backgroundColor: colors.$1, color: colors.$3 }} - /> +
+ + + + + setIsVisible(true)} + placeholder={`${t('Find invoices, clients and more')}. (Ctrl+K)`} + style={{ backgroundColor: colors.$1, color: colors.$3 }} + /> +
@@ -197,4 +215,4 @@ export function Search$() { ); } -export const Search = memo(Search$); \ No newline at end of file +export const Search = memo(Search$); From c6b88cae5eec0822b9dfe9224932558f38c83d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 18 Oct 2024 18:51:11 +0200 Subject: [PATCH 2/2] update placeholder --- src/pages/dashboard/components/Search.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/dashboard/components/Search.tsx b/src/pages/dashboard/components/Search.tsx index 089a0358f..de47c5aae 100644 --- a/src/pages/dashboard/components/Search.tsx +++ b/src/pages/dashboard/components/Search.tsx @@ -144,7 +144,7 @@ export function Search$() { onChange={handleChange} ref={inputRef} onFocus={() => setIsVisible(true)} - placeholder={`${t('Find invoices, clients and more')}. (Ctrl+K)`} + placeholder={`${t('search_placeholder')}. (Ctrl+K)`} style={{ backgroundColor: colors.$1, color: colors.$3 }} />