Skip to content

Commit 05bdbf5

Browse files
committed
All waitpoint sidebar variants
1 parent 677077a commit 05bdbf5

File tree

4 files changed

+106
-8
lines changed

4 files changed

+106
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useAnimate } from "framer-motion";
2+
import { HourglassIcon } from "lucide-react";
3+
import { useEffect } from "react";
4+
5+
export function AnimatedHourglassIcon({
6+
className,
7+
delay,
8+
}: {
9+
className?: string;
10+
delay?: number;
11+
}) {
12+
const [scope, animate] = useAnimate();
13+
14+
useEffect(() => {
15+
animate(
16+
[
17+
[scope.current, { rotate: 0 }, { duration: 0.7 }],
18+
[scope.current, { rotate: 180 }, { duration: 0.3 }],
19+
[scope.current, { rotate: 180 }, { duration: 0.7 }],
20+
[scope.current, { rotate: 360 }, { duration: 0.3 }],
21+
],
22+
{ repeat: Infinity, delay }
23+
);
24+
});
25+
26+
return <HourglassIcon ref={scope} className={className} />;
27+
}

apps/webapp/app/components/runs/v3/LiveTimer.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,37 @@ export function LiveCountUp({
6666
</>
6767
);
6868
}
69+
70+
export function LiveCountdown({
71+
endTime,
72+
updateInterval = 100,
73+
}: {
74+
endTime: Date;
75+
updateInterval?: number;
76+
}) {
77+
const [now, setNow] = useState<Date>();
78+
79+
useEffect(() => {
80+
const interval = setInterval(() => {
81+
const date = new Date();
82+
setNow(date);
83+
84+
if (date > endTime) {
85+
clearInterval(interval);
86+
}
87+
}, updateInterval);
88+
89+
return () => clearInterval(interval);
90+
}, [endTime]);
91+
92+
return (
93+
<>
94+
{formatDuration(now, endTime, {
95+
style: "short",
96+
maxDecimalPoints: 0,
97+
units: ["d", "h", "m", "s"],
98+
maxUnits: 4,
99+
})}
100+
</>
101+
);
102+
}

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.waitpoints.$waitpointFriendlyId.complete/route.tsx

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@ import { InformationCircleIcon } from "@heroicons/react/20/solid";
33
import { Form, useNavigation, useSubmit } from "@remix-run/react";
44
import { ActionFunctionArgs, json } from "@remix-run/server-runtime";
55
import { Waitpoint } from "@trigger.dev/database";
6+
import { motion } from "framer-motion";
67
import { useCallback, useRef } from "react";
78
import { z } from "zod";
9+
import { AnimatedHourglassIcon } from "~/assets/icons/AnimatedHourglassIcon";
810
import { CodeBlock } from "~/components/code/CodeBlock";
9-
import { InlineCode } from "~/components/code/InlineCode";
1011
import { JSONEditor } from "~/components/code/JSONEditor";
1112
import { Button } from "~/components/primitives/Buttons";
12-
import { Callout } from "~/components/primitives/Callout";
13-
import { Fieldset } from "~/components/primitives/Fieldset";
14-
import { Header3 } from "~/components/primitives/Headers";
15-
import { InputGroup } from "~/components/primitives/InputGroup";
16-
import { Label } from "~/components/primitives/Label";
13+
import { DateTime } from "~/components/primitives/DateTime";
1714
import { Paragraph } from "~/components/primitives/Paragraph";
15+
import { LiveCountdown } from "~/components/runs/v3/LiveTimer";
1816
import { prisma } from "~/db.server";
1917
import { useOrganization } from "~/hooks/useOrganizations";
2018
import { useProject } from "~/hooks/useProject";
2119
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
2220
import { logger } from "~/services/logger.server";
2321
import { requireUserId } from "~/services/session.server";
24-
import { cn } from "~/utils/cn";
2522
import { ProjectParamSchema, v3SchedulesPath } from "~/utils/pathBuilder";
2623
import { UpsertSchedule } from "~/v3/schedules";
2724
import { UpsertTaskScheduleService } from "~/v3/services/upsertTaskSchedule.server";
@@ -118,6 +115,8 @@ export function CompleteWaitpointForm({ waitpoint }: { waitpoint: FormWaitpoint
118115
[currentJson]
119116
);
120117

118+
const endTime = new Date(Date.now() + 60_000 * 113);
119+
121120
return (
122121
<div className="space-y-3">
123122
<Form
@@ -174,6 +173,43 @@ await wait.completeToken<YourType>(tokenId,
174173
);`}
175174
showLineNumbers={false}
176175
/>
176+
<Form
177+
action={formAction}
178+
method="post"
179+
onSubmit={(e) => submitForm(e)}
180+
className="grid h-full max-h-full grid-rows-[2.5rem_1fr_2.5rem] overflow-hidden rounded-md border border-grid-bright"
181+
>
182+
<div className="mx-3 flex items-center">
183+
<Paragraph variant="small/bright">Manually skip this waitpoint</Paragraph>
184+
</div>
185+
<div className="border-t border-grid-dimmed">
186+
<input type="hidden" name="type" value={waitpoint.type} />
187+
<div className="flex flex-wrap items-center justify-between gap-1 p-2 text-sm tabular-nums">
188+
<div className="flex items-center gap-1">
189+
<AnimatedHourglassIcon
190+
className="text-dimmed-dimmed size-4"
191+
delay={(endTime.getMilliseconds() - Date.now()) / 1000}
192+
/>
193+
<span className="mt-0.5 ">
194+
<LiveCountdown endTime={endTime} />
195+
</span>
196+
</div>
197+
<DateTime date={endTime} />
198+
</div>
199+
</div>
200+
<div className="px-2">
201+
<div className="mb-2 flex items-center justify-end gap-2 border-t border-grid-dimmed pt-2">
202+
<Button
203+
variant="secondary/small"
204+
type="submit"
205+
disabled={isLoading}
206+
LeadingIcon={isLoading ? "spinner" : undefined}
207+
>
208+
{isLoading ? "Completing…" : "Skip waitpoint"}
209+
</Button>
210+
</div>
211+
</div>
212+
</Form>
177213
</div>
178214
);
179215
}

packages/core/src/v3/utils/durations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type DurationOptions = {
88
style?: "long" | "short";
99
maxDecimalPoints?: number;
1010
units?: Unit[];
11+
maxUnits?: number;
1112
};
1213

1314
export function formatDuration(
@@ -48,7 +49,7 @@ export function formatDurationMilliseconds(
4849
? belowOneSecondUnits
4950
: aboveOneSecondUnits,
5051
maxDecimalPoints: options?.maxDecimalPoints ?? 1,
51-
largest: 2,
52+
largest: options?.maxUnits ?? 2,
5253
});
5354

5455
if (!options) {

0 commit comments

Comments
 (0)