feat: add routing support for view artwork page
This commit is contained in:
parent
77003926da
commit
550df8fb36
@ -15,7 +15,8 @@ const router = createBrowserRouter([
|
|||||||
{ path: "/toodle", Component: MyFurinaPage },
|
{ path: "/toodle", Component: MyFurinaPage },
|
||||||
{
|
{
|
||||||
path: "/treasures",
|
path: "/treasures",
|
||||||
children: [{ index: true, Component: ArtworksPage }],
|
Component: ArtworksPage,
|
||||||
|
children: [{ index: true }, { path: ":id" }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
ErrorBoundary: () => (
|
ErrorBoundary: () => (
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import pb from "@/utility/api";
|
import pb from "@/utility/api";
|
||||||
import { Howl } from "howler";
|
import { Howl } from "howler";
|
||||||
import { useInfiniteQuery } from "react-query";
|
import { useInfiniteQuery } from "react-query";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
import playIcon from "@/assets/icons/play-outline.svg";
|
import playIcon from "@/assets/icons/play-outline.svg";
|
||||||
import openingSfx from "@/assets/audio/VO_JA_Furina_Opening_Treasure_Chest_02.ogg";
|
import openingSfx from "@/assets/audio/VO_JA_Furina_Opening_Treasure_Chest_02.ogg";
|
||||||
import ViewSheet from "./viewSheet";
|
import ViewSheet from "./viewSheet";
|
||||||
import useModal from "@/hooks/useModal";
|
|
||||||
import LazyImage from "@/components/ui/LazyImage";
|
import LazyImage from "@/components/ui/LazyImage";
|
||||||
import PageMetadata from "@/components/containers/PageMetadata";
|
import PageMetadata from "@/components/containers/PageMetadata";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
@ -19,6 +18,9 @@ const openingChestSfx = new Howl({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ArtworksPage = () => {
|
const ArtworksPage = () => {
|
||||||
|
const { id: viewArtId } = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage } =
|
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage } =
|
||||||
useInfiniteQuery({
|
useInfiniteQuery({
|
||||||
queryKey: ["artworks"],
|
queryKey: ["artworks"],
|
||||||
@ -38,7 +40,6 @@ const ArtworksPage = () => {
|
|||||||
},
|
},
|
||||||
{ offset: 100 }
|
{ offset: 100 }
|
||||||
);
|
);
|
||||||
const viewItemModal = useModal<string>();
|
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
() => data?.pages.flatMap((i) => i.items) || [],
|
() => data?.pages.flatMap((i) => i.items) || [],
|
||||||
@ -47,7 +48,7 @@ const ArtworksPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container py-16">
|
<div className="container py-16">
|
||||||
<PageMetadata title="Treasures" />
|
<PageMetadata title={viewArtId ? "View Artwork" : "Treasures"} />
|
||||||
|
|
||||||
<h1 className="text-2xl">Treasures</h1>
|
<h1 className="text-2xl">Treasures</h1>
|
||||||
<div>
|
<div>
|
||||||
@ -69,13 +70,8 @@ const ArtworksPage = () => {
|
|||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<Link
|
<Link
|
||||||
key={item.id}
|
key={item.id}
|
||||||
// to={`/treasures/${item.id}`}
|
to={`/treasures/${item.id}`}
|
||||||
to="#"
|
|
||||||
className="bg-white rounded-lg shadow border border-gray-300 overflow-hidden hover:scale-105 transition-all relative"
|
className="bg-white rounded-lg shadow border border-gray-300 overflow-hidden hover:scale-105 transition-all relative"
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
viewItemModal.onOpen(item.id);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<LazyImage
|
<LazyImage
|
||||||
lazySrc={pb.files.getUrl(item, item.image, { thumb: "32x48" })}
|
lazySrc={pb.files.getUrl(item, item.image, { thumb: "32x48" })}
|
||||||
@ -111,7 +107,11 @@ const ArtworksPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<ViewSheet modal={viewItemModal} />
|
<ViewSheet
|
||||||
|
isOpen={viewArtId != null}
|
||||||
|
id={viewArtId}
|
||||||
|
onClose={() => navigate("/treasures")}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import Sheet from "@/components/ui/Sheet";
|
import Sheet from "@/components/ui/Sheet";
|
||||||
import useModal from "@/hooks/useModal";
|
|
||||||
import pb from "@/utility/api";
|
import pb from "@/utility/api";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import loadingIllust from "@/assets/images/l9fsdoa2j7vb1.gif";
|
import loadingIllust from "@/assets/images/l9fsdoa2j7vb1.gif";
|
||||||
@ -8,11 +7,12 @@ import Button from "@/components/ui/Button";
|
|||||||
import { ChevronLeft } from "lucide-react";
|
import { ChevronLeft } from "lucide-react";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
modal: ReturnType<typeof useModal<string>>;
|
id?: string | null;
|
||||||
|
isOpen?: boolean;
|
||||||
|
onClose: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ViewSheet = ({ modal }: Props) => {
|
const ViewSheet = ({ id, isOpen, onClose }: Props) => {
|
||||||
const id = modal.data;
|
|
||||||
const { data, isLoading, isError } = useQuery({
|
const { data, isLoading, isError } = useQuery({
|
||||||
queryKey: ["artwork", id],
|
queryKey: ["artwork", id],
|
||||||
queryFn: () => pb.collection("artworks").getOne(id || ""),
|
queryFn: () => pb.collection("artworks").getOne(id || ""),
|
||||||
@ -21,7 +21,12 @@ const ViewSheet = ({ modal }: Props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet
|
<Sheet
|
||||||
{...modal}
|
isOpen={isOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}}
|
||||||
title="View Item"
|
title="View Item"
|
||||||
position="bottom"
|
position="bottom"
|
||||||
className="md:rounded-t-none h-[90vh] md:h-screen"
|
className="md:rounded-t-none h-[90vh] md:h-screen"
|
||||||
@ -48,7 +53,7 @@ const ViewSheet = ({ modal }: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="md:w-1/3 border-t md:border-l md:border-t-0 py-4 md:pt-0 px-4 lg:px-8 overflow-y-auto">
|
<div className="md:w-1/3 border-t md:border-l md:border-t-0 py-4 md:pt-0 px-4 lg:px-8 overflow-y-auto">
|
||||||
<Button className="flex pl-2 mb-6" onClick={modal.onClose}>
|
<Button className="flex pl-2 mb-6" onClick={onClose}>
|
||||||
<ChevronLeft /> Back
|
<ChevronLeft /> Back
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user