From b6987a313edf6652287e46cbdadc2186937109b2 Mon Sep 17 00:00:00 2001 From: Carey Gumaer Date: Thu, 13 Feb 2025 16:24:42 -0500 Subject: [PATCH] fix pre-commit, linting and run it --- .eslintrc | 3 +- .pre-commit-config.yaml | 2 +- base-theme/assets/js/clients.ts | 12 ++++---- base-theme/assets/js/components/UserMenu.tsx | 29 ++++++++++++++------ base-theme/assets/js/user.ts | 29 ++++++++++++-------- course-v2/assets/course-v2.tsx | 9 ++++-- package.json | 2 +- www/assets/www.tsx | 9 ++++-- 8 files changed, 63 insertions(+), 32 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0e6192cae..3bcf9dd4e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,6 +17,7 @@ "@typescript-eslint/no-non-null-assertion": "off" }, "ignorePatterns": [ - "**/dist" + "**/dist", + "**/static_shared" ] } diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f9145d2f3..736632aec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,5 +11,5 @@ repos: - --exclude-files - README.md - --exclude-files - - .yarn/releases/yarn-3.1.0.cjs + - .yarn/releases/yarn-3.8.3.cjs exclude: .*_test.*|yarn\.lock diff --git a/base-theme/assets/js/clients.ts b/base-theme/assets/js/clients.ts index 3070fbb7e..b8d449299 100644 --- a/base-theme/assets/js/clients.ts +++ b/base-theme/assets/js/clients.ts @@ -15,8 +15,8 @@ const makeQueryClient = (): QueryClient => { defaultOptions: { queries: { refetchOnWindowFocus: false, - staleTime: Infinity, - onError: (error) => { + staleTime: Infinity, + onError: error => { const status = (error as MaybeHasStatus)?.response?.status if (THROW_ERROR_CODES.includes(status)) { throw error @@ -33,10 +33,10 @@ const makeQueryClient = (): QueryClient => { return failureCount < MAX_RETRIES } return false - }, - }, - }, + } + } + } }) } -export { makeQueryClient } \ No newline at end of file +export { makeQueryClient } diff --git a/base-theme/assets/js/components/UserMenu.tsx b/base-theme/assets/js/components/UserMenu.tsx index fd63638b9..e278088e4 100644 --- a/base-theme/assets/js/components/UserMenu.tsx +++ b/base-theme/assets/js/components/UserMenu.tsx @@ -1,8 +1,6 @@ import React from "react" -import { - RiAccountCircleFill, -} from "@remixicon/react" +import { RiAccountCircleFill } from "@remixicon/react" import { useUserMe } from "../user" @@ -26,25 +24,40 @@ export default function UserMenu() { ) -} \ No newline at end of file +} diff --git a/base-theme/assets/js/user.ts b/base-theme/assets/js/user.ts index d7f2f6af5..18a65a00a 100644 --- a/base-theme/assets/js/user.ts +++ b/base-theme/assets/js/user.ts @@ -1,36 +1,43 @@ import { useQuery } from "@tanstack/react-query" -import { Configuration, User as UserApi, UsersApi } from "@mitodl/open-api-axios/v0" +import { + Configuration, + User as UserApi, + UsersApi +} from "@mitodl/open-api-axios/v0" interface User extends Partial { - is_authenticated: boolean + isAuthenticated: boolean } const useUserMe = () => useQuery({ queryKey: ["userMe"], - queryFn: async (): Promise => { + queryFn: async (): Promise => { try { - const config = { basePath: process.env.MIT_LEARN_API_BASEURL, baseOptions: { withCredentials: true } } + const config = { + basePath: process.env.MIT_LEARN_API_BASEURL, + baseOptions: { withCredentials: true } + } const configuration = new Configuration({ - basePath: config.basePath, - baseOptions: config.baseOptions, + basePath: config.basePath, + baseOptions: config.baseOptions }) const usersApi = new UsersApi(configuration) const response = await usersApi.usersMeRetrieve() return { - is_authenticated: true, - ...response.data, + isAuthenticated: true, + ...response.data } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { if (error.response?.status === 403) { return { - is_authenticated: false, + isAuthenticated: false } } throw error } - }, + } }) -export { useUserMe } \ No newline at end of file +export { useUserMe } diff --git a/course-v2/assets/course-v2.tsx b/course-v2/assets/course-v2.tsx index 392ecb78d..241b4c88b 100644 --- a/course-v2/assets/course-v2.tsx +++ b/course-v2/assets/course-v2.tsx @@ -35,7 +35,12 @@ $(function() { const userMenuContainer = document.querySelector("#user-menu-container") if (userMenuContainer) { const queryClient = makeQueryClient() - ReactDOM.render(, userMenuContainer) + ReactDOM.render( + + + , + userMenuContainer + ) } }) @@ -45,4 +50,4 @@ window.initNanogallery2 = () => { if (nanogallery2Loaded) return import("./nanogallery2-imports.js") nanogallery2Loaded = true -} \ No newline at end of file +} diff --git a/package.json b/package.json index 5c9e8110d..8afc255d2 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "base-theme/assets/index.js", "packageManager": "yarn@3.8.3", "scripts": { - "lint": "eslint $PROJECT_CWD/'**/*.{js,jsx,ts,tsx}'", + "lint": "eslint $PROJECT_CWD/'**/*.{js,jsx,ts,tsx}' --fix", "start": "NODE_ENV=development ts-node ./package_scripts/start.ts", "start:webpack": "yarn with-env --dev -- webpack --config ./base-theme/assets/webpack/webpack.dev.ts --stats-children", "start:www": "echo This command has been removed. Use `yarn start www` instead.", diff --git a/www/assets/www.tsx b/www/assets/www.tsx index fbde54aa5..73efe9e02 100644 --- a/www/assets/www.tsx +++ b/www/assets/www.tsx @@ -35,7 +35,12 @@ $(function() { const userMenuContainer = document.querySelector("#user-menu-container") if (userMenuContainer) { const queryClient = makeQueryClient() - ReactDOM.render(, userMenuContainer) + ReactDOM.render( + + + , + userMenuContainer + ) } const searchPageEl = document.querySelector("#search-page") @@ -68,4 +73,4 @@ $(function() { initNotifications() setupEmailSignupForm() initSubNav() -}) \ No newline at end of file +})