[WIP] Migrate trade lists page to Next.js routing

We're getting so close! :3

There was some shared components in `UserItemListPage` that needed updated too, even though the rest of the page isn't migrated yet.
This commit is contained in:
Emi Matchu 2022-09-14 23:04:58 -07:00
parent 750ca208f1
commit e1ebb0eb9a
4 changed files with 40 additions and 42 deletions

View file

@ -0,0 +1,5 @@
import UserItemListsIndexPage from "../../../src/app/UserItemListsIndexPage";
export default function UserItemListsIndexPageWrapper() {
return <UserItemListsIndexPage />;
}

View file

@ -11,9 +11,6 @@ import WardrobePageLayout from "./WardrobePage/WardrobePageLayout";
import { loadable } from "./util"; import { loadable } from "./util";
const HomePage = loadable(() => import("./HomePage")); const HomePage = loadable(() => import("./HomePage"));
const UserItemListsIndexPage = loadable(() =>
import("./UserItemListsIndexPage")
);
const UserItemListPage = loadable(() => import("./UserItemListPage")); const UserItemListPage = loadable(() => import("./UserItemListPage"));
const WardrobePage = loadable(() => import("./WardrobePage"), { const WardrobePage = loadable(() => import("./WardrobePage"), {
fallback: <WardrobePageLayout />, fallback: <WardrobePageLayout />,
@ -42,11 +39,6 @@ function App() {
<UserItemListPage /> <UserItemListPage />
</PageLayout> </PageLayout>
</Route> </Route>
<Route path="/user/:userId/lists">
<PageLayout>
<UserItemListsIndexPage />
</PageLayout>
</Route>
<Route path="/"> <Route path="/">
<PageLayout hideHomeLink> <PageLayout hideHomeLink>
<HomePage /> <HomePage />

View file

@ -23,8 +23,9 @@ import {
EmailIcon, EmailIcon,
} from "@chakra-ui/icons"; } from "@chakra-ui/icons";
import { gql, useMutation, useQuery } from "@apollo/client"; import { gql, useMutation, useQuery } from "@apollo/client";
import { Link, useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { HashLink } from "react-router-hash-link"; import { HashLink } from "react-router-hash-link";
import Link from "next/link";
import { import {
List as VirtualizedList, List as VirtualizedList,
AutoSizer, AutoSizer,
@ -252,13 +253,11 @@ export function ClosetList({
{closetList.isDefaultList || headingVariant === "top-level" ? ( {closetList.isDefaultList || headingVariant === "top-level" ? (
closetList.name closetList.name
) : ( ) : (
<Box <Link href={buildClosetListPath(closetList)} passHref>
as={Link} <Box as="a" _hover={{ textDecoration: "underline" }}>
to={buildClosetListPath(closetList)}
_hover={{ textDecoration: "underline" }}
>
{closetList.name} {closetList.name}
</Box> </Box>
</Link>
)} )}
</Heading> </Heading>
))} ))}
@ -416,9 +415,9 @@ export function ClosetListContents({
<Box fontStyle="italic">This list is empty!</Box> <Box fontStyle="italic">This list is empty!</Box>
)} )}
{numMoreItems > 0 && ( {numMoreItems > 0 && (
<Link href={buildClosetListPath(closetList)} passHref>
<Box <Box
as={Link} as="a"
to={buildClosetListPath(closetList)}
display="flex" display="flex"
width="100%" width="100%"
alignItems="center" alignItems="center"
@ -439,6 +438,7 @@ export function ClosetListContents({
<ArrowForwardIcon /> <ArrowForwardIcon />
</Flex> </Flex>
</Box> </Box>
</Link>
)} )}
</Box> </Box>
); );

View file

@ -29,7 +29,7 @@ import {
StarIcon, StarIcon,
} from "@chakra-ui/icons"; } from "@chakra-ui/icons";
import gql from "graphql-tag"; import gql from "graphql-tag";
import { useHistory, useParams } from "react-router-dom"; import { useRouter } from "next/router";
import { useQuery, useLazyQuery, useMutation } from "@apollo/client"; import { useQuery, useLazyQuery, useMutation } from "@apollo/client";
import HangerSpinner from "./components/HangerSpinner"; import HangerSpinner from "./components/HangerSpinner";
@ -44,7 +44,8 @@ const BadgeButton = React.forwardRef((props, ref) => (
)); ));
function UserItemListsIndexPage() { function UserItemListsIndexPage() {
const { userId } = useParams(); const { query } = useRouter();
const { userId } = query;
const currentUser = useCurrentUser(); const currentUser = useCurrentUser();
const isCurrentUser = currentUser.id === userId; const isCurrentUser = currentUser.id === userId;
@ -317,7 +318,7 @@ function UserSearchForm() {
const [query, setQuery] = React.useState(""); const [query, setQuery] = React.useState("");
const { isSupportUser, supportSecret } = useSupport(); const { isSupportUser, supportSecret } = useSupport();
const history = useHistory(); const { push: pushHistory } = useRouter();
const toast = useToast(); const toast = useToast();
const [loadUserSearch, { loading: loading1 }] = useLazyQuery( const [loadUserSearch, { loading: loading1 }] = useLazyQuery(
@ -341,7 +342,7 @@ function UserSearchForm() {
return; return;
} }
history.push(`/user/${user.id}/lists`); pushHistory(`/user/${user.id}/lists`);
}, },
onError: (error) => { onError: (error) => {
console.error(error); console.error(error);