Skip to content

Commit

Permalink
Merge pull request #10 from software-students-spring2024/update-frontend
Browse files Browse the repository at this point in the history
changed layout of game page
  • Loading branch information
zhaojustin authored Apr 23, 2024
2 parents 3beb36e + d37fa9c commit b23023a
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 96 deletions.
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"proxy": "http://localhost:5000",
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/core": "^11.0.0",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@testing-library/jest-dom": "^5.17.0",
Expand All @@ -14,6 +15,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.1.0",
"react-medium-image-zoom": "^5.2.0",
"react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
Expand Down
38 changes: 0 additions & 38 deletions frontend/src/Components/ArtifactViewer.js

This file was deleted.

126 changes: 126 additions & 0 deletions frontend/src/Pages/Game/ArtifactViewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { useEffect, useState } from "react";
import {
HStack,
VStack,
Image,
Spinner,
Box,
Text,
Center,
Icon,
} from "@chakra-ui/react";
import Zoom from "react-medium-image-zoom";
import "react-medium-image-zoom/dist/styles.css";
import { FiZoomIn } from "react-icons/fi";

export default function ArtifactViewer({ gameObjects, progression }) {
const [bigImgSrc, setBigImgSrc] = useState(gameObjects[0]["primaryImage"]);
const [loading, setLoading] = useState(true);

useEffect(() => {
setLoading(true);
setBigImgSrc(gameObjects[progression]["primaryImage"]);
setTimeout(() => {
setLoading(false);
}, 200);
}, [progression]);

return (
<HStack gap={5}>
{/* additional images */}
<VStack
maxH="500px"
overflowY="auto"
style={{ scrollBarWidth: "none", msOverflowStyle: "none" }}
>
<VStack gap={5}></VStack>
</VStack>

<HStack>
{/* image */}
{loading ? (
<Box h={400} w={400}>
<Center h="100%">
<Spinner size="lg" color="brand.700" />
</Center>
</Box>
) : (
<Zoom zoomMargin={400}>
<Image src={bigImgSrc} maxW={400} maxH={400} objectFit="contain" />
</Zoom>
)}
</HStack>

{/* image description */}
<VStack
borderRadius={20}
p={5}
px={10}
maxW={350}
gap={5}
alignItems="left"
>
{gameObjects[progression]["title"] && (
<VStack alignItems="left">
<Text color="gray.500" fontFamily="monospace">
Title
</Text>
<Text
fontSize={18}
fontWeight="600"
color="brand.700"
fontFamily="monospace"
>
{gameObjects[progression]["title"]}
</Text>
</VStack>
)}
{gameObjects[progression]["artistDisplayName"] && (
<VStack alignItems="left">
<Text color="gray.500" fontFamily="monospace">
Artist
</Text>
<Text
fontSize={18}
fontWeight="600"
color="brand.700"
fontFamily="monospace"
>
{gameObjects[progression]["artistDisplayName"]}
</Text>
</VStack>
)}
{gameObjects[progression]["medium"] && (
<VStack alignItems="left">
<Text color="gray.500" fontFamily="monospace">
Medium
</Text>
<Text
fontSize={18}
fontWeight="600"
color="brand.700"
fontFamily="monospace"
>
{gameObjects[progression]["medium"]}
</Text>
</VStack>
)}
{gameObjects[progression]["country"] && (
<VStack alignItems="left">
<Text color="gray.500" fontFamily="monospace">
Medium
</Text>
<Text
fontSize={18}
fontWeight="600"
color="brand.700"
fontFamily="monospace"
>
{gameObjects[progression]["country"]}
</Text>
</VStack>
)}
</VStack>
</HStack>
);
}
69 changes: 22 additions & 47 deletions frontend/src/Pages/Game/Game.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { useEffect, useState } from "react";
import {
VStack,
Center,
Text,
Spinner,
HStack,
Icon,
IconButton,
Box,
} from "@chakra-ui/react";
import { motion } from "framer-motion";
import { VStack, Center, Text, Spinner } from "@chakra-ui/react";

// import components
import ArtifactViewer from "../../Components/ArtifactViewer";
import { FiChevronLeft, FiChevronRight } from "react-icons/fi";
import FadeInUpBox from "../../Components/FadeUp";
import ArtifactViewer from "./ArtifactViewer";
import GameProgress from "./GameProgress";
import GuessingBox from "./GuessingBox";

export default function Game({ setStage, gameState, setGameState }) {
// loading states
Expand Down Expand Up @@ -84,41 +74,26 @@ export default function Game({ setStage, gameState, setGameState }) {
// return game content
return (
<VStack gap={10}>
<HStack alignItems="center">
{/* left arrow */}
<VStack position="absolute" left={25}>
<IconButton
colorScheme="brand"
borderRadius={25}
onClick={() => {
if (progression != 0) setProgression(progression - 1);
}}
icon={<Icon as={FiChevronLeft} />}
>
Last Item
</IconButton>
</VStack>
{/* top legend */}
<GameProgress
gameState={gameState}
setGameState={setGameState}
progression={progression}
setProgression={setProgression}
/>

{/* main content */}
<HStack>
<ArtifactViewer
gameObjects={gameState["gameObjects"]}
progression={progression}
/>
</HStack>
{/* main content */}
<ArtifactViewer
gameObjects={gameState["gameObjects"]}
progression={progression}
/>

{/* right arrow */}
<VStack position="absolute" right={25}>
<IconButton
colorScheme="brand"
borderRadius={25}
onClick={() => {
if (progression != 4) setProgression(progression + 1);
}}
icon={<Icon as={FiChevronRight} />}
></IconButton>
</VStack>
</HStack>
{/* guessor */}
<GuessingBox
gameState={gameState}
setGameState={setGameState}
progression={progression}
/>
</VStack>
);
}
102 changes: 102 additions & 0 deletions frontend/src/Pages/Game/GameProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Box, HStack, VStack, Icon, IconButton } from "@chakra-ui/react";
import { motion } from "framer-motion";
import { useEffect } from "react";
import {
FiCheckCircle,
FiChevronLeft,
FiChevronRight,
FiCircle,
} from "react-icons/fi";

export default function GameProgress({
gameState,
setGameState,
progression,
setProgression,
}) {
return (
<HStack gap={10} position="absolute" top={20}>
<motion.div
initial={{ opacity: 0, x: 15 }} // start state
animate={{ opacity: 1, x: 0 }} // end state
transition={{
duration: 1.2,
delay: 0.6,
ease: [0.6, -0.05, 0.01, 0.99],
}}
>
<IconButton
colorScheme="brand"
boxShadow="md"
borderRadius={25}
onClick={() => {
if (progression != 0) setProgression(progression - 1);
}}
icon={<Icon as={FiChevronLeft} />}
/>
</motion.div>

<motion.div
initial={{ opacity: 0, y: -25 }} // start state
animate={{ opacity: 1, y: 0 }} // end state
transition={{
duration: 1.2,
delay: 0.4,
ease: [0.6, -0.05, 0.01, 0.99],
}}
>
<VStack bg="white" p={5} borderRadius={20} boxShadow="lg" width={300}>
<HStack>
{gameState["playerGuessed"].map((guessed, index) => {
return (
<VStack w={8} key={index}>
{guessed ? (
<Icon
as={FiCheckCircle}
boxSize={7}
color={index == progression ? "yellow.500" : "brand.500"}
onClick={() => {
setProgression(index);
}}
_hover={{ cursor: "pointer" }}
/>
) : (
<Icon
as={FiCircle}
boxSize={7}
color={index == progression ? "yellow.500" : "gray.500"}
onClick={() => {
setProgression(index);
}}
_hover={{ cursor: "pointer" }}
/>
)}
</VStack>
);
})}
</HStack>
</VStack>
</motion.div>

<motion.div
initial={{ opacity: 0, x: -15 }} // start state
animate={{ opacity: 1, x: 0 }} // end state
transition={{
duration: 1.2,
delay: 0.6,
ease: [0.6, -0.05, 0.01, 0.99],
}}
>
<IconButton
colorScheme="brand"
boxShadow="md"
borderRadius={25}
onClick={() => {
if (progression != 4) setProgression(progression + 1);
}}
icon={<Icon as={FiChevronRight} />}
/>
</motion.div>
</HStack>
);
}
Loading

0 comments on commit b23023a

Please sign in to comment.