Skip to content

Commit

Permalink
Fix auth route handling interactions with theming
Browse files Browse the repository at this point in the history
  • Loading branch information
Willdotwhite committed Mar 21, 2024
1 parent ab8150d commit cac7787
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
19 changes: 16 additions & 3 deletions ui/src/common/components/JamSpecificStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ type Jam = {
expiry: number,
}

export const JamSpecificThemeContext = createContext<Jam>({
// Used on homepage etc. which don't have a theme
const defaultThemeContext: Jam = {
jamId: "",
logoLargeUrl: "",
logoStackedUrl: "",
styles: {},
expiry: Date.now()
})
}

export const JamSpecificThemeContext = createContext<Jam>(defaultThemeContext)

export const JamSpecificStyling: React.FC<{children: any}> = ({children}) => {
const jamId = useMatch("/:jamId/:postId?")?.params.jamId!!;
const [activeTheme, setActiveTheme] = useState<Jam>()

useEffect(() => {
if (!jamId) return

Expand All @@ -47,6 +49,17 @@ export const JamSpecificStyling: React.FC<{children: any}> = ({children}) => {

}, [jamId])

// Ignore theme handling for non-jam pages
// TODO: Fix this, it's just so so gross; should be fixed when a base site theme exists
console.log(window.location.pathname)
if (['/', '/about', '/login', '/login/authorized', '/logout'].includes(window.location.pathname)) {
return (
<JamSpecificThemeContext.Provider value={defaultThemeContext}>
{children}
</JamSpecificThemeContext.Provider>
)
}

// If searching for a jam by ID and not finding it:
if (jamId && activeTheme == null) {
return (<>No jam of that ID could be found</>)
Expand Down
6 changes: 3 additions & 3 deletions ui/src/pages/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Header: React.FC = () => {
<nav className="c-header">
<div className="sm:flex h-[40px]">
<div className="hidden sm:flex">
<Link to="/">
<Link to={`/${theme.jamId}`}>
<img src={theme.logoStackedUrl} width="40" height="40" alt={"jamName" + " Team Finder logo"} className="bg-black border border-white rounded-lg mr-2 hover:scale-125"/>
</Link>

Expand Down Expand Up @@ -67,7 +67,6 @@ const ToggleBookmarks: React.FC = () => {
icon: "🔒",
id: "favourite-post-view-info",
});
console.log("toast called")
return;
}

Expand Down Expand Up @@ -127,6 +126,7 @@ const MyPostButton: React.FC = () => {
}

const LoginLogout: React.FC = () => {
const theme = useContext(JamSpecificThemeContext)
const userInfo = useUserInfo();
const shouldDisplayLogin = !userInfo.data;

Expand All @@ -146,7 +146,7 @@ const LoginLogout: React.FC = () => {
return (
<p className="sm:mr-4 text-right inline-grid sm:inline text-xs sm:text-sm">
<span className="sm:block ml-auto w-[min-content]">Welcome&nbsp;{userInfo.data?.username as string}!</span>
<Link to="/logout" className="block sm:inline sm:ml-1 cursor-pointer hover:underline">
<Link to={`/logout?redirect=${theme.jamId}`} className="block sm:inline sm:ml-1 cursor-pointer hover:underline">
(Click here to logout)
</Link>
</p>
Expand Down
2 changes: 0 additions & 2 deletions ui/src/pages/jamhome/JamHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export const JamHome: React.FC = () => {
.then(setPosts)
}, [searchParams])

// console.log(posts)

return (
<main>
<Onboarding />
Expand Down
5 changes: 4 additions & 1 deletion ui/src/pages/logout/Logout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as React from "react";
import {useAuth, useAuthActions} from "../../api/AuthContext";
import {useSearchParams} from "react-router-dom";

export function Logout(): null {
const [searchParams] = useSearchParams()
const auth = useAuth();
const { logout } = useAuthActions();
const jamId = searchParams.get("redirect")

React.useEffect(() => {
if (auth) {
logout();
window.location.replace("/"); // Do a browser movement to refresh page and reload userInfo
window.location.replace(`/${jamId}`); // Do a browser movement to refresh page and reload userInfo
}
}, [auth, logout]);

Expand Down

0 comments on commit cac7787

Please sign in to comment.