Skip to content

Commit

Permalink
whole lotta eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed May 6, 2024
1 parent 7a60961 commit 1928c76
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 91 deletions.
7 changes: 3 additions & 4 deletions dashboard/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"@typescript-eslint/no-explicit-any": ["off"],
"react-refresh/only-export-components": ["off"],
"react-hooks/exhaustive-deps": ["off"],
},
};
7 changes: 7 additions & 0 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.11.0",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
Expand Down
26 changes: 1 addition & 25 deletions dashboard/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./App.css";
import React, { useReducer } from "react";
import React from "react";
import axios from "axios";
import { MAPACHE_API_URL } from "./consts/config";
import { Button } from "./components/ui/button";
Expand All @@ -11,42 +11,18 @@ import {
getAxiosErrorMessage,
} from "./lib/axios-error-handler";
import { useNavigate } from "react-router-dom";
import { checkCredentials } from "./lib/auth";

function App() {
const navigate = useNavigate();
const [, forceUpdate] = useReducer((x) => x + 1, 0);

const [connected, setConnected] = React.useState(false);
const [pingResponse, setPingResponse] = React.useState<any>({});

const [loginLoading, setLoginLoading] = React.useState(false);
const [loginEmail, setLoginEmail] = React.useState("");
const [loginPassword, setLoginPassword] = React.useState("");

React.useEffect(() => {
init();
checkVpnConnection();
const interval = setInterval(() => {
// checkVpnConnection();
}, 1000);

return () => clearInterval(interval);
}, []);

const checkVpnConnection = async () => {
try {
const response = await axios.get(`${MAPACHE_API_URL}/ping`);
if (response.status == 200) {
setConnected(true);
setPingResponse(response.data);
}
} catch (error) {
setConnected(false);
return;
}
};

const init = async () => {
if (
localStorage.getItem("id") != null &&
Expand Down
2 changes: 0 additions & 2 deletions dashboard/src/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Separator } from "./ui/separator";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/consts/config.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User, initUser } from "@/models/user";

export var currentUser: User = initUser;
export const currentUser: User = initUser;

export const MAPACHE_API_URL =
import.meta.env.VITE_MAPACHE_API_URL ?? "http://localhost:7001";
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const checkCredentials = async () => {
return 1;
} else if (currentUser.id == "") {
try {
var userId = localStorage.getItem("id");
const userId = localStorage.getItem("id");
const response = await axios.get(`${MAPACHE_API_URL}/users/${userId}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
Expand Down
22 changes: 11 additions & 11 deletions dashboard/src/models/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ export interface User {
roles: string[];
}

function setUser(user: User, userInput: any): void {
user.id = userInput.id || user.id;
user.firstName = userInput.firstName || user.firstName;
user.lastName = userInput.lastName || user.lastName;
user.email = userInput.email || user.email;
user.subteam = userInput.subteam || user.subteam;
user.createdAt = userInput.createdAt || user.createdAt;
user.updatedAt = userInput.updatedAt || user.updatedAt;
user.roles = userInput.roles || user.roles;
}
// function setUser(user: User, userInput: any): void {
// user.id = userInput.id || user.id;
// user.firstName = userInput.firstName || user.firstName;
// user.lastName = userInput.lastName || user.lastName;
// user.email = userInput.email || user.email;
// user.subteam = userInput.subteam || user.subteam;
// user.createdAt = userInput.createdAt || user.createdAt;
// user.updatedAt = userInput.updatedAt || user.updatedAt;
// user.roles = userInput.roles || user.roles;
// }

export var initUser = {
export const initUser = {
id: "",
firstName: "",
lastName: "",
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/pages/auth/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function RegisterPage() {
navigate("/");
}
try {
var userId = localStorage.getItem("id");
const userId = localStorage.getItem("id");
const response = await axios.get(`${MAPACHE_API_URL}/users/${userId}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
Expand Down Expand Up @@ -81,7 +81,7 @@ function RegisterPage() {
return;
setCreateAccountLoading(true);
try {
var userId = localStorage.getItem("id");
const userId = localStorage.getItem("id");
const response = await axios.post(
`${MAPACHE_API_URL}/users/${userId}`,
{
Expand Down
7 changes: 1 addition & 6 deletions dashboard/src/pages/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import React from "react";
import axios from "axios";
import { Loader2 } from "lucide-react";
import { useToast } from "@/components/ui/use-toast";
import { MAPACHE_API_URL, currentUser } from "@/consts/config";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { useNavigate } from "react-router-dom";
import { checkCredentials } from "@/lib/auth";
Expand All @@ -12,7 +8,6 @@ import GR24PedalLiveWidget from "../gr24/pedal/PedalLiveWidget";
import { Card } from "@/components/ui/card";

function DashboardPage() {
const { toast } = useToast();
const navigate = useNavigate();
const [loading, setLoading] = React.useState(true);

Expand All @@ -21,7 +16,7 @@ function DashboardPage() {
}, []);

const init = async () => {
var status = await checkCredentials();
const status = await checkCredentials();
if (status != 0) {
navigate("/auth/register");
} else {
Expand Down
26 changes: 4 additions & 22 deletions dashboard/src/pages/gr24/pedal/PedalDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import axios from "axios";
import { Loader2 } from "lucide-react";
import { useToast } from "@/components/ui/use-toast";
import {
LineChart,
Line,
CartesianGrid,
XAxis,
YAxis,
Tooltip,
} from "recharts";
import React, { useCallback } from "react";
import { checkCredentials } from "@/lib/auth";
import { useNavigate } from "react-router-dom";
Expand All @@ -17,30 +7,22 @@ import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";

function PedalDetailsPage() {
const { toast } = useToast();
const navigate = useNavigate();
const [loading, setLoading] = React.useState(true);

const [socketUrl, setSocketUrl] = React.useState(
"ws://localhost:7001/ws/gr24/pedal",
);
const [messageHistory, setMessageHistory] = React.useState([]);
const [socketUrl] = React.useState("ws://localhost:7001/ws/gr24/pedal");
const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl);

const [jsonData, setJsonData] = React.useState([{}]);

React.useEffect(() => {
init();
if (lastMessage !== null) {
setMessageHistory((prev) => prev.concat(lastMessage));
if (messageHistory.length > 999) {
setMessageHistory([]);
}
setJsonData((prev) => [
...prev.concat(JSON.parse(lastMessage.data)).slice(-100),
]);
}
}, [lastMessage, setMessageHistory]);
}, [lastMessage]);

const handleClickSendMessage = useCallback(() => sendMessage("Hello"), []);

Expand All @@ -54,7 +36,7 @@ function PedalDetailsPage() {

const init = async () => {
const currentRoute = window.location.pathname + window.location.search;
var status = await checkCredentials();
const status = await checkCredentials();
if (status != 0) {
navigate(`/auth/register?route=${currentRoute}`);
} else {
Expand Down Expand Up @@ -133,7 +115,7 @@ function PedalDetailsPage() {
</div>
<div className="m-4 w-1/2 text-wrap text-start text-slate-500">
<h1 className="text-xl text-white">
Message Count: {messageHistory.length}
Message Count: {jsonData.length}
</h1>
{jsonData.reverse().map((message, idx) => (
<div key={idx}>{JSON.stringify(message)}</div>
Expand Down
18 changes: 1 addition & 17 deletions dashboard/src/pages/gr24/pedal/PedalLiveWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,12 @@ import useWebSocket, { ReadyState } from "react-use-websocket";
import { Progress } from "@/components/ui/progress";
import { Separator } from "@/components/ui/separator";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faCircleCheck,
faCircleXmark,
} from "@fortawesome/free-regular-svg-icons";
import { faCircleXmark } from "@fortawesome/free-regular-svg-icons";

function GR24PedalLiveWidget() {
const [socketUrl] = React.useState("ws://localhost:7001/ws/gr24/pedal");
const { lastMessage, readyState } = useWebSocket(socketUrl);

React.useEffect(() => {
if (lastMessage !== null) {
}
}, [lastMessage]);

const connectionStatus = {
[ReadyState.CONNECTING]: "Connecting",
[ReadyState.OPEN]: "Open",
[ReadyState.CLOSING]: "Closing",
[ReadyState.CLOSED]: "Closed",
[ReadyState.UNINSTANTIATED]: "Uninstantiated",
}[readyState];

const LoadingComponent = () => {
if (readyState === ReadyState.CONNECTING) {
return (
Expand Down

0 comments on commit 1928c76

Please sign in to comment.