Skip to content

Commit

Permalink
feat: show calculated session duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobu committed Oct 5, 2024
1 parent 0acb9de commit dac1de9
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ArrowBigRight } from "lucide-react";
import { useForm } from "react-hook-form";

import { prefixBasedMatch } from "@/lib/searching";
import { showSelectedTagsFirst } from "@/lib/utils";
import { getFormattedTimeDifference, showSelectedTagsFirst } from "@/lib/utils";
import { queryKeys } from "@/components/hooks/queryHooks/queryKeys";
import { Button } from "@/components/shadcn/button";
import { Card, CardContent } from "@/components/shadcn/card";
Expand Down Expand Up @@ -66,6 +66,15 @@ const creationFormQuickOptions: QuickOption[] = [
},
];

const DurationLabel: FC<{ from?: Date, to?: Date }> = (props) => {
if (!props.from || !props.to) {
return <span>--:--</span>
}

const result = getFormattedTimeDifference(props.from, props.to)
return <span>{result}</span>
}

export const ScheduledSessionCreationForm: FC = () => {
const { toast } = useToast();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -141,7 +150,7 @@ export const ScheduledSessionCreationForm: FC = () => {
)}
/>

<div className="flex items-center">
<div className="flex items-center gap-4">
<FormField
name="startTime"
control={form.control}
Expand Down Expand Up @@ -171,7 +180,10 @@ export const ScheduledSessionCreationForm: FC = () => {
)}
/>

<ArrowBigRight className="m-10" />
<div className="flex flex-col items-center justify-center">
<DurationLabel from={form.watch("startTime")} to={form.watch("endTime")} />
<ArrowBigRight />
</div>

<FormField
name="endTime"
Expand Down

0 comments on commit dac1de9

Please sign in to comment.