-
Notifications
You must be signed in to change notification settings - Fork 82
feat(frontend): show estimated end date/time preview in CreateStreamF… #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,39 @@ export function CreateStreamForm({ | |
|
|
||
| const parsedApiError = apiError ? humaniseApiError(apiError) : null; | ||
|
|
||
| const startInMinsNum = Number(values.startInMinutes); | ||
| const durationHoursNum = Number(values.durationHours); | ||
| const estimatedEndLabel: string | null = (() => { | ||
| if ( | ||
| values.startInMinutes === "" || | ||
| values.durationHours === "" || | ||
| isNaN(startInMinsNum) || | ||
| isNaN(durationHoursNum) || | ||
| durationHoursNum < 1 || | ||
| !Number.isInteger(durationHoursNum) | ||
| ) { | ||
|
Comment on lines
+174
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear the preview when This guard only rejects invalid Suggested fix if (
values.startInMinutes === "" ||
values.durationHours === "" ||
isNaN(startInMinsNum) ||
isNaN(durationHoursNum) ||
+ startInMinsNum < 0 ||
+ !Number.isInteger(startInMinsNum) ||
durationHoursNum < 1 ||
!Number.isInteger(durationHoursNum)
) {
return null;
}🤖 Prompt for AI Agents |
||
| return null; | ||
| } | ||
| const nowSeconds = Math.floor(Date.now() / 1000); | ||
| const startAt = | ||
| startInMinsNum > 0 ? nowSeconds + Math.floor(startInMinsNum * 60) : nowSeconds; | ||
| const endAt = startAt + Math.floor(durationHoursNum * 3600); | ||
| const endDate = new Date(endAt * 1000); | ||
| const datePart = new Intl.DateTimeFormat("en-US", { | ||
| month: "short", | ||
| day: "numeric", | ||
| year: "numeric", | ||
| timeZone: "UTC", | ||
| }).format(endDate); | ||
| const timePart = new Intl.DateTimeFormat("en-US", { | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| hour12: false, | ||
| timeZone: "UTC", | ||
| }).format(endDate); | ||
| return `Ends: ${datePart} at ${timePart} UTC`; | ||
| })(); | ||
|
|
||
| return ( | ||
| <form onSubmit={handleSubmit} noValidate> | ||
| {parsedApiError && ( | ||
|
|
@@ -304,6 +337,78 @@ export function CreateStreamForm({ | |
| </div> | ||
| </div> | ||
|
|
||
| {/* Duration */} | ||
| <div | ||
| className={`field-group${errors.durationHours ? " field-group--error" : ""}`} | ||
| > | ||
| <label htmlFor="stream-duration"> | ||
| Duration (hours) | ||
| <span className="field-required" aria-hidden> | ||
| * | ||
| </span> | ||
| </label> | ||
| <input | ||
| id="stream-duration" | ||
| type="number" | ||
| min="1" | ||
| step="1" | ||
| value={values.durationHours} | ||
| onChange={set("durationHours")} | ||
| onBlur={blur("durationHours")} | ||
| onKeyDown={(e) => { | ||
| if (["e", "E", "+", "-", "."].includes(e.key)) e.preventDefault(); | ||
| }} | ||
| aria-describedby={ | ||
| errors.durationHours ? "duration-error" : "duration-hint" | ||
| } | ||
| aria-invalid={!!errors.durationHours} | ||
| required | ||
| /> | ||
| {estimatedEndLabel && ( | ||
| <span id="duration-hint" className="field-hint" aria-live="polite"> | ||
| {estimatedEndLabel} | ||
| </span> | ||
| )} | ||
| {errors.durationHours && ( | ||
| <span id="duration-error" className="field-error" role="alert"> | ||
| {errors.durationHours} | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Start In Minutes */} | ||
| <div | ||
| className={`field-group${errors.startInMinutes ? " field-group--error" : ""}`} | ||
| > | ||
| <label htmlFor="stream-start"> | ||
| Start In (minutes) | ||
| <span className="field-required" aria-hidden> | ||
| * | ||
| </span> | ||
| </label> | ||
| <input | ||
| id="stream-start" | ||
| type="number" | ||
| min="0" | ||
| step="1" | ||
| value={values.startInMinutes} | ||
| onChange={set("startInMinutes")} | ||
| onBlur={blur("startInMinutes")} | ||
| onKeyDown={(e) => { | ||
| if (["e", "E", "+", "-", "."].includes(e.key)) e.preventDefault(); | ||
| }} | ||
| aria-describedby={ | ||
| errors.startInMinutes ? "start-error" : "start-hint" | ||
| } | ||
| aria-invalid={!!errors.startInMinutes} | ||
| required | ||
| /> | ||
| <span id="start-hint" className="field-hint"> | ||
| Enter 0 to start immediately | ||
| </span> | ||
| {errors.startInMinutes && ( | ||
| <span id="start-error" className="field-error" role="alert"> | ||
| {errors.startInMinutes} | ||
| {/* Duration & Start In Minutes */} | ||
|
Danielodingz marked this conversation as resolved.
|
||
| <div className="row"> | ||
| <div | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.