Skip to content

Commit

Permalink
feat: remove the choice of precision according to the days chosen (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordyBSK authored Jul 8, 2024
1 parent d8a64f5 commit d9a1758
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
18 changes: 7 additions & 11 deletions nextjs-interface/src/app/dashboard/esp/[espId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "@/lib/data";

// import libraries
import { endOfMonth, format, startOfMonth } from "date-fns";
import { differenceInDays, endOfWeek, format, startOfWeek } from "date-fns";
import { DateRange } from "react-day-picker";
import React, { useState } from "react";

Expand All @@ -39,8 +39,8 @@ export default function Page({ params }: { params: any }) {
const [date, setDate] = React.useState<DateRange | undefined>(() => {
const now = new Date();
return {
from: startOfMonth(now),
to: endOfMonth(now),
from: startOfWeek(now),
to: endOfWeek(now),
};
});

Expand Down Expand Up @@ -69,8 +69,9 @@ export default function Page({ params }: { params: any }) {

const handleSelect = (value: any) => {
setPrecision(value);
console.log(value);
};
const dateRangeInDays =
date?.from && date?.to ? differenceInDays(date.to, date.from) : 0;

return (
<div className="flex h-full w-full min-w-[500px] flex-col gap-y-5 pt-2">
Expand Down Expand Up @@ -104,16 +105,11 @@ export default function Page({ params }: { params: any }) {
</SelectItem>
<SelectItem
value="Hour"
className="cursor-pointer rounded-none border-t-2 border-secondary dark:border-gray-700"
className={`cursor-pointer rounded-none border-t-2 border-secondary dark:border-gray-700 ${dateRangeInDays > 7 ? "cursor-not-allowed opacity-50" : ""}`}
disabled={dateRangeInDays > 7}
>
Hour
</SelectItem>
<SelectItem
value="Minute"
className="cursor-pointer rounded-none border-t-2 border-secondary dark:border-gray-700"
>
Minute
</SelectItem>
</SelectContent>
</Select>
</div>
Expand Down
7 changes: 0 additions & 7 deletions nextjs-interface/src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const useFetchData = (
.then((response) => response.json())
.then((apiData: avgData[]) => {
setData(apiData);
console.log("useFetchData", apiData);
})
.catch((e) => {
console.error("Une erreur s'est produite :", e);
Expand All @@ -52,7 +51,6 @@ export function useLastData(type: string, ip: string) {
fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } })
.then((response) => response.json())
.then((apiData: data[]) => {
console.log("useLastData", apiData);
if (apiData && apiData.length > 0) {
if (type == "humidity") {
setValue(apiData[0].humidity);
Expand All @@ -76,7 +74,6 @@ export const useAllEsp = () => {
.then((response) => response.json())
.then((apiEsp: esp[]) => {
setEsp(apiEsp);
console.log("useAllEsp", apiEsp);
})
.catch((e) => {
console.error("Une erreur s'est produite :", e);
Expand All @@ -94,7 +91,6 @@ export default function useFindIpById(id: string) {
fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } })
.then((response) => response.json())
.then((apiIp: esp[]) => {
console.log("useFindIpByName", apiIp);
setIp(apiIp[0].ip);
})
.catch((e) => {
Expand All @@ -113,7 +109,6 @@ export function useFindNameById(id: string) {
fetch(url, { headers: { Authorization: `Bearer ${getToken()}` } })
.then((response) => response.json())
.then((apiIp: esp[]) => {
console.log("useFindIpByName", apiIp);
setName(apiIp[0].name);
})
.catch((e) => {
Expand All @@ -133,7 +128,6 @@ export function useAllUsers() {
.then((response) => response.json())
.then((apiUsers: user[]) => {
setUsers(apiUsers);
console.log("useAllusers", apiUsers);
})
.catch((e) => {
console.error("Une erreur s'est produite :", e);
Expand All @@ -152,7 +146,6 @@ export function GetEspPosition(id: string) {
.then((response) => response.json())
.then((apiPosition: esp[]) => {
setPosition(apiPosition);
console.log("GetEspPosition", apiPosition);
})
.catch((e) => {
console.error("Une erreur s'est produite :", e);
Expand Down

0 comments on commit d9a1758

Please sign in to comment.