From 559902e0211a06b349c4c2f50b0882a8d314f8b7 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Fri, 6 Jan 2023 02:32:59 +1100 Subject: Jump to and highlight search results Use a 'searchTarget' prop of Timeline to trigger jumping to a search result. Make TimeLine prioritise search result in layout. When querying for events in App, check for a search target, and use incl= to retrieve it. On server, for the incl= query param, don't include the event if outside specified range. --- src/lib.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/lib.ts') diff --git a/src/lib.ts b/src/lib.ts index f6147dc..d26c8df 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -565,6 +565,21 @@ export function dateToUnit(date: HistDate, scale: number): number { } } } +export function dateToScaleDate(date: HistDate, scale: number): HistDate { + // Returns a date representing the unit on 'scale' that 'date' is within + if (scale == DAY_SCALE){ + return new CalDate(date.year, date.month, date.day); + } else if (scale == MONTH_SCALE){ + return new CalDate(date.year, date.month, 1); + } else { + const year = Math.floor(date.year / scale) * scale; + if (year < MIN_CAL_YEAR){ + return new YearDate(year); + } else { + return new CalDate(year == 0 ? 1 : year, 1, 1); + } + } +} // For sending timeline-bound data to BaseLine export class TimelineState { -- cgit v1.2.3