diff --git a/src/lib/types/search.ts b/src/lib/types/search.ts new file mode 100644 index 0000000..2c8fe80 --- /dev/null +++ b/src/lib/types/search.ts @@ -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 + }; +}