Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix faulty session issues and login styles #1207

Open
wants to merge 1 commit into
base: new-systems-and-communites-rewrite-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/cyberstorm-remix/app/communities/communities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export default function CommunitiesPage() {
Communities
</NewBreadCrumbs>
<header className={rootStyles.pageHeader}>
<Heading level="1" styleLevel="2" variant="primary" mode="display">
<Heading
csLevel="1"
csStyleLevel="2"
csVariant="primary"
mode="display"
>
Communities
</Heading>
</header>
Expand Down
27 changes: 18 additions & 9 deletions apps/cyberstorm-remix/cyberstorm/dapper/sessionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { redirect } from "@remix-run/react";
import { DapperTs } from "@thunderstore/dapper-ts";
import { RequestConfig } from "@thunderstore/thunderstore-api";

export async function getDapper(isClient = false) {
if (isClient) {
const getCookie = (cookieName: string) =>
new RegExp(`${cookieName}=([^;]+);`).exec(document.cookie)?.[1];
const deleteCookie = (name: string) => {
const date = new Date();
date.setTime(0);
document.cookie = `${name}=${null}; expires=${date.toUTCString()}; path=/`;
};

const removeSession = () => {
deleteCookie("sessionid");
deleteCookie("csrftoken");
redirect("/communities");
};
const dapper = window.Dapper;

let shouldRemakeDapper = false;

// const allCookies = new URLSearchParams(
// window.document.cookie.replaceAll("&", "%26").replaceAll("; ", "&")
// );
// const cookie = allCookies.get("sessionid");
// const csrftoken = allCookies.get("csrftoken");
const cookie = null;
const csrftoken = null;
const cookie = getCookie("sessionid");
const csrftoken = getCookie("csrftoken");

const newConfig: RequestConfig = {
apiHost: window.ENV.PUBLIC_API_URL,
Expand Down Expand Up @@ -65,7 +74,7 @@ export async function getDapper(isClient = false) {
}

const createNewDapper = () => {
const newDapper = new DapperTs(newConfig);
const newDapper = new DapperTs(newConfig, removeSession);
window.Dapper = newDapper;
return newDapper;
};
Expand All @@ -75,7 +84,7 @@ export async function getDapper(isClient = false) {
? createNewDapper()
: dapper
? dapper
: new DapperTs(newConfig);
: new DapperTs(newConfig, removeSession);

return existingDapper;
} else {
Expand Down
30 changes: 20 additions & 10 deletions apps/cyberstorm-remix/cyberstorm/navigation/DesktopLoginPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import styles from "./Navigation.module.css";
import { Modal } from "@thunderstore/cyberstorm";
import { AvatarButton } from "@thunderstore/cyberstorm/src/components/Avatar/AvatarButton";
import { Modal, NewButton, NewIcon } from "@thunderstore/cyberstorm";
import { LoginList } from "./LoginList";
import { faArrowRightToBracket } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

export function DesktopLoginPopover() {
return (
<Modal
popoverId={"navAccount"}
trigger={
<AvatarButton
size="small"
popovertarget="navAccount"
popovertargetaction="open"
/>
<NewButton
csVariant="primary"
csColor="purple"
csSize="l"
rootClasses={styles.loginButton}
{...{
popovertarget: "navAccount",
popovertargetaction: "open",
}}
csTextStyles={["fontSizeS", "fontWeightBold", "lineHeightAuto"]}
>
<NewIcon csMode="inline" noWrapper>
<FontAwesomeIcon icon={faArrowRightToBracket} />
</NewIcon>
Log In
</NewButton>
}
>
<nav className={styles.mobileNavPopoverList}>
<LoginList />
</nav>
<LoginList />
</Modal>
);
}
153 changes: 77 additions & 76 deletions apps/cyberstorm-remix/cyberstorm/navigation/DesktopUserDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,96 +1,97 @@
import { faSignOut, faUsers, faCog } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import * as RadixDropDown from "@radix-ui/react-dropdown-menu";

import styles from "./Navigation.module.css";
import dropdownStyles from "../../../../packages/cyberstorm/src/newComponents/DropDown/DropDown.module.css";
import {
Avatar,
DropDownDivider,
DropDownItem,
CyberstormLink,
DropDown,
NewDropDown,
NewText,
NewDropDownItem,
NewDropDownDivider,
NewLink,
NewIcon,
} from "@thunderstore/cyberstorm";
import { DropDownLink } from "@thunderstore/cyberstorm/src/components/DropDown/DropDownLink";
import { emptyUser } from "@thunderstore/dapper-ts/src/methods/currentUser";
import { CurrentUser } from "@thunderstore/dapper/types";
import { getDapper } from "cyberstorm/dapper/sessionUtils";
import { useState, useEffect } from "react";
import { AvatarButton } from "@thunderstore/cyberstorm/src/components/Avatar/AvatarButton";
import { DesktopLoginPopover } from "./DesktopLoginPopover";
import { classnames } from "@thunderstore/cyberstorm/src/utils/utils";

export function DesktopUserDropdown() {
const [user, setUser] = useState<CurrentUser>(emptyUser);
const avatar = user.connections.find((c) => c.avatar !== null)?.avatar;

useEffect(() => {
const fetchAndSetUser = async () => {
const dapper = await getDapper(true);
const fetchedUser = await dapper.getCurrentUser();
setUser(fetchedUser);
};
fetchAndSetUser();
}, []);
export function DesktopUserDropdown(props: { user: CurrentUser }) {
const { user } = props;

if (!user.username) {
return <DesktopLoginPopover />;
}
const avatar = user.connections.find((c) => c.avatar !== null)?.avatar;

// REMIX TODO: Turn this into a popover
return (
<DropDown
<NewDropDown
contentAlignment="end"
trigger={
<AvatarButton src={avatar} username={user.username} size="small" />
}
content={[
<RadixDropDown.Item key="user">
<div className={styles.dropDownUserInfo}>
<Avatar src={avatar} username={user.username} size="small" />
<div className={styles.dropdownUserInfoDetails}>
<div className={styles.dropdownUserInfoDetails_userName}>
{user.username}
</div>
</div>
</div>
</RadixDropDown.Item>,

<DropDownDivider key="divider-first" />,

<CyberstormLink linkId="Settings" key="settings">
<DropDownItem
content={
<DropDownLink
leftIcon={<FontAwesomeIcon icon={faCog} />}
label="Settings"
/>
}
/>
</CyberstormLink>,

<CyberstormLink linkId="Teams" key="teams">
<DropDownItem
content={
<DropDownLink
leftIcon={<FontAwesomeIcon icon={faUsers} />}
label="Teams"
/>
}
/>
</CyberstormLink>,

<DropDownDivider key="divider-second" />,

<a href="/logout" key="logout">
<DropDownItem
content={
<DropDownLink
leftIcon={<FontAwesomeIcon icon={faSignOut} />}
label="Log Out"
/>
}
/>
</a>,
]}
/>
csVariant="default"
csColor="surface"
>
<NewDropDownItem rootClasses={styles.dropDownUserInfo}>
<Avatar src={avatar} username={user.username} size="small" />
<NewText rootClasses={styles.dropdownUserInfoDetails}>
{user.username}
</NewText>
</NewDropDownItem>
<NewDropDownDivider csVariant="default" csColor="surface" />
<NewDropDownItem asChild>
<NewLink
primitiveType="cyberstormLink"
linkId="Settings"
csVariant="default"
csColor="surface"
rootClasses={classnames(
dropdownStyles.dropdownItem,
styles.dropDownItem
)}
csTextStyles={["fontSizeS", "fontWeightRegular"]}
>
<NewIcon csMode="inline" noWrapper csVariant="tertiary">
<FontAwesomeIcon icon={faCog} />
</NewIcon>
Settings
</NewLink>
</NewDropDownItem>
<NewDropDownItem asChild>
<NewLink
primitiveType="cyberstormLink"
linkId="Teams"
csVariant="default"
csColor="surface"
rootClasses={classnames(
dropdownStyles.dropdownItem,
styles.dropDownItem
)}
csTextStyles={["fontSizeS", "fontWeightRegular"]}
>
<NewIcon csMode="inline" noWrapper csVariant="tertiary">
<FontAwesomeIcon icon={faUsers} />
</NewIcon>
Teams
</NewLink>
</NewDropDownItem>
<NewDropDownItem asChild>
<NewLink
primitiveType="link"
href="/logout"
csVariant="default"
csColor="surface"
rootClasses={classnames(
dropdownStyles.dropdownItem,
styles.dropDownItem
)}
csTextStyles={["fontSizeS", "fontWeightRegular"]}
>
<NewIcon csMode="inline" noWrapper csVariant="tertiary">
<FontAwesomeIcon icon={faSignOut} />
</NewIcon>
Log Out
</NewLink>
</NewDropDownItem>
</NewDropDown>
);
}
Loading
Loading