-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alma and Wen - Labyrinth project #3
base: main
Are you sure you want to change the base?
Changes from all commits
7a20f30
3a43436
8721c7b
ca9c973
c7d924c
6eff1a0
813a73f
a9931b2
b83111a
e5939c8
60c5c48
be06687
8654f36
be8d675
6170ec8
99d939f
160bc49
3a978ff
5471e8d
90879c4
abe5287
228264f
88c43a0
c05dc41
19259df
0a0e02c
a92cdc3
9d250d0
cb4ad7b
0d8c4b4
8d79870
e8638ce
00ca49a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,13 @@ | ||
<h1 align="center"> | ||
<a href=""> | ||
<img src="./src/assets/banner.svg" alt="Project Banner Image"> | ||
</a> | ||
</h1> | ||
|
||
# Labyrinth - Zustand Project | ||
|
||
Replace this readme with your own information about your project. | ||
|
||
Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
|
||
## Getting Started with the Project | ||
|
||
### Dependency Installation & Startup Development Server | ||
|
||
Once cloned, navigate to the project's root directory and this project uses npm (Node Package Manager) to manage its dependencies. | ||
|
||
The command below is a combination of installing dependencies, opening up the project on VS Code and it will run a development server on your terminal. | ||
|
||
```bash | ||
npm i && code . && npm run dev | ||
``` | ||
In this pair project, we built a text based adventure using Zustand for state management and an API from Technigo to post data. | ||
|
||
### The Problem | ||
|
||
Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
We approached the problem by laying out the components and stores we needed. We then ensured that the API calls worked as intended. We identified the states that should be defined globally with Zustand and used them in the components. As a next step, we made sure to implement a user-friendly design that would allow the user to quickly understand what to do. | ||
|
||
### View it live | ||
If we had more time we would look into more of the stretch goals. | ||
|
||
Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
|
||
## Instructions | ||
### View it live | ||
|
||
<a href="instructions.md"> | ||
See instructions of this project | ||
</a> | ||
https://alma-wen-labyrinth.netlify.app/ |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { FirstPage } from "./components/FirstPage"; | ||
|
||
export const App = () => { | ||
return ( | ||
<div> | ||
Labyrinth Project | ||
</div> | ||
<> | ||
<FirstPage /> | ||
</> | ||
); | ||
}; |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this font! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useEffect } from "react"; | ||
import { useLabyrinthStore } from "../stores/useLabyrinthStore"; | ||
import "../style/ActionPage.css"; | ||
|
||
export const ActionPage = ({ changeBgImg }) => { | ||
const { coordinates, description, actions, makeMove, restart } = | ||
useLabyrinthStore(); | ||
|
||
// useEffect that runs on mount of the component and changes the bg img | ||
useEffect(() => { | ||
changeBgImg(coordinates); | ||
}, [changeBgImg, coordinates]); | ||
|
||
return ( | ||
<div className="action-container"> | ||
<p>{description}</p> | ||
<div className="button-container"> | ||
{actions.map((action, index) => ( | ||
<button | ||
className="action-button" | ||
value={action.direction} | ||
key={index} | ||
onClick={e => { | ||
const direction = e.target.value; | ||
makeMove(direction); | ||
}} | ||
> | ||
{action.direction} | ||
</button> | ||
))} | ||
</div> | ||
<button | ||
className="restart-button" | ||
type="button" | ||
onClick={() => { | ||
restart(); | ||
// change background back to start page | ||
changeBgImg("start"); | ||
}} | ||
> | ||
Restart | ||
</button> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useRef, useState } from "react" | ||
import { useLabyrinthStore } from "../stores/useLabyrinthStore" | ||
import { ActionPage } from "./ActionPage" | ||
import { LoadingAnimation } from "./LoadingAnimation" | ||
import "../style/FirstPage.css" | ||
|
||
export const FirstPage = () => { | ||
// create ref for main container div | ||
const bgImgRef = useRef() | ||
|
||
const { loggedIn, startGame, loading } = useLabyrinthStore() | ||
const [userInput, setUserInput] = useState("") | ||
const handleSubmit = (e) => { | ||
e.preventDefault() | ||
setUserInput("") | ||
startGame(userInput) | ||
} | ||
|
||
// function that changes the background img | ||
const changeBgImg = (coordinates) => { | ||
// replace the url for each coordinate | ||
bgImgRef.current.style.backgroundImage = `url('${coordinates}.jpeg')` | ||
} | ||
|
||
if (loading) { | ||
return <LoadingAnimation /> | ||
} | ||
|
||
return ( | ||
<div | ||
ref={bgImgRef} | ||
className="main-container" | ||
style={{ backgroundColor: "gray" }}> | ||
{loggedIn ? ( | ||
<ActionPage changeBgImg={changeBgImg} /> | ||
) : ( | ||
<div className="start-container"> | ||
<h1 className="heading">Labyrinth</h1> | ||
<h2 className="subheading"> | ||
Dare to tread the labyrinth's enigmatic paths, where secrets | ||
lurk in every shadow. | ||
</h2> | ||
<p className="description"> | ||
Are you ready to uncover the secrets of the labyrinth? Embark on the | ||
journey and find out. | ||
</p> | ||
<form className="form" onSubmit={handleSubmit}> | ||
<label htmlFor="userName">Adventurer name:</label> | ||
<input | ||
id="userName" | ||
type="text" | ||
value={userInput} | ||
onChange={(e) => setUserInput(e.target.value)} | ||
/> | ||
<button | ||
className="submit-btn" | ||
disabled={userInput ? false : true} | ||
type="submit"> | ||
Start | ||
</button> | ||
</form> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice loading animation you found! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useEffect, useRef } from "react" | ||
import lottie from "lottie-web" | ||
import loadingCompass from "../assets/animations/loading-compass.json" | ||
import "../style/LoadingAnimation.css" | ||
|
||
export const LoadingAnimation = () => { | ||
const container = useRef(null) | ||
|
||
useEffect(() => { | ||
const anim = lottie.loadAnimation({ | ||
container: container.current, | ||
renderer: "svg", | ||
loop: true, | ||
autoplay: true, | ||
animationData: loadingCompass, | ||
}) | ||
|
||
return () => { | ||
anim.destroy() | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div className="loading-container" style={{ backgroundColor: "gray" }}> | ||
<div className="loading-animation" ref={container}></div> | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for fragments when you're only returning one element