diff --git a/.env b/.env
new file mode 100644
index 0000000..8917459
--- /dev/null
+++ b/.env
@@ -0,0 +1 @@
+VITE_API_URL=http://localhost:8787
\ No newline at end of file
diff --git a/src/components/game/Game.tsx b/src/components/game/Game.tsx
index 39a8317..4dff6c0 100644
--- a/src/components/game/Game.tsx
+++ b/src/components/game/Game.tsx
@@ -4,20 +4,22 @@ import { Grid2 as Grid, Card, CardContent, CardHeader } from '@mui/material'
import { Score, Gitcoin } from '@/components/game/core'
import { Skills } from '@/components/game/skills'
import { Store } from '@/components/game/store'
-import { loop } from '@/modules/game'
-
-import { useDispatch } from 'react-redux'
+import { loop, start, stop } from '@/modules/game'
+import { useAppDispatch } from '@/store'
export function Game() {
- const dispatch = useDispatch()
+ const dispatch = useAppDispatch()
useEffect(() => {
+ dispatch(start())
const interval = setInterval(() => {
dispatch(loop())
}, 100)
- return () => clearInterval(interval)
- // eslint-disable-next-line react-hooks/exhaustive-deps
+ return () => {
+ clearInterval(interval)
+ dispatch(stop())
+ }
}, [])
return (
diff --git a/src/components/game/__tests__/Game.test.tsx b/src/components/game/__tests__/Game.test.tsx
index 40d874f..0503706 100644
--- a/src/components/game/__tests__/Game.test.tsx
+++ b/src/components/game/__tests__/Game.test.tsx
@@ -8,6 +8,12 @@ describe('Game', () => {
lines: 6,
linesPerMillisecond: 2,
skills: {},
+ items: [{
+ id: 1,
+ name: 'Bash',
+ price: 10,
+ linesPerMillisecond: 0.1,
+ }],
},
}
@@ -17,6 +23,7 @@ describe('Game', () => {
expect(screen.getByText(/per second: 20/)).toBeInTheDocument()
expect(screen.getByText(/Skills/)).toBeInTheDocument()
expect(screen.getByText(/Store/)).toBeInTheDocument()
+ expect(screen.getByText(/Bash/)).toBeInTheDocument()
await screen.findByText(/8 lines/, undefined, { timeout: 150 })
await screen.findByText(/10 lines/, undefined, { timeout: 150 })
diff --git a/src/components/game/core/__tests__/Score.test.tsx b/src/components/game/core/__tests__/Score.test.tsx
index 81cd73a..03c88f6 100644
--- a/src/components/game/core/__tests__/Score.test.tsx
+++ b/src/components/game/core/__tests__/Score.test.tsx
@@ -4,7 +4,7 @@ import { render, screen } from '@/test-setup'
describe('Score', () => {
it('should display the number of lines', () => {
const initialState = {
- game: { lines: 6, linesPerMillisecond: 2, skills: {} },
+ game: { lines: 6, linesPerMillisecond: 2, skills: {}, items: [] },
}
render(, { preloadedState: initialState })
diff --git a/src/components/game/skills/Section.tsx b/src/components/game/skills/Section.tsx
index 2913797..6f89edb 100644
--- a/src/components/game/skills/Section.tsx
+++ b/src/components/game/skills/Section.tsx
@@ -1,5 +1,7 @@
-import { items } from '@/constants/items'
+import { RootState } from '@/store'
+import getItemIcon from '@/utils/getItemIcon'
import { Box, Grid2 as Grid, Typography } from '@mui/material'
+import { useSelector } from 'react-redux'
type Props = {
itemName: string
@@ -7,6 +9,7 @@ type Props = {
}
export const Section = ({ itemName, number }: Props) => {
+ const items = useSelector((state: RootState) => state.game.items)
const item = items.find(element => element.name === itemName)
if (item == null) {
@@ -22,7 +25,7 @@ export const Section = ({ itemName, number }: Props) => {
key={index}
>
{
it('displays the owned skills', () => {
- render()
+ const initialState = {
+ game: {
+ lines: 6,
+ linesPerMillisecond: 2,
+ skills: {},
+ items: [{
+ id: 1,
+ name: 'Bash',
+ price: 10,
+ linesPerMillisecond: 0.1,
+ }],
+ },
+ }
+ render(, { preloadedState: initialState })
expect(screen.getByText('Bash')).toBeInTheDocument()
expect(screen.getAllByAltText('Bash')).toHaveLength(3)
diff --git a/src/components/game/skills/__tests__/Skills.test.tsx b/src/components/game/skills/__tests__/Skills.test.tsx
index 0056f74..0a6db4a 100644
--- a/src/components/game/skills/__tests__/Skills.test.tsx
+++ b/src/components/game/skills/__tests__/Skills.test.tsx
@@ -1,5 +1,6 @@
import { render, screen } from '@/test-setup'
import { Skills } from '../Skills'
+import { items } from '@/utils/__mocks__/items.mock'
describe('Skills', () => {
it('renders correctly', () => {
@@ -8,6 +9,7 @@ describe('Skills', () => {
lines: 6,
linesPerMillisecond: 2,
skills: { Bash: 2, Git: 3, Javascript: 4 },
+ items,
},
}
diff --git a/src/components/game/store/Item.tsx b/src/components/game/store/Item.tsx
index 5aa6a99..cbeb2e1 100644
--- a/src/components/game/store/Item.tsx
+++ b/src/components/game/store/Item.tsx
@@ -1,6 +1,7 @@
import '@/styles/game/store/item.css'
import { Typography, Button } from '@mui/material'
import { Item as ItemType } from '@/types'
+import getItemIcon from '@/utils/getItemIcon'
type Props = {
item: ItemType
@@ -19,14 +20,10 @@ export function Item({ item, lines, onBuy }: Props) {
onClick={() => canBuy && onBuy(item)}
>
-

+
{item.name}
-
- {linePerSecond}
- {' '}
- lines per second
-
+ {linePerSecond} lines per second