feat(05-01): create search types and utility functions

- Add SearchFilters interface for query, tags, type, dateRange
- Add defaultFilters constant with empty/default values
- Add hasActiveFilters() to detect when filters are active
- Add getDatePreset() helper for today/week/month presets
This commit is contained in:
Thomas Richter
2026-01-31 17:11:51 +01:00
parent f6144f4edf
commit b1e62a4658

52
src/lib/types/search.ts Normal file
View File

@@ -0,0 +1,52 @@
export interface SearchFilters {
query: string;
tags: string[];
type: 'task' | 'thought' | 'all';
dateRange: {
start: string | null;
end: string | null;
};
}
export const defaultFilters: SearchFilters = {
query: '',
tags: [],
type: 'all',
dateRange: { start: null, end: null }
};
export function hasActiveFilters(filters: SearchFilters): boolean {
return (
filters.query.length >= 2 ||
filters.tags.length > 0 ||
filters.type !== 'all' ||
filters.dateRange.start !== null ||
filters.dateRange.end !== null
);
}
// Date preset helper for quick date range selection
export function getDatePreset(preset: 'today' | 'week' | 'month'): { start: string; end: string } {
const now = new Date();
const end = now.toISOString().split('T')[0];
let start: Date;
switch (preset) {
case 'today':
start = now;
break;
case 'week':
start = new Date(now);
start.setDate(start.getDate() - 7);
break;
case 'month':
start = new Date(now);
start.setMonth(start.getMonth() - 1);
break;
}
return {
start: start.toISOString().split('T')[0],
end
};
}