Skip to content

Commit

Permalink
Merge branch 'stuysu:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
willpill authored Jan 22, 2025
2 parents 72c95e9 + 012fe89 commit aa69217
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/comps/context/UserProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { useEffect } from "react";
import React, { useEffect, useState, useContext } from "react";
import { supabase } from "../../supabaseClient";
import UserContext from "./UserContext";
import { useSnackbar } from "notistack";
import { ThemeContext } from "./ThemeProvider";

const UserProvider = ({ children }: { children: React.ReactNode }) => {
const { enqueueSnackbar } = useSnackbar();
const { colorMode } = useContext(ThemeContext);
const [loading, setLoading] = useState(true);

const [value, setValue] = React.useState<UserContextType>({
signed_in: false,
Expand Down Expand Up @@ -79,6 +82,7 @@ const UserProvider = ({ children }: { children: React.ReactNode }) => {
"Error logging in. Contact it@stuysu.org for support.",
{ variant: "error" },
);
setLoading(false);
return;
}

Expand All @@ -90,6 +94,7 @@ const UserProvider = ({ children }: { children: React.ReactNode }) => {
"Unverified account. Please contact it@stuysu.org for support.",
{ variant: "error" },
);
setLoading(false);
return;
}

Expand Down Expand Up @@ -130,6 +135,7 @@ const UserProvider = ({ children }: { children: React.ReactNode }) => {
"Error fetching permissions. Contact it@stuysu.org for support.",
{ variant: "error" },
);
setLoading(false);
}
if (Array.isArray(data) && data?.length > 0) {
isAdmin = true;
Expand All @@ -150,6 +156,7 @@ const UserProvider = ({ children }: { children: React.ReactNode }) => {
"Unable to save profile picture to server. Please contact it@stuysu.org for support.",
{ variant: "error" },
);
setLoading(false);
}

enqueueSnackbar("Profile Picture Updated!", {
Expand All @@ -176,11 +183,24 @@ const UserProvider = ({ children }: { children: React.ReactNode }) => {
active: user.active,
});
}
setLoading(false);
};

getUser();
}, [enqueueSnackbar]);

if (loading) {
return (
<div
style={{
backgroundColor: colorMode ? "#0c161b" : "#ebf5f2",
width: "100vw",
height: "100vh",
}}
/>
);
}

return (
<UserContext.Provider value={value}>{children}</UserContext.Provider>
);
Expand Down
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import UserProvider from "./comps/context/UserProvider";

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement,
);
root.render(<App />);
root.render(
<UserProvider>
<App />
</UserProvider>,
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down

0 comments on commit aa69217

Please sign in to comment.