From 17cbc64273545086869e7ad273bb40047b5ca61d Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 25 Aug 2023 17:17:09 -0300 Subject: [PATCH 1/3] update browser route context location --- src/frontend/src/contexts/index.tsx | 3 +++ src/frontend/src/index.tsx | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/contexts/index.tsx b/src/frontend/src/contexts/index.tsx index 64142f942..acc7f4070 100644 --- a/src/frontend/src/contexts/index.tsx +++ b/src/frontend/src/contexts/index.tsx @@ -9,11 +9,13 @@ import { LocationProvider } from "./locationContext"; import { TabsProvider } from "./tabsContext"; import { TypesProvider } from "./typesContext"; import { UndoRedoProvider } from "./undoRedoContext"; +import { BrowserRouter } from "react-router-dom"; export default function ContextWrapper({ children }: { children: ReactNode }) { //element to wrap all context return ( <> + @@ -33,6 +35,7 @@ export default function ContextWrapper({ children }: { children: ReactNode }) { + ); } diff --git a/src/frontend/src/index.tsx b/src/frontend/src/index.tsx index 2542f4903..db196080b 100644 --- a/src/frontend/src/index.tsx +++ b/src/frontend/src/index.tsx @@ -17,10 +17,8 @@ const root = ReactDOM.createRoot( ); root.render( - - ); reportWebVitals(); From d2f5a5d56480373acf0654a5bee15f1461b41902 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 25 Aug 2023 17:21:54 -0300 Subject: [PATCH 2/3] moved api interceptor --- src/frontend/src/contexts/index.tsx | 2 ++ src/frontend/src/controllers/API/api.tsx | 1 - src/frontend/src/index.tsx | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/contexts/index.tsx b/src/frontend/src/contexts/index.tsx index acc7f4070..b213ace9d 100644 --- a/src/frontend/src/contexts/index.tsx +++ b/src/frontend/src/contexts/index.tsx @@ -10,6 +10,7 @@ import { TabsProvider } from "./tabsContext"; import { TypesProvider } from "./typesContext"; import { UndoRedoProvider } from "./undoRedoContext"; import { BrowserRouter } from "react-router-dom"; +import { ApiInterceptor } from "../controllers/API/api"; export default function ContextWrapper({ children }: { children: ReactNode }) { //element to wrap all context @@ -23,6 +24,7 @@ export default function ContextWrapper({ children }: { children: ReactNode }) { + {children} diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index fc4358ed0..0e74670b0 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -24,7 +24,6 @@ function ApiInterceptor() { async (error: AxiosError) => { if (error.response?.status === 401) { const refreshToken = cookies.get("refresh_token"); - if (refreshToken) { authenticationErrorCount = authenticationErrorCount + 1; if (authenticationErrorCount > 3) { diff --git a/src/frontend/src/index.tsx b/src/frontend/src/index.tsx index db196080b..3a7cbd9f5 100644 --- a/src/frontend/src/index.tsx +++ b/src/frontend/src/index.tsx @@ -18,7 +18,6 @@ const root = ReactDOM.createRoot( root.render( - ); reportWebVitals(); From 10ba3381e0c67eaef5e83c3d4ea1ef50bf5993f2 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Fri, 25 Aug 2023 17:48:39 -0300 Subject: [PATCH 3/3] Refactor: Move github stars context to darkContext --- .../src/components/headerComponent/index.tsx | 3 ++- src/frontend/src/contexts/authContext.tsx | 10 ---------- src/frontend/src/contexts/darkContext.tsx | 16 ++++++++++++++++ src/frontend/src/types/contexts/auth.ts | 2 -- src/frontend/src/types/typesContext/index.ts | 2 ++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/components/headerComponent/index.tsx b/src/frontend/src/components/headerComponent/index.tsx index 6b50313c4..1c780417b 100644 --- a/src/frontend/src/components/headerComponent/index.tsx +++ b/src/frontend/src/components/headerComponent/index.tsx @@ -18,7 +18,8 @@ export default function Header(): JSX.Element { const { dark, setDark } = useContext(darkContext); const { notificationCenter } = useContext(alertContext); const location = useLocation(); - const { logout, autoLogin, isAdmin, stars } = useContext(AuthContext); + const { logout, autoLogin, isAdmin } = useContext(AuthContext); + const { stars } = useContext(darkContext); const navigate = useNavigate(); return ( diff --git a/src/frontend/src/contexts/authContext.tsx b/src/frontend/src/contexts/authContext.tsx index 1fcfef58e..875ccc263 100644 --- a/src/frontend/src/contexts/authContext.tsx +++ b/src/frontend/src/contexts/authContext.tsx @@ -19,8 +19,6 @@ const initialValue: AuthContextType = { authenticationErrorCount: 0, autoLogin: false, setAutoLogin: () => {}, - stars: 0, - setStars: (stars) => 0, }; export const AuthContext = createContext(initialValue); @@ -32,7 +30,6 @@ export function AuthProvider({ children }): React.ReactElement { const [isAdmin, setIsAdmin] = useState(false); const [userData, setUserData] = useState(null); const [autoLogin, setAutoLogin] = useState(false); - const [stars, setStars] = useState(0); const cookies = new Cookies(); useEffect(() => { @@ -40,11 +37,6 @@ export function AuthProvider({ children }): React.ReactElement { if (storedAccessToken) { setAccessToken(storedAccessToken); } - async function fetchStars() { - const starsCount = await getRepoStars("logspace-ai", "langflow"); - setStars(starsCount); - } - fetchStars(); }, []); useEffect(() => { @@ -108,8 +100,6 @@ export function AuthProvider({ children }): React.ReactElement { // !! to convert string to boolean {}, + stars: 0, + setStars: (stars) => 0, }; export const darkContext = createContext(initialValue); @@ -12,6 +15,16 @@ export function DarkProvider({ children }) { const [dark, setDark] = useState( JSON.parse(window.localStorage.getItem("isDark")!) ?? false ); + const [stars, setStars] = useState(0); + + useEffect(() => { + async function fetchStars() { + const starsCount = await getRepoStars("logspace-ai", "langflow"); + setStars(starsCount); + } + fetchStars(); + }, []); + useEffect(() => { if (dark) { document.getElementById("body")!.classList.add("dark"); @@ -20,9 +33,12 @@ export function DarkProvider({ children }) { } window.localStorage.setItem("isDark", dark.toString()); }, [dark]); + return ( void; - stars: number; - setStars: (stars: number) => void; }; diff --git a/src/frontend/src/types/typesContext/index.ts b/src/frontend/src/types/typesContext/index.ts index 9e57822b9..fedb06341 100644 --- a/src/frontend/src/types/typesContext/index.ts +++ b/src/frontend/src/types/typesContext/index.ts @@ -44,6 +44,8 @@ export type alertContextType = { export type darkContextType = { dark: {}; setDark: (newState: {}) => void; + stars: number; + setStars: (stars: number) => void; }; export type locationContextType = {