Skip to content

Commit

Permalink
feat(router): adjusting for rr7
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Jan 4, 2025
1 parent 0a57c59 commit b156389
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 218 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"react-redux": "^9.2.0",
"react-refresh": "^0.16.0",
"react-router": "^7.0.2",
"react-router-dom": "^7.0.2",
"react-select": "^5.9.0",
"react-share": "^5.1.1",
"react-split-pane": "^0.1.92",
Expand Down
4 changes: 1 addition & 3 deletions src/components/console/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ConsoleWriteContext = createContext(undefined);
export const ConsoleProvider = ({
children
}: {
children: React.ReactElement;
children: React.ReactElement | React.ReactNode;
}) => {
const [logs, setLogs]: [string[], any] = useState([""]);

Expand Down Expand Up @@ -46,5 +46,3 @@ export const useSetConsole = (): string[] | undefined => {
}
return context;
};

export default useConsole;
2 changes: 1 addition & 1 deletion src/components/cs-logo/cs-logo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import styled from "@emotion/styled";
import Tooltip from "@mui/material/Tooltip";
import { Link } from "react-router-dom";
import { Link } from "react-router";

interface ILogoContainer {
size: number;
Expand Down
2 changes: 1 addition & 1 deletion src/components/file-tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export const FileTree = ({
const currentTabDocumentUid = useSelector(selectCurrentTabDocumentUid);

const filelist = values(documents || {});
console.log(stateDnD, project, currentTabDocumentUid);

return (
<React.Fragment>
{stateDnD && project && currentTabDocumentUid && (
Expand Down
11 changes: 5 additions & 6 deletions src/components/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { RefObject, useState, useRef } from "react";
import { RootState, useDispatch, useSelector } from "@root/store";
import { selectCurrentRoute } from "@comp/router/selectors";
import { selectIsOwner } from "@comp/project-editor/selectors";
import {
selectUserImageURL,
Expand All @@ -11,7 +10,7 @@ import AppBar from "@mui/material/AppBar";
import Login from "@comp/login/login";
import * as loginActions from "@comp/login/actions";
import CSLogo from "@comp/cs-logo/cs-logo";
import { Link } from "react-router-dom";
import { Link, useLocation } from "react-router";
import {
Toolbar,
IconButton,
Expand Down Expand Up @@ -49,13 +48,13 @@ export const Header = () => {
(store: RootState) => store.ProjectsReducer.activeProjectUid
);

const currentRoute = useSelector(selectCurrentRoute);
const currentRoute = useLocation();

const routeIsHome = currentRoute === "home";
const routeIsHome = currentRoute.pathname === "/";

const routeIsEditor = currentRoute === "editor";
const routeIsEditor = currentRoute.pathname.startsWith("/editor");

const routeIsProfile = currentRoute === "profile";
const routeIsProfile = currentRoute.pathname.startsWith("/profile");

const isOwner = useSelector(selectIsOwner);

Expand Down
2 changes: 1 addition & 1 deletion src/components/header/project-profile-meta.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { useSelector } from "react-redux";
import { Link } from "react-router-dom";
import { Link } from "react-router";
import { formatDistance } from "date-fns";
import { selectActiveProject } from "@comp/projects/selectors";
import { selectProjectLastModified } from "@comp/project-last-modified/selectors";
Expand Down
32 changes: 1 addition & 31 deletions src/components/home/home-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
// import { TextField, IconButton, Grid } from "@mui/material";
import { Link } from "react-router-dom";
import { Link } from "react-router";
import styled from "@emotion/styled";
// import styled, { createGlobalStyle } from "styled-components";
// import { Gradient } from "./gradient";
import { headerHeight } from "@styles/constants";

// export const GlobalStyle = createGlobalStyle`
// body {
// ${Gradient}
// }
// `;

export const StyledGrid = styled.div`
&& {
background-color: black;
Expand All @@ -37,27 +28,6 @@ export const StyledTextField = styled.div`
}
`;

// interface IAnimatedGridContainer {
// duration: number;
// }

// export const AnimatedGridContainer = styled(Grid)<IAnimatedGridContainer>`
// position: relative;
// transition: all ${(properties) => properties.duration}ms;

// &.entering {
// opacity: 0;
// transform: translate(30px);
// }
// &.entered {
// opacity: 1;
// }
// &.exiting {
// opacity: 0;
// transform: translate(30px);
// }
// `;

interface IProjectCard {
duration: number;
projectIndex: number;
Expand Down
2 changes: 1 addition & 1 deletion src/components/hot-keys/hot-keys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CommandKey = keyof IHotKeysCallbacks;
const HotKeys = ({
children
}: {
children: React.ReactElement;
children: React.ReactElement | React.ReactElement[];
}): React.ReactElement => {
// prevent leak into the manual iframe
const insideIframe = !!window.frameElement;
Expand Down
14 changes: 8 additions & 6 deletions src/components/main/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { useDispatch } from "@root/store";
import { isMobile } from "@root/utils";
import Router from "@comp/router/router";
import { WebIdeRouter } from "@comp/router/router";
import ThemeProvider from "@styles/theme-provider";
import Modal from "@comp/modal";
import IosWarning from "./ios-warning";
Expand All @@ -12,6 +12,7 @@ import {
thirdPartyAuthSuccess
} from "@comp/login/actions";
import { getAuth } from "firebase/auth";
import { ConsoleProvider } from "@comp/console/context";
import HotKeys from "@comp/hot-keys/hot-keys";

const Main = () => {
Expand Down Expand Up @@ -59,13 +60,14 @@ const Main = () => {

return (
<ThemeProvider>
<Router>
<>
<ConsoleProvider>
<HotKeys>
<Modal />
<IosWarning />
<Snackbar />
</>
</Router>
<WebIdeRouter />
</HotKeys>
</ConsoleProvider>
</ThemeProvider>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/manual/manual.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Link, useParams } from "react-router-dom";
import { Link, useParams } from "react-router";
import { DebounceInput } from "react-debounce-input";
import { css } from "@emotion/react";
import { doc, getDoc } from "firebase/firestore";
Expand Down
2 changes: 1 addition & 1 deletion src/components/profile/profile-lists.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Link } from "react-router-dom";
import { Link } from "react-router";
import { useDispatch, useSelector } from "@root/store";
import { List, ListItem, ListItemText } from "@mui/material";
import { FollowingList } from "./tabs/following-list";
Expand Down
44 changes: 7 additions & 37 deletions src/components/profile/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isMobile, updateBodyScroller } from "@root/utils";
import { gradient } from "./gradient";
import { usernames } from "@config/firestore";
import { push } from "connected-react-router";
import { useLocation, useParams } from "react-router";
import { createButtonAddIcon } from "./styles";
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
Expand All @@ -30,7 +31,6 @@ import {
selectLoginRequesting,
selectLoggedInUid
} from "@comp/login/selectors";
import { selectCurrentProfileRoute } from "@comp/router/selectors";
import {
uploadProfileImage,
addProject,
Expand Down Expand Up @@ -80,37 +80,13 @@ const UserLink = ({ link }: { link: string | undefined }) => {
<></>
);
};
const routerLocationToProfileUriPath = (
location: Location | undefined
): [string | undefined, string | undefined] => {
if (!location) {
return [undefined, undefined];
}
const { pathname } = location;

if (pathname.startsWith("/profile/")) {
const woPrefix = pathname.slice(9); // Remove "/profile/"
const [woPostfix, nested] = woPrefix.split("/", 2);

if (nested) {
return [woPostfix, nested];
} else {
return [woPostfix, undefined];
}
}

return [undefined, undefined];
};

export const Profile = () => {
const [profileUid, setProfileUid]: [string | undefined, any] = useState();
const theme = useTheme();
const dispatch = useDispatch();
const location: Location | undefined = useSelector(
selectCurrentProfileRoute
) as any;
const [username, profileUriPath] = routerLocationToProfileUriPath(location);

const { username, tab } = useParams();
const profile = useSelector(selectUserProfile(profileUid));
const imageUrl = useSelector(selectUserImageURL(profileUid));
const loggedInUserUid = useSelector(selectLoggedInUid);
Expand Down Expand Up @@ -139,23 +115,17 @@ export const Profile = () => {

useEffect(() => {
if (username) {
if (!profileUriPath && selectedSection !== 0) {
if (!tab && selectedSection !== 0) {
setSelectedSection(0);
} else if (
profileUriPath === "following" &&
selectedSection !== 1
) {
} else if (tab === "following" && selectedSection !== 1) {
setSelectedSection(1);
} else if (
profileUriPath === "followers" &&
selectedSection !== 2
) {
} else if (tab === "followers" && selectedSection !== 2) {
setSelectedSection(2);
} else if (profileUriPath === "stars" && selectedSection !== 3) {
} else if (tab === "stars" && selectedSection !== 3) {
setSelectedSection(3);
}
}
}, [profileUriPath, selectedSection, username]);
}, [tab, selectedSection, username]);

useEffect(() => {
if (!isRequestingLogin) {
Expand Down
8 changes: 2 additions & 6 deletions src/components/projects/project-context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { Audio as AudioSpinner } from "react-loader-spinner";
import { useParams } from "react-router-dom";
import { useParams } from "react-router";
import { push } from "connected-react-router";
import { Theme, useTheme } from "@emotion/react";
// import { IStore } from "@store/types";
Expand All @@ -15,15 +15,11 @@ import { UnknownAction } from "redux";
import { RootState } from "@root/store";
import * as SS from "./styles";

interface IProjectContextProperties {
match: any;
}

const ForceBackgroundColor = ({ theme }: { theme: Theme }) => (
<style>{`body {background-color: ${theme.background}}`}</style>
);

export const ProjectContext = (properties: IProjectContextProperties) => {
export const ProjectContext = () => {
const dispatch = useDispatch();
const theme = useTheme();
const routeParams: { id?: string } = useParams();
Expand Down
Loading

0 comments on commit b156389

Please sign in to comment.