Skip to content

Commit

Permalink
reset time button
Browse files Browse the repository at this point in the history
  • Loading branch information
rgodha24 committed Sep 21, 2023
1 parent 911864d commit 6a0748b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/web/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from "react";
import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown, MinusCircle, MinusIcon } from "lucide-react";
import { Check, ChevronDown } from "lucide-react";

import { cn } from "@/lib/utils";
import { Button } from "./button";

const Select = SelectPrimitive.Root;

Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/lib/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Values = {
type Functions = {
setStart: (date: Date | ((d: Date) => Date)) => void;
setEnd: (date: Date | ((d: Date) => Date)) => void;
setTimes: (start: Date, end: Date) => void;
};

export const datesStore = create<Values & Functions>((set) => ({
Expand Down Expand Up @@ -46,4 +47,7 @@ export const datesStore = create<Values & Functions>((set) => ({
return { end: date };
});
},
setTimes: (start, end) => {
set({ start, end });
},
}));
43 changes: 41 additions & 2 deletions packages/web/src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSignins } from "@/lib/useSignins";
import { useWsConnection } from "@/lib/ws";
import { useQuery } from "@tanstack/react-query";
import { useAtom } from "jotai";
import { RefreshCwIcon } from "lucide-react";
import { ClockIcon, RefreshCwIcon } from "lucide-react";
import { FC, useEffect, useMemo, useState } from "react";
import { useStore } from "zustand";
import { selectedClassAtom, scannerNameAtom } from "@/lib/atoms";
Expand All @@ -20,7 +20,8 @@ import {
Tooltip,
TooltipContent,
} from "@/components/ui/tooltip";
import { formatDistanceStrict } from "date-fns";
import { formatDistanceStrict, setHours, setMinutes } from "date-fns";
import { toast } from "@/components/ui/use-toast";

export type Class = {
name: string;
Expand Down Expand Up @@ -100,6 +101,7 @@ export const Home = () => {
return (
<>
<div className="flex flex-row gap-x-4 justify-between mx-4">
<ResetTimeButton />
<DateTimePicker date={start} setDate={setStart} />
<ClassSelect classes={classes.data} />
<ScannerSelect scanners={scanners.data} />
Expand All @@ -121,6 +123,43 @@ export const Home = () => {
);
};

const ResetTimeButton: FC<{}> = () => {
const { setTimes } = useStore(datesStore, ({ setTimes }) => ({ setTimes }));

return (
<div className="min-w-4">
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<Button
variant="outline"
className="flex-1 rounded-full group"
size="icon"
onClick={() => {
setTimes(
setMinutes(new Date(), new Date().getMinutes() - 10),
setHours(new Date(), new Date().getHours() + 1)
);
toast({
title: "reset time successfully",
});
}}
>
<ClockIcon className="h-4 min-w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>
reset time to starting at 10 minutes go and ending at 1 hour in
the future
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
);
};

const FetchFromServerButton: FC<{
onClick: () => void;
isSubmitting: boolean;
Expand Down

0 comments on commit 6a0748b

Please sign in to comment.