add retry button for global search while error

This commit is contained in:
smanylov
2026-03-03 11:57:18 +07:00
parent 3b1509edf0
commit 2227a842ae
2 changed files with 20 additions and 12 deletions
-1
View File
@@ -3275,7 +3275,6 @@
} }
.global-error { .global-error {
display: none;
background: #fef2f2; background: #fef2f2;
border: 2px solid #fecaca; border: 2px solid #fecaca;
border-radius: 12px; border-radius: 12px;
+20 -11
View File
@@ -44,6 +44,7 @@ export function FileSearchPanel(
const [showGlobalSearch, setShowGlobalSearch] = useState<boolean>(false); const [showGlobalSearch, setShowGlobalSearch] = useState<boolean>(false);
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [errorMessage, setErrorMessage] = useState<string | null>(null); const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [globalSearchErrorMessage, setGlobalSearchErrorMessage] = useState<string | null>(null);
const t = useTranslations('Global'); const t = useTranslations('Global');
const [searchTotalPages, setSearchTotalPages] = useState<number>(0); const [searchTotalPages, setSearchTotalPages] = useState<number>(0);
@@ -64,6 +65,7 @@ export function FileSearchPanel(
const handlerSearchUserFile = useCallback(async (fileId: string, page: number): Promise<void> => { const handlerSearchUserFile = useCallback(async (fileId: string, page: number): Promise<void> => {
setErrorMessage(null); setErrorMessage(null);
setGlobalSearchErrorMessage(null);
try { try {
let result = await searchUserFiles(fileId); let result = await searchUserFiles(fileId);
@@ -84,6 +86,8 @@ export function FileSearchPanel(
}, [fileId]) }, [fileId])
const handlerSearchGlobalFile = useCallback(async (fileId: string, page: number, actionFromPagination?: boolean): Promise<void> => { const handlerSearchGlobalFile = useCallback(async (fileId: string, page: number, actionFromPagination?: boolean): Promise<void> => {
setGlobalSearchErrorMessage(null);
if (!actionFromPagination) { if (!actionFromPagination) {
setLoading(true); setLoading(true);
setSearchedGlobalFilesShowNull(false); setSearchedGlobalFilesShowNull(false);
@@ -94,8 +98,10 @@ export function FileSearchPanel(
try { try {
let result = await searchGlobalFiles(fileId, page); let result = await searchGlobalFiles(fileId, page);
console.log('searchGlobalFiles');
console.log(result); if (result.error) {
throw result.error;
}
if (result.images.length) { if (result.images.length) {
setSearchedGlobalFiles(result.images); setSearchedGlobalFiles(result.images);
setSearchTotalPages(result.totalPages); setSearchTotalPages(result.totalPages);
@@ -105,7 +111,7 @@ export function FileSearchPanel(
setSearchedGlobalFilesShowNull(true); setSearchedGlobalFilesShowNull(true);
} }
} catch (error) { } catch (error) {
setErrorMessage('error'); setGlobalSearchErrorMessage('error');
} finally { } finally {
await queryClient.invalidateQueries({ queryKey: ['userData'] }); await queryClient.invalidateQueries({ queryKey: ['userData'] });
await queryClient.invalidateQueries({ queryKey: ['userSearchData'] }); await queryClient.invalidateQueries({ queryKey: ['userSearchData'] });
@@ -230,7 +236,15 @@ export function FileSearchPanel(
<p className="global-no-result-text"> <p className="global-no-result-text">
{t('no-similar-global-description')} {t('no-similar-global-description')}
</p> </p>
{/* <button </div>
)}
{globalSearchErrorMessage && (
<>
<div className="global-error">
<strong>{t('search-error')}</strong>
</div>
<button
onClick={() => { onClick={() => {
if (fileId) { if (fileId) {
handlerSearchGlobalFile(fileId, 1); handlerSearchGlobalFile(fileId, 1);
@@ -239,15 +253,10 @@ export function FileSearchPanel(
className="btn btn-primary btn-search" className="btn btn-primary btn-search"
> >
{t('search-again')} {t('search-again')}
</button> */} </button>
</div> </>
)} )}
<div className="global-error">
<strong>{t('global-error-title')}</strong>
<span id="global-error-text"></span>
</div>
<Pagination <Pagination
totalPages={searchTotalPages} totalPages={searchTotalPages}
currentPage={searchCurrentPages} currentPage={searchCurrentPages}