From e852322597f0e9c5dcf52c374b71b562a53d7886 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 9 Dec 2024 16:11:14 +0100 Subject: [PATCH] :rotating_light: Next linter https://nextjs.org/docs/app/api-reference/config/eslint --- eslint.config.mjs | 3 ++- src/components/Login.tsx | 14 ++++---------- src/pages/fireplace/[mac].tsx | 25 ++++++++++--------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index a38b091..aa4ad62 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -19,7 +19,8 @@ const compat = new FlatCompat({ export default [ ...compat.extends( "eslint:recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "next" ), { plugins: { diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 017cb14..06376ef 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -1,8 +1,8 @@ import { signIn } from "edilkamin"; -import React, { useCallback, useContext, useState } from "react"; +import React, { useContext, useState } from "react"; import { Button, Form } from "react-bootstrap"; -import { ErrorContext, ErrorType } from "../context/error"; +import { ErrorContext } from "../context/error"; import { TokenContext } from "../context/token"; import { setTokenLocalStorage } from "../utils/helpers"; @@ -12,12 +12,6 @@ const Login = () => { const { setToken } = useContext(TokenContext); const { addError } = useContext(ErrorContext); - const addErrorCallback = useCallback( - (error: ErrorType) => addError(error), - - [] - ); - const onUsernameChange = (e: React.ChangeEvent): void => setUsername(e.target.value); @@ -32,9 +26,9 @@ const Login = () => { } catch (error: unknown) { console.error(error); if (error instanceof Error) { - addErrorCallback({ title: "Couldn't login", body: error.message }); + addError({ title: "Couldn't login", body: error.message }); } else { - addErrorCallback({ body: "Unknown login error" }); + addError({ body: "Unknown login error" }); } } }; diff --git a/src/pages/fireplace/[mac].tsx b/src/pages/fireplace/[mac].tsx index d491427..e807fb4 100644 --- a/src/pages/fireplace/[mac].tsx +++ b/src/pages/fireplace/[mac].tsx @@ -2,14 +2,14 @@ import axios from "axios"; import { configure, DeviceInfoType } from "edilkamin"; import { NextPage } from "next"; import { useRouter } from "next/router"; -import { useCallback, useContext, useEffect, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { Accordion, Col, Row } from "react-bootstrap"; import DebugInfo from "../../components/DebugInfo"; import DeviceDetails from "../../components/DeviceDetails"; import PowerToggle from "../../components/PowerToggle"; import TemperatureAdjuster from "../../components/TemperatureAdjuster"; -import { ErrorContext, ErrorType } from "../../context/error"; +import { ErrorContext } from "../../context/error"; import { TokenContext } from "../../context/token"; const Fireplace: NextPage = () => { @@ -24,12 +24,6 @@ const Fireplace: NextPage = () => { const baseUrl = "/api/proxy/"; const { deviceInfo, setPower, setTargetTemperature } = configure(baseUrl); - const addErrorCallback = useCallback( - (error: ErrorType) => addError(error), - - [] - ); - useEffect(() => { if (!mac || !token) return; const fetch = async () => { @@ -42,7 +36,7 @@ const Fireplace: NextPage = () => { } catch (error: unknown) { console.error(error); if (axios.isAxiosError(error) && error?.response?.status === 404) { - addErrorCallback({ + addError({ title: "Device not found", body: `The address provided ("${mac}") is invalid or the device is not registered.`, }); @@ -50,22 +44,23 @@ const Fireplace: NextPage = () => { axios.isAxiosError(error) && error?.response?.data?.message !== undefined ) { - addErrorCallback({ + addError({ title: "Couldn't fetch device info.", body: error.response.data.message, }); } else if (error instanceof Error) { - addErrorCallback({ + addError({ title: "Couldn't fetch device info.", body: error.message, }); } else { - addErrorCallback({ body: "Couldn't fetch device info." }); + addError({ body: "Couldn't fetch device info." }); } } }; fetch(); - }, [addErrorCallback, mac, token]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [mac, token]); const onPowerChange = async (value: number) => { // set the state before hand to avoid the lag feeling @@ -74,7 +69,7 @@ const Fireplace: NextPage = () => { await setPower(token!, mac!, value); } catch (error) { console.error(error); - addErrorCallback({ + addError({ title: "Power State Update Failed", body: "Unable to change the power state. Please try again.", }); @@ -90,7 +85,7 @@ const Fireplace: NextPage = () => { await setTargetTemperature(token!, mac!, newTemperature); } catch (error) { console.error(error); - addErrorCallback({ + addError({ title: "Temperature Update Failed", body: "Unable to update the temperature. Please try again.", });