add animations and play/pause button to item page
This commit is contained in:
parent
ffe9d25b1c
commit
d52849c7a2
2 changed files with 28 additions and 3 deletions
|
@ -5,6 +5,7 @@ import {
|
||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
Box,
|
Box,
|
||||||
|
IconButton,
|
||||||
Skeleton,
|
Skeleton,
|
||||||
SkeletonText,
|
SkeletonText,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
|
@ -22,6 +23,7 @@ import {
|
||||||
StarIcon,
|
StarIcon,
|
||||||
WarningIcon,
|
WarningIcon,
|
||||||
} from "@chakra-ui/icons";
|
} from "@chakra-ui/icons";
|
||||||
|
import { MdPause, MdPlayArrow } from "react-icons/md";
|
||||||
import gql from "graphql-tag";
|
import gql from "graphql-tag";
|
||||||
import { useQuery } from "@apollo/client";
|
import { useQuery } from "@apollo/client";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
@ -39,6 +41,7 @@ import {
|
||||||
} from "./components/useOutfitAppearance";
|
} from "./components/useOutfitAppearance";
|
||||||
import OutfitPreview from "./components/OutfitPreview";
|
import OutfitPreview from "./components/OutfitPreview";
|
||||||
import SpeciesColorPicker from "./components/SpeciesColorPicker";
|
import SpeciesColorPicker from "./components/SpeciesColorPicker";
|
||||||
|
import { useLocalStorage } from "./util";
|
||||||
|
|
||||||
function ItemPage() {
|
function ItemPage() {
|
||||||
const { itemId } = useParams();
|
const { itemId } = useParams();
|
||||||
|
@ -539,6 +542,9 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [hasAnimations, setHasAnimations] = React.useState(false);
|
||||||
|
const [isPaused, setIsPaused] = useLocalStorage("DTIOutfitIsPaused", true);
|
||||||
|
|
||||||
const borderColor = useColorModeValue("green.700", "green.400");
|
const borderColor = useColorModeValue("green.700", "green.400");
|
||||||
const errorColor = useColorModeValue("red.600", "red.400");
|
const errorColor = useColorModeValue("red.600", "red.400");
|
||||||
|
|
||||||
|
@ -575,7 +581,25 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
spinnerVariant="corner"
|
spinnerVariant="corner"
|
||||||
loadingDelayMs={2000}
|
loadingDelayMs={2000}
|
||||||
|
engine="canvas"
|
||||||
|
onChangeHasAnimations={setHasAnimations}
|
||||||
/>
|
/>
|
||||||
|
{hasAnimations && (
|
||||||
|
<IconButton
|
||||||
|
icon={isPaused ? <MdPlayArrow /> : <MdPause />}
|
||||||
|
aria-label={isPaused ? "Play" : "Pause"}
|
||||||
|
onClick={() => setIsPaused(!isPaused)}
|
||||||
|
borderRadius="full"
|
||||||
|
boxShadow="md"
|
||||||
|
color="gray.50"
|
||||||
|
backgroundColor="blackAlpha.700"
|
||||||
|
position="absolute"
|
||||||
|
bottom="2"
|
||||||
|
left="2"
|
||||||
|
_hover={{ backgroundColor: "blackAlpha.900" }}
|
||||||
|
_focus={{ backgroundColor: "blackAlpha.900" }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
<Box display="flex" width="100%" alignItems="center">
|
<Box display="flex" width="100%" alignItems="center">
|
||||||
|
|
|
@ -119,7 +119,7 @@ export function OutfitLayers({
|
||||||
}, [loadingDelayMs, loadingAnything]);
|
}, [loadingDelayMs, loadingAnything]);
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
function computeAndSizeCanvasSize() {
|
function computeAndSaveCanvasSize() {
|
||||||
setCanvasSize(
|
setCanvasSize(
|
||||||
Math.min(
|
Math.min(
|
||||||
containerRef.current.offsetWidth,
|
containerRef.current.offsetWidth,
|
||||||
|
@ -128,8 +128,9 @@ export function OutfitLayers({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", computeAndSizeCanvasSize);
|
computeAndSaveCanvasSize();
|
||||||
return () => window.removeEventListener("resize", computeAndSizeCanvasSize);
|
window.addEventListener("resize", computeAndSaveCanvasSize);
|
||||||
|
return () => window.removeEventListener("resize", computeAndSaveCanvasSize);
|
||||||
}, [setCanvasSize]);
|
}, [setCanvasSize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue