Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: rewind date change controls (#1262)

shaik-zeeshan26c20f293b12
diff --git a/pipes/rewind/src/app/page.tsx b/pipes/rewind/src/app/page.tsx
index b059452ab..2e4b9b56a 100644
--- a/pipes/rewind/src/app/page.tsx
+++ b/pipes/rewind/src/app/page.tsx
@@ -11,12 +11,13 @@ import { TimelineSelection } from "@/components/timeline/timeline-selection";
import { TimelineControls } from "@/components/timeline/timeline-controls";
import { TimelineSearch } from "@/components/timeline/timeline-search";
import { TimelineSearch2 } from "@/components/timeline/timeline-search-v2";
-import { isAfter, isSameDay } from "date-fns";
+import { addDays, isAfter, isSameDay, subDays } from "date-fns";
import { getStartDate } from "@/lib/actions/get-start-date";
import { useTimelineData } from "@/lib/hooks/use-timeline-data";
import { useCurrentFrame } from "@/lib/hooks/use-current-frame";
import { TimelineSlider } from "@/components/timeline/timeline";
import { useTimelineStore } from "@/lib/hooks/use-timeline-store";
+import { hasFramesForDate } from "@/lib/actions/has-frames-date";
export interface StreamTimeSeriesResponse {
timestamp: string;
@@ -85,7 +86,6 @@ export default function Timeline() {
const getStartDateAndSet = async () => {
const data = await getStartDate();
if (!("error" in data)) {
- console.log(data);
setStartAndEndDates((prev) => ({
...prev,
start: data,
@@ -248,8 +248,20 @@ export default function Timeline() {
}
};
- const handleDateChange = (newDate: Date) => {
- console.log(hasDateBeenFetched(newDate));
+ const handleDateChange = async (newDate: Date) => {
+ const checkFramesForDate = await hasFramesForDate(newDate);
+
+ if (!checkFramesForDate) {
+ let subDate;
+ if (isAfter(currentDate, newDate)) {
+ subDate = subDays(newDate, 1);
+ } else {
+ subDate = addDays(newDate, 1);
+ }
+
+ return await handleDateChange(subDate);
+ }
+
if (!hasDateBeenFetched(newDate)) {
setCurrentFrame(null);
const frameTimeStamp = new Date(newDate);
diff --git a/pipes/rewind/src/components/timeline/timeline-controls.tsx b/pipes/rewind/src/components/timeline/timeline-controls.tsx
index fae4d1caf..ef53fa890 100644
--- a/pipes/rewind/src/components/timeline/timeline-controls.tsx
+++ b/pipes/rewind/src/components/timeline/timeline-controls.tsx
@@ -22,7 +22,7 @@ interface TimeRange {
interface TimelineControlsProps {
startAndEndDates: TimeRange;
currentDate: Date;
- onDateChange: (date: Date) => void;
+ onDateChange: (date: Date) => Promise<any>;
onJumpToday: () => void;
className?: string;
}
@@ -34,19 +34,19 @@ export function TimelineControls({
onJumpToday,
className,
}: TimelineControlsProps) {
- const jumpDay = (days: number) => {
+ const jumpDay = async (days: number) => {
const today = new Date();
const newDate = endOfDay(new Date(currentDate));
newDate.setDate(newDate.getDate() + days);
// Prevent jumping to future dates
- if (isAfter(newDate.getDate(), today.getDate())) {
- onDateChange(today);
+ if (isAfter(startOfDay(newDate), startOfDay(today))) {
+ await onDateChange(today);
return;
}
- onDateChange(newDate);
+ await onDateChange(newDate);
};
// Disable forward button if we're at today