From 332788a77a7aaafefb14382936ef1c6655614880 Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 23 Feb 2026 14:44:22 +0700 Subject: [PATCH] remove preview for all file except images --- src/app/lib/getFileType.ts | 28 +++++++++++ src/app/styles/pages-styles.scss | 22 +++------ src/app/ui/search/file-search-panel.tsx | 5 +- .../ui/search/searched-user-files-list.tsx | 49 +++++++++++-------- src/app/ui/search/section-search-file.tsx | 47 ++++-------------- 5 files changed, 76 insertions(+), 75 deletions(-) create mode 100644 src/app/lib/getFileType.ts diff --git a/src/app/lib/getFileType.ts b/src/app/lib/getFileType.ts new file mode 100644 index 0000000..7fba588 --- /dev/null +++ b/src/app/lib/getFileType.ts @@ -0,0 +1,28 @@ +export const getFileType = (fileName: string, allowedExtensions: { + images: string[], + videos: string[], + audios: string[], + documents: string[] +}): 'image' | 'video' | 'audio' | 'document' | 'unknown' => { + + const lastDotIndex = fileName.lastIndexOf('.'); + const extension = fileName.substring(lastDotIndex + 1).toLowerCase(); + + if (allowedExtensions.images.includes(extension)) { + return 'image'; + } + + if (allowedExtensions.videos.includes(extension)) { + return 'video'; + } + + if (allowedExtensions.audios.includes(extension)) { + return 'audio'; + } + + if (allowedExtensions.documents.includes(extension)) { + return 'document'; + } + + return 'unknown'; +} \ No newline at end of file diff --git a/src/app/styles/pages-styles.scss b/src/app/styles/pages-styles.scss index 6076114..eefb587 100644 --- a/src/app/styles/pages-styles.scss +++ b/src/app/styles/pages-styles.scss @@ -3388,19 +3388,6 @@ } } - .preview-fallback { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - display: flex; - align-items: center; - justify-content: center; - font-size: 24px; - background: #f3f4f6; - } - .result-info { flex: 1; } @@ -3533,11 +3520,14 @@ background: v.$white; &-wrapper { - display: grid; - grid-template-columns: 1fr 300px; - gap: 20px; height: 100%; max-height: 80vh; + + &.image { + display: grid; + grid-template-columns: 1fr 300px; + gap: 20px; + } } .image-section { diff --git a/src/app/ui/search/file-search-panel.tsx b/src/app/ui/search/file-search-panel.tsx index 3a6d278..9a2e67e 100644 --- a/src/app/ui/search/file-search-panel.tsx +++ b/src/app/ui/search/file-search-panel.tsx @@ -5,6 +5,7 @@ import { searchUserFiles, searchGlobalFiles } from '@/app/actions/searchActions' import { useQueryClient } from '@tanstack/react-query'; import { Pagination } from '@/app/components/Pagination'; import { useTranslations } from 'next-intl'; +import { AllowedExtensions } from '@/app/ui/search/section-search-file'; export interface SearchItem { url: string, @@ -15,7 +16,7 @@ export interface SearchItem { pageUrl: string } -export function FileSearchPanel({ fileId, ref }: { fileId: string | null, ref: any }) { +export function FileSearchPanel({ fileId, ref, allowedExtensions }: { fileId: string | null, ref: any, allowedExtensions: AllowedExtensions }) { const [searchedUserFiles, setSearchedUserFiles] = useState([]); const [searchedUserFilesShowNull, setSearchedUserFilesShowNull] = useState(false); const [searchedGlobalFiles, setSearchedGlobalFiles] = useState([]); @@ -117,7 +118,7 @@ export function FileSearchPanel({ fileId, ref }: { fileId: string | null, ref: a {(searchedUserFiles.length !== 0) && ( - + )} {searchedUserFilesShowNull && ( diff --git a/src/app/ui/search/searched-user-files-list.tsx b/src/app/ui/search/searched-user-files-list.tsx index d5f35ed..c5fe420 100644 --- a/src/app/ui/search/searched-user-files-list.tsx +++ b/src/app/ui/search/searched-user-files-list.tsx @@ -4,8 +4,11 @@ import { useState, ReactNode } from 'react'; import { useTranslations } from 'next-intl'; import ModalWindow from '@/app/components/ModalWindow'; import { IconEye, IconDownload } from '@/app/ui/icons/icons'; +import { getFileType } from '@/app/lib/getFileType'; +import { AllowedExtensions } from '@/app/ui/search/section-search-file'; +import { FileTypeIcon } from '@/app/components/FileTypeIcon'; -export function SearchedUserFilesList({ list }: { list: any }) { +export function SearchedUserFilesList({ list, allowedExtensions }: { list: string[], allowedExtensions: AllowedExtensions }) { const [isFileLoading, setIsFileLoading] = useState(false); const [openWindow, setOpenWindow] = useState(false); const [openWindowChildren, setOpenWindowChildren] = useState(null); @@ -38,7 +41,7 @@ export function SearchedUserFilesList({ list }: { list: any }) { } }; - const handlerViewfile = async (e: any) => { + const handlerViewfile = async (e: any, fileType: string) => { setOpenWindowChildren(() => { return (
-
-
-
- img +
+ {fileType === 'image' && ( +
+
+ img +
-
+ )}
@@ -117,6 +122,8 @@ export function SearchedUserFilesList({ list }: { list: any }) { className="results-list" > {list.map((e: any, index: number) => { + const fileType = getFileType(e.originalFileName, allowedExtensions); + if (e.similarityLevel !== 'DIFFERENT') { return (
-
- {e.url ? ( - Preview - ) : ( -
- 📄 -
- )} -
+ {fileType === 'image' ? ( +
+ {e.url ? ( + Preview + ) : ( + + )} +
+ ) : ( + + )}
{e.originalFileName} @@ -161,7 +170,7 @@ export function SearchedUserFilesList({ list }: { list: any }) {
{isFileUploaded && ( - + )}
);