Skip to content

Commit

Permalink
🚨 Next linter
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Dec 9, 2024
1 parent d9ce37d commit e852322
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const compat = new FlatCompat({
export default [
...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"next"
),
{
plugins: {
Expand Down
14 changes: 4 additions & 10 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<HTMLInputElement>): void =>
setUsername(e.target.value);

Expand All @@ -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" });
}
}
};
Expand Down
25 changes: 10 additions & 15 deletions src/pages/fireplace/[mac].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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 () => {
Expand All @@ -42,30 +36,31 @@ 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.`,
});
} else if (
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
Expand All @@ -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.",
});
Expand All @@ -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.",
});
Expand Down

0 comments on commit e852322

Please sign in to comment.