Updated presets and added a 'sort by' feature.

This commit is contained in:
ktdd
2026-01-06 12:33:09 +02:00
parent 0c46432150
commit 7edd7c2e35
23 changed files with 103 additions and 47 deletions
+32 -5
View File
@@ -39,6 +39,14 @@ import { EditTagsDialog } from './add-tag-dialog';
import { useTranslation } from 'react-i18next';
import Logo from '@/assets/logo.svg'
import { RestoreMessageDialog } from './restore-message-dialog';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { Label } from '@/components/ui/label';
export default function Search() {
const { t } = useTranslation()
@@ -56,8 +64,10 @@ export default function Search() {
isFetching,
page,
pageSize,
sortBy,
setPage,
setPageSize,
setSortBy,
onSubmit,
reset,
filter
@@ -121,10 +131,27 @@ export default function Search() {
</div>
</aside>
<div className="flex-1 min-w-0 space-y-4">
<Button size="sm" onClick={() => setOpen("search-form")}>
<SearchIcon className="mr-2 h-4 w-4" />
{t('common.search')}
</Button>
<div className="flex flex-row gap-4 items-end">
<Button size="sm" onClick={() => setOpen("search-form")}>
<SearchIcon className="mr-2 h-4 w-4" />
{t('common.search')}
</Button>
<Label className="">
{t('search.sortBy')}
<Select
value={sortBy}
onValueChange={(value: "date" | "size") => setSortBy(value)}
>
<SelectTrigger className='h-8 mt-2'>
<SelectValue placeholder="Placeholder" />
</SelectTrigger>
<SelectContent side='top'>
<SelectItem value="date">{t('search.date')}</SelectItem>
<SelectItem value="size">{t('search.size')}</SelectItem>
</SelectContent>
</Select>
</Label>
</div>
{isLoading && (
<Card>
<CardContent className="py-12">
@@ -207,4 +234,4 @@ export default function Search() {
</Main>
</>
);
}
}
+5 -3
View File
@@ -67,7 +67,7 @@ const getSearchFilterSchema = (t: (key: string) => string) => z.object({
before: z.date().optional(),
account_id: z.number().optional().or(z.literal("")),
mailbox_id: z.number().optional().or(z.literal("")),
size_preset: z.enum(['any', 'tiny', 'small', 'medium', 'large']).optional(),
size_preset: z.enum(['any', 'tiny', 'small', 'medium', 'large', 'huge']).optional(),
message_id: z.string().optional().or(z.literal("")),
});
@@ -107,8 +107,10 @@ function withSizePreset(values: Record<string, any>) {
case 'small':
return { ...rest, max_size: 2 * 1024 * 1024 };
case 'medium':
return { ...rest, max_size: 20 * 1024 * 1024 };
return { ...rest, min_size: 2 * 1024 * 1024, max_size: 10 * 1024 * 1024 };
case 'large':
return { ...rest, min_size: 10 * 1024 * 1024, max_size: 20 * 1024 * 1024 };
case 'huge':
return { ...rest, min_size: 20 * 1024 * 1024 };
default:
return rest;
@@ -496,4 +498,4 @@ export function SearchFormDialog({ onSubmit, isLoading, reset, open, onOpenChang
</Form>
</SheetContent>
</Sheet>);
}
}
+5 -1
View File
@@ -29,6 +29,7 @@ export function useSearchMessages() {
const [filter, setFilter] = useState<Record<string, any>>({});
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(30);
const [sortBy, setSortBy] = useState<"date" | "size">("date");
const onSubmit = (cleaned: Record<string, any>) => {
if ('has_attachment' in cleaned && cleaned.has_attachment === false) {
@@ -59,12 +60,13 @@ export function useSearchMessages() {
error,
isFetching,
} = useQuery<PaginatedResponse<EmailEnvelope>>({
queryKey: ['search-messages', filter, page, pageSize],
queryKey: ['search-messages', filter, page, pageSize, sortBy],
queryFn: () =>
search_messages({
filter: filter,
page,
page_size: pageSize,
sort_by: sortBy
}),
staleTime: 1000,
retry: false,
@@ -76,6 +78,8 @@ export function useSearchMessages() {
totalPages: data?.total_pages ?? 1,
pageSize: data?.page_size ?? pageSize,
setPageSize,
sortBy,
setSortBy,
isLoading,
isError,
error: error as Error | null,
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "الكل",
"tiny": "صغير جدًا (<15 كيلوبايت)",
"small": "صغير (<2 ميغابايت)",
"medium": "متوسط (<20 ميغابايت)",
"large": "كبير (20 ميغابايت)",
"medium": "متوسط (2 - 10 ميغابايت)",
"large": "كبير (10 - 20 ميغابايت)",
"sizeDescription": "يشير الحجم إلى الحجم الإجمالي للبريد الإلكتروني، بما في ذلك المرفقات.",
"title": "بحث",
"searching": "جارٍ البحث، يرجى الانتظار...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Alle",
"tiny": "Meget lille (<15 KB)",
"small": "Lille (<2 MB)",
"medium": "Mellem (<20 MB)",
"large": "Stor (20 MB)",
"medium": "Mellem (2 - 10 MB)",
"large": "Stor (10 - 20 MB)",
"sizeDescription": "Størrelsen henviser til den samlede e-mailstørrelse, inklusive vedhæftede filer.",
"title": "Søg",
"searching": "Søger, vent venligst...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Beliebig",
"tiny": "Sehr klein (<15 KB)",
"small": "Klein (<2 MB)",
"medium": "Mittel (<20 MB)",
"large": "Groß (20 MB)",
"medium": "Mittel (2 - 10 MB)",
"large": "Groß (10 - 20 MB)",
"sizeDescription": "Die Größe bezieht sich auf die gesamte E-Mail inklusive Anhängen.",
"title": "Suchen",
"searching": "Wird gesucht, bitte warten Sie...",
+4 -2
View File
@@ -412,8 +412,10 @@
"any": "Any",
"tiny": "Tiny (<15 KB)",
"small": "Small (<2 MB)",
"medium": "Medium (<20 MB)",
"large": "Large (20 MB)",
"medium": "Medium (2 - 10 MB)",
"large": "Large (10 - 20 MB)",
"huge": "Huge (≥20 MB)",
"sortBy": "Sort by",
"sizeDescription": "The size refers to the total email size, including attachments.",
"title": "Search",
"searching": "Searching, please wait…",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Cualquiera",
"tiny": "Muy pequeño (<15 KB)",
"small": "Pequeño (<2 MB)",
"medium": "Mediano (<20 MB)",
"large": "Grande (20 MB)",
"medium": "Mediano (2 - 10 MB)",
"large": "Grande (10 - 20 MB)",
"sizeDescription": "El tamaño se refiere al tamaño total del correo electrónico, incluidos los archivos adjuntos.",
"title": "Buscar",
"searching": "Buscando, por favor espera...",
+4 -2
View File
@@ -412,8 +412,10 @@
"any": "Kaikki",
"tiny": "Erittäin pieni (<15 KB)",
"small": "Pieni (<2 MB)",
"medium": "Keskikokoinen (<20 MB)",
"large": "Suuri (20 MB)",
"medium": "Keskikokoinen (2 - 10 MB)",
"large": "Suuri (10 - 20 MB)",
"huge": "Valtava (≥20 MB)",
"sortBy": "Lajittele",
"sizeDescription": "Koko tarkoittaa sähköpostin kokonaiskokoa, liitteet mukaan lukien.",
"title": "Hae",
"searching": "Haetaan, odota hetki...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Toutes",
"tiny": "Très petite (<15 KB)",
"small": "Petite (<2 MB)",
"medium": "Moyenne (<20 MB)",
"large": "Grande (20 MB)",
"medium": "Moyenne (2 - 10 MB)",
"large": "Grande (10 - 20 MB)",
"sizeDescription": "La taille correspond à la taille totale de le-mail, pièces jointes incluses.",
"title": "Recherche",
"searching": "Recherche en cours, veuillez patienter...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Qualsiasi",
"tiny": "Molto piccolo (<15 KB)",
"small": "Piccolo (<2 MB)",
"medium": "Medio (<20 MB)",
"large": "Grande (20 MB)",
"medium": "Medio (2 - 10 MB)",
"large": "Grande (10 - 20 MB)",
"sizeDescription": "La dimensione indica la dimensione totale dellemail, inclusi gli allegati.",
"title": "Cerca",
"searching": "Ricerca in corso, attendere prego...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "指定なし",
"tiny": "極小(15 KB 未満)",
"small": "小(2 MB 未満)",
"medium": "中(20 MB 未満",
"large": "大(20 MB 以上",
"medium": "中(2 - 10 MB",
"large": "大(10 - 20 MB",
"sizeDescription": "サイズは添付ファイルを含むメール全体の容量を指します。",
"title": "検索",
"searching": "検索中です。お待ちください…",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "전체",
"tiny": "아주 작음 (<15 KB)",
"small": "작음 (<2 MB)",
"medium": "중간 (<20 MB)",
"large": "큼 (20 MB)",
"medium": "중간 (2 - 10 MB)",
"large": "큼 (10 - 20 MB)",
"sizeDescription": "크기는 첨부 파일을 포함한 이메일 전체 크기를 의미합니다.",
"title": "검색",
"searching": "검색 중입니다. 잠시 기다려 주십시오...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Alle",
"tiny": "Zeer klein (<15 KB)",
"small": "Klein (<2 MB)",
"medium": "Middelgroot (<20 MB)",
"large": "Groot (20 MB)",
"medium": "Middelgroot (2 - 10 MB)",
"large": "Groot (10 - 20 MB)",
"sizeDescription": "De grootte verwijst naar de totale e-mailgrootte, inclusief bijlagen.",
"title": "Zoeken",
"searching": "Bezig met zoeken, even geduld alstublieft…",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Alle",
"tiny": "Svært liten (<15 KB)",
"small": "Liten (<2 MB)",
"medium": "Middels (<20 MB)",
"large": "Stor (20 MB)",
"medium": "Middels (2 - 10 MB)",
"large": "Stor (10 - 20 MB)",
"sizeDescription": "Størrelsen viser til e-postens totale størrelse, inkludert vedlegg.",
"title": "Søk",
"searching": "Søker, vennligst vent…",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Dowolny",
"tiny": "Bardzo mały (<15 KB)",
"small": "Mały (<2 MB)",
"medium": "Średni (<20 MB)",
"large": "Duży (20 MB)",
"medium": "Średni (2 - 10 MB)",
"large": "Duży (10 - 20 MB)",
"sizeDescription": "Rozmiar odnosi się do całkowitego rozmiaru wiadomości e-mail, łącznie z załącznikami.",
"title": "Szukaj",
"searching": "Wyszukiwanie, proszę czekać...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Qualquer",
"tiny": "Muito pequeno (<15 KB)",
"small": "Pequeno (<2 MB)",
"medium": "Médio (<20 MB)",
"large": "Grande (20 MB)",
"medium": "Médio (2 - 10 MB)",
"large": "Grande (10 - 20 MB)",
"sizeDescription": "O tamanho refere-se ao tamanho total do e-mail, incluindo anexos.",
"title": "Pesquisa",
"searching": "Pesquisando, por favor, aguarde...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Любой",
"tiny": "Очень маленький (<15 КБ)",
"small": "Маленький (<2 МБ)",
"medium": "Средний (<20 МБ)",
"large": "Большой (20 МБ)",
"medium": "Средний (2 - 10 МБ)",
"large": "Большой (10 - 20 МБ)",
"sizeDescription": "Размер означает общий размер электронного письма, включая вложения.",
"title": "Поиск",
"searching": "Поиск, пожалуйста, подождите...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "Alla",
"tiny": "Mycket liten (<15 KB)",
"small": "Liten (<2 MB)",
"medium": "Medelstor (<20 MB)",
"large": "Stor (20 MB)",
"medium": "Medelstor (2 - 10 MB)",
"large": "Stor (10 - 20 MB)",
"sizeDescription": "Storleken avser e-postens totala storlek, inklusive bilagor.",
"title": "Sök",
"searching": "Söker, vänligen vänta…",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "不限",
"tiny": "很小(<15 KB",
"small": "小(<2 MB",
"medium": "中(<20 MB",
"large": "大(20 MB",
"medium": "中(2 - 10 MB",
"large": "大(10 - 20 MB",
"sizeDescription": "大小指的是整封郵件的大小,包含附件。",
"title": "搜尋",
"searching": "正在搜尋,請稍候...",
+2 -2
View File
@@ -412,8 +412,8 @@
"any": "不限",
"tiny": "很小(<15 KB",
"small": "小(<2 MB",
"medium": "中(<20 MB",
"large": "大(20 MB",
"medium": "中(2 - 10 MB",
"large": "大(10 - 20 MB",
"sizeDescription": "大小指的是邮件整体大小,包含附件。",
"title": "搜索",
"searching": "搜索中,请稍候…",