Skip to content

Commit

Permalink
feat: display callendar with data range
Browse files Browse the repository at this point in the history
  • Loading branch information
mgierada committed Jun 16, 2024
1 parent 11b0a60 commit 18a5c39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 9 additions & 2 deletions ui/src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ const fetchCounter = async () => {
throw new Error("Failed to fetch data");
}

/** @type {CounterApiResponse} */
const data = await response.json();

if (!data) {
throw new Error("Invalid response data");
}

/** @type {Counter} */
const result = {
currentValue: data.CurrentValue,
updatedAt: data.UpdatedAt,
Expand All @@ -52,7 +54,7 @@ const fetchCounter = async () => {
};
return result;
} catch (error) {
console.error("Error fetching the current value:", error.message);
/** @type {Counter} */
return {
currentValue: null,
updatedAt: null,
Expand All @@ -69,6 +71,7 @@ const fetchCounter = async () => {
* @returns {JSX.Element} The Home component.
*/
const Home = async () => {
/** @type {Counter} */
const data = await fetchCounter();

return (
Expand All @@ -78,7 +81,11 @@ const Home = async () => {
<CounterDisplay currentValue={data.currentValue} error={data.error} />
</div>
<div className="flex flex-col items-center justify-center">
<Callendar className="mt-5" />
<Callendar
className="mt-5"
lastTimeReseted={data.resetedAt}
currentCouterValue={data.currentValue}
/>
</div>
</main>
);
Expand Down
9 changes: 4 additions & 5 deletions ui/src/components/Callendar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";

const Callendar = ({ className }) => {
const Callendar = ({ className, lastTimeReseted, currentCouterValue }) => {
const [date, setDate] = React.useState({
from: new Date(2022, 0, 20),
to: addDays(new Date(2022, 0, 20), 20),
from: lastTimeReseted || new Date(2024, 4, 13),
to: addDays(new Date(2024, 4, 13), currentCouterValue),
});

return (
<div className={cn("grid gap-2", className)}>
<Popover>
Expand Down Expand Up @@ -53,7 +52,7 @@ const Callendar = ({ className }) => {
defaultMonth={date?.from}
selected={date}
onSelect={() => {}}
numberOfMonths={2}
numberOfMonths={1}
disabled={() => true}
/>
</PopoverContent>
Expand Down

0 comments on commit 18a5c39

Please sign in to comment.