From 14b7eafc9ec2f40a2a34fae6e0d973ef4f030e0d Mon Sep 17 00:00:00 2001 From: Rajat Saxena Date: Wed, 9 Oct 2024 00:28:06 +0530 Subject: [PATCH] CodeQL fixes --- apps/web/app/dashboard2/profile/page.tsx | 43 ++++++++++++--------- apps/web/app/dashboard2/users/[id]/page.tsx | 2 +- apps/web/app/dashboard2/users/users-hub.tsx | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/web/app/dashboard2/profile/page.tsx b/apps/web/app/dashboard2/profile/page.tsx index dab2805d8..b3e56417f 100644 --- a/apps/web/app/dashboard2/profile/page.tsx +++ b/apps/web/app/dashboard2/profile/page.tsx @@ -29,7 +29,7 @@ import { PROFILE_SECTION_DETAILS_NAME, PROFILE_SECTION_DISPLAY_PICTURE, } from "@ui-config/strings"; -import { FormEvent, useContext, useState } from "react"; +import { FormEvent, useContext, useEffect, useState } from "react"; export default function Page() { const [bio, setBio] = useState(""); @@ -42,8 +42,9 @@ export default function Page() { const profile = useContext(ProfileContext); const address = useContext(AddressContext); - const getUser = async function (userId: string) { - const query = ` + useEffect(() => { + const getUser = async function (userId: string) { + const query = ` query { user: getUser(userId: "${userId}") { name, @@ -63,25 +64,29 @@ export default function Page() { } } `; - const fetch = new FetchBuilder() - .setUrl(`${address.backend}/api/graph`) - .setPayload(query) - .setIsGraphQLEndpoint(true) - .build(); + const fetch = new FetchBuilder() + .setUrl(`${address.backend}/api/graph`) + .setPayload(query) + .setIsGraphQLEndpoint(true) + .build(); - try { - const response = await fetch.exec(); - if (response.user) { - setUser(response.user); - setName(response.user.name); - setBio(response.user.bio); - setAvatar(response.user.avatar); - setSubscribedToUpdates(response.user.subscribedToUpdates); + try { + const response = await fetch.exec(); + if (response.user) { + setUser(response.user); + setName(response.user.name); + setBio(response.user.bio); + setAvatar(response.user.avatar); + setSubscribedToUpdates(response.user.subscribedToUpdates); + } + } catch (err: any) { + console.error(`Profile page: ${err.message}`); } - } catch (err: any) { - console.error(`Profile page: ${err.message}`); + }; + if (profile.userId && address.backend) { + getUser(profile.userId); } - }; + }, [profile, address.backend]); const updateProfilePic = async (media?: Media) => { const mutation = ` diff --git a/apps/web/app/dashboard2/users/[id]/page.tsx b/apps/web/app/dashboard2/users/[id]/page.tsx index 06ba57b91..2a5643a0c 100644 --- a/apps/web/app/dashboard2/users/[id]/page.tsx +++ b/apps/web/app/dashboard2/users/[id]/page.tsx @@ -24,7 +24,7 @@ import { useCallback, useContext, useEffect, useState } from "react"; export default function Page({ params }: { params: { id: string } }) { const [userData, setUserData] = useState(); - const [enrolledCourses, setEnrolledCourses] = useState([]); + const [_, setEnrolledCourses] = useState([]); const [tags, setTags] = useState([]); const address = useContext(AddressContext); const { id } = params; diff --git a/apps/web/app/dashboard2/users/users-hub.tsx b/apps/web/app/dashboard2/users/users-hub.tsx index 2a8c8a815..7ddc7bfab 100644 --- a/apps/web/app/dashboard2/users/users-hub.tsx +++ b/apps/web/app/dashboard2/users/users-hub.tsx @@ -43,7 +43,7 @@ export default function UsersHub() { const tab = searchParams?.get("tab") || "Users"; const [page, setPage] = useState(1); - const [rowsPerPage, setRowsPerPage] = useState(10); + const [rowsPerPage, _] = useState(10); const [users, setUsers] = useState([]); const [filters, setFilters] = useState([]); const [filtersAggregator, setFiltersAggregator] =