incorporating callback to lift ui collapse state
This commit is contained in:
@@ -7,10 +7,6 @@
|
|||||||
margin: 1rem 0;
|
margin: 1rem 0;
|
||||||
width: 45vw;
|
width: 45vw;
|
||||||
|
|
||||||
&.collapsed {
|
|
||||||
width: 15vw;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-row-top-bar {
|
.card-row-top-bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import cardTierToKey from '../../util/cardTierToKey';
|
import cardTierToKey from '../../util/mechanics/cardTierToKey';
|
||||||
import { CardRowProps } from '../../util/propTypes';
|
import { CardRowProps } from '../../util/propTypes';
|
||||||
import { CardData } from "../../util/types"
|
import { CardData } from "../../util/types"
|
||||||
import Card from "../Card/Card"
|
import Card from "../Card/Card"
|
||||||
@@ -26,6 +26,14 @@ export default function CardRow({tier, state, setState}: CardRowProps) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
/**
|
||||||
|
* run callback function to pass state of collapsed to parent component
|
||||||
|
* repeat this process in Nobles.tsx
|
||||||
|
**/
|
||||||
|
console.log(collapsed);
|
||||||
|
}, [collapsed])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`card-row tier-${tier} ${collapsed && 'collapsed'}`}>
|
<div className={`card-row tier-${tier} ${collapsed && 'collapsed'}`}>
|
||||||
<div className="card-row-top-bar">
|
<div className="card-row-top-bar">
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
// types, data, utils
|
// types, data, utils
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import initializeBoard, { setCardRows } from '../../util/initializeBoard';
|
import initializeBoard, { setCardRows } from '../../util/setup/initializeBoard';
|
||||||
import { AppState, PlayerData, ResourceCost } from '../../util/types';
|
import { AppState, PlayerData, ResourceCost, UIState } from '../../util/types';
|
||||||
|
import { defaultUIState } from '../../util/setup/defaultUIState';
|
||||||
import { getChipsActions } from '../Player/ActionMethods';
|
import { getChipsActions } from '../Player/ActionMethods';
|
||||||
import { StateProps } from '../../util/propTypes';
|
import { StateProps } from '../../util/propTypes';
|
||||||
import './Gameboard.scss';
|
import './Gameboard.scss';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import Nobles from '../Nobles/Nobles';
|
import Nobles from '../Nobles/Nobles';
|
||||||
import AvailableChips from '../Resources/AvailableChips';
|
|
||||||
import AllPlayers from '../Player/AllPlayers';
|
import AllPlayers from '../Player/AllPlayers';
|
||||||
import CardRow from '../Card/CardRow';
|
import CardRow from '../Card/CardRow';
|
||||||
import SelectionView from '../Resources/SelectionView';
|
|
||||||
import { useCurrentPlayer } from '../../hooks/useCurrentPlayer';
|
import { useCurrentPlayer } from '../../hooks/useCurrentPlayer';
|
||||||
import usePreviousPlayer from '../../hooks/usePreviousPlayer';
|
import usePreviousPlayer from '../../hooks/usePreviousPlayer';
|
||||||
const { validateChips } = getChipsActions;
|
const { validateChips } = getChipsActions;
|
||||||
@@ -20,7 +19,7 @@ const { validateChips } = getChipsActions;
|
|||||||
export default function Gameboard({ state, setState }: StateProps) {
|
export default function Gameboard({ state, setState }: StateProps) {
|
||||||
const [view, setView] = useState(<p>Loading...</p>);
|
const [view, setView] = useState(<p>Loading...</p>);
|
||||||
const [endgame, setEndgame] = useState<PlayerData>();
|
const [endgame, setEndgame] = useState<PlayerData>();
|
||||||
const [winner, setWinner] = useState<PlayerData>();
|
const [UICollapse, setUICollapse] = useState<UIState>(defaultUIState);
|
||||||
|
|
||||||
// callbacks for lifting state
|
// callbacks for lifting state
|
||||||
const liftSelection = useCallback((value: keyof ResourceCost) => {
|
const liftSelection = useCallback((value: keyof ResourceCost) => {
|
||||||
@@ -47,6 +46,29 @@ export default function Gameboard({ state, setState }: StateProps) {
|
|||||||
})
|
})
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
|
const liftCollapsed = useCallback((collapsed: boolean, tier?: number) => {
|
||||||
|
/**
|
||||||
|
* if tier is not provided, default should refer to the nobles row
|
||||||
|
* update ui collapse state within gameboard
|
||||||
|
* pass this section of state as a dependency to new useEffect
|
||||||
|
* if any of the four rows are open, collapse player ui
|
||||||
|
*
|
||||||
|
* todo: incorporate "collapse all rows" to player ui
|
||||||
|
* also incorporate "collapse player ui"?
|
||||||
|
**/
|
||||||
|
|
||||||
|
switch (tier) {
|
||||||
|
case 1:
|
||||||
|
setUICollapse((prev) => {
|
||||||
|
return prev;
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
case 2: break;
|
||||||
|
case 3: break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
// util functions, setup on mount
|
// util functions, setup on mount
|
||||||
useEffect(() => initializeBoard(state, setState), [])
|
useEffect(() => initializeBoard(state, setState), [])
|
||||||
|
|
||||||
@@ -90,10 +112,10 @@ export default function Gameboard({ state, setState }: StateProps) {
|
|||||||
<h2 id="round-marker">Round: {state.round}</h2>
|
<h2 id="round-marker">Round: {state.round}</h2>
|
||||||
<div className="gameboard-columns">
|
<div className="gameboard-columns">
|
||||||
<section className="gameboard-left">
|
<section className="gameboard-left">
|
||||||
<Nobles state={state} setState={setState} />
|
<Nobles state={state} setState={setState} liftCollapsed={liftCollapsed} />
|
||||||
<CardRow tier={3} state={state} setState={setState} />
|
<CardRow tier={3} state={state} setState={setState} liftCollapsed={liftCollapsed} />
|
||||||
<CardRow tier={2} state={state} setState={setState} />
|
<CardRow tier={2} state={state} setState={setState} liftCollapsed={liftCollapsed} />
|
||||||
<CardRow tier={1} state={state} setState={setState} />
|
<CardRow tier={1} state={state} setState={setState} liftCollapsed={liftCollapsed} />
|
||||||
</section>
|
</section>
|
||||||
<section className="gameboard-right">
|
<section className="gameboard-right">
|
||||||
<AllPlayers state={state} setState={setState} liftSelection={liftSelection} />
|
<AllPlayers state={state} setState={setState} liftSelection={liftSelection} />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { expect, it, describe, vi } from 'vitest';
|
import { expect, it, describe, vi } from 'vitest';
|
||||||
import initializeBoard from '../../util/initializeBoard';
|
import initializeBoard from '../../util/setup/initializeBoard';
|
||||||
import { initialState } from '../../hooks/stateSetters';
|
import { initialState } from '../../hooks/stateSetters';
|
||||||
import { AppState, setStateType } from '../../util/types';
|
import { AppState, setStateType } from '../../util/types';
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,7 @@
|
|||||||
background-color: rgb(212, 196, 152);
|
background-color: rgb(212, 196, 152);
|
||||||
color: black;
|
color: black;
|
||||||
padding: 1rem 0;
|
padding: 1rem 0;
|
||||||
width: 55vw;
|
width: 45vw;
|
||||||
|
|
||||||
&.collapsed {
|
|
||||||
width: 15vw;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nobles-topbar {
|
.nobles-topbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
import { NobleData, ResourceCost } from "../../util/types";
|
import { NobleData, ResourceCost } from "../../util/types";
|
||||||
import { StateProps } from "../../util/propTypes";
|
import { NobleProps } from "../../util/propTypes";
|
||||||
import "../Nobles/Nobles.scss"
|
import "../Nobles/Nobles.scss"
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function Nobles({ state }: StateProps) {
|
export default function Nobles({ state }: NobleProps) {
|
||||||
const [collapsed, setCollapsed] = useState(true);
|
const [collapsed, setCollapsed] = useState(true);
|
||||||
|
|
||||||
if (!state.gameboard.nobles.length) {
|
if (!state.gameboard.nobles.length) {
|
||||||
@@ -19,7 +19,7 @@ export default function Nobles({ state }: StateProps) {
|
|||||||
return (
|
return (
|
||||||
<div className={`nobles-panel ${collapsed && 'collapsed'}`}>
|
<div className={`nobles-panel ${collapsed && 'collapsed'}`}>
|
||||||
<div className="nobles-topbar">
|
<div className="nobles-topbar">
|
||||||
<strong className="nobles-header">NOBLES</strong>
|
<strong className="nobles-header">Nobles</strong>
|
||||||
<button onClick={() => setCollapsed(!collapsed)}>{collapsed ? "Show" : "Hide"}</button>
|
<button onClick={() => setCollapsed(!collapsed)}>{collapsed ? "Show" : "Hide"}</button>
|
||||||
</div>
|
</div>
|
||||||
<div className={collapsed ? "hidden" : "all-nobles"}>
|
<div className={collapsed ? "hidden" : "all-nobles"}>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import getTotalBuyingPower from "../../util/getTotalBuyingPower";
|
import getTotalBuyingPower from "../../util/mechanics/getTotalBuyingPower";
|
||||||
import { NobleData, PlayerData, ResourceCost } from "../../util/types";
|
import { NobleData, PlayerData, ResourceCost } from "../../util/types";
|
||||||
|
|
||||||
export const canPickUpNoble = (player: PlayerData, noble: NobleData) => {
|
export const canPickUpNoble = (player: PlayerData, noble: NobleData) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { turnOrderUtil } from "../../../util/turnOrderUtil";
|
import { turnOrderUtil } from "../../../util/mechanics/TurnOrderUtil";
|
||||||
import getTotalBuyingPower from "../../../util/getTotalBuyingPower";
|
import getTotalBuyingPower from "../../../util/mechanics/getTotalBuyingPower";
|
||||||
import { AppState, CardData, PlayerCards, ResourceCost, setStateType } from "../../../util/types";
|
import { AppState, CardData, PlayerCards, ResourceCost, setStateType } from "../../../util/types";
|
||||||
import cardTierToKey from "../../../util/cardTierToKey";
|
import cardTierToKey from "../../../util/mechanics/cardTierToKey";
|
||||||
import { canPickUpNoble } from "../../Nobles/canPickUpNoble";
|
import { canPickUpNoble } from "../../Nobles/canPickUpNoble";
|
||||||
import { initialActions, setStateGetNoble } from "../../../hooks/stateSetters";
|
import { initialActions, setStateGetNoble } from "../../../hooks/stateSetters";
|
||||||
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
|
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { AppState, PlayerData, setStateType } from '../../../util/types';
|
import { AppState, PlayerData, setStateType } from '../../../util/types';
|
||||||
import { useCurrentPlayer } from '../../../hooks/useCurrentPlayer';
|
import { useCurrentPlayer } from '../../../hooks/useCurrentPlayer';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { turnOrderUtil } from '../../../util/turnOrderUtil';
|
import { turnOrderUtil } from '../../../util/mechanics/TurnOrderUtil';
|
||||||
import { initialActions } from "../../../hooks/stateSetters";
|
import { initialActions } from "../../../hooks/stateSetters";
|
||||||
|
|
||||||
export const hasMaxChips = (player: PlayerData | null): boolean => {
|
export const hasMaxChips = (player: PlayerData | null): boolean => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import cardTierToKey from "../../../util/cardTierToKey";
|
import cardTierToKey from "../../../util/mechanics/cardTierToKey";
|
||||||
import { initialActions } from "../../../hooks/stateSetters";
|
import { initialActions } from "../../../hooks/stateSetters";
|
||||||
import { turnOrderUtil } from "../../../util/turnOrderUtil";
|
import { turnOrderUtil } from "../../../util/mechanics/TurnOrderUtil";
|
||||||
import { AppState, CardData, FullDeck, PlayerData, setStateType } from "../../../util/types";
|
import { AppState, CardData, FullDeck, PlayerData, setStateType } from "../../../util/types";
|
||||||
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
|
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: rgb(237, 213, 156);
|
background-color: rgb(188, 176, 146);
|
||||||
color: black;
|
color: black;
|
||||||
|
|
||||||
.player-ui {
|
.player-ui {
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
@import "../../sass/helper/mixins";
|
@import "../../sass/helper/mixins";
|
||||||
|
@import "../../sass/helper/variables";
|
||||||
|
|
||||||
.available-chips {
|
.available-chips {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: row wrap;
|
flex-flow: row wrap;
|
||||||
max-width: 50%;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: black;
|
color: black;
|
||||||
|
margin: 1rem;
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@include map-gem-values(".chips");
|
@include map-gem-values(".chips");
|
||||||
|
@each $gem in $gemlist {
|
||||||
|
.chips-#{$gem} {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ export default function AvailableChips({ state, liftSelection }: ResourceProps)
|
|||||||
disabled={state.gameboard.tradingResources[typedKey] <= 0}
|
disabled={state.gameboard.tradingResources[typedKey] <= 0}
|
||||||
onClick={() => liftSelection(typedKey)}
|
onClick={() => liftSelection(typedKey)}
|
||||||
>
|
>
|
||||||
{key}: {state.gameboard.tradingResources[typedKey]}
|
{state.gameboard.tradingResources[typedKey]}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
padding: 0.5rem;
|
padding: 1rem;
|
||||||
border-radius: 25%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ export const GetChipsHTML = ({ state, setState }: StateProps) => {
|
|||||||
<div className="current-selections">
|
<div className="current-selections">
|
||||||
{
|
{
|
||||||
state.actions.getChips.active &&
|
state.actions.getChips.active &&
|
||||||
state.actions.getChips.selection?.map((each: keyof ResourceCost) => <p className={`selection-value-${each}`} key={v4()}>{each}</p>)
|
state.actions.getChips.selection?.map((each: keyof ResourceCost) => <p className={`selection-value-${each}`} key={v4()}>{each[0].toUpperCase()}</p>)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
@extend %hidden;
|
@extend %hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.collapsed {
|
||||||
|
width: 20vw;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppState, PlayerData } from "./types";
|
import { AppState, PlayerData } from "../types";
|
||||||
|
|
||||||
export const turnOrderUtil = (prev: AppState, dynamic: PlayerData) => {
|
export const turnOrderUtil = (prev: AppState, dynamic: PlayerData) => {
|
||||||
let roundIncrement = false;
|
let roundIncrement = false;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FullDeck } from "./types"
|
import { FullDeck } from "../types"
|
||||||
|
|
||||||
export default function cardTierToKey(tier: number): keyof FullDeck {
|
export default function cardTierToKey(tier: number): keyof FullDeck {
|
||||||
switch (tier) {
|
switch (tier) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PlayerData, ResourceCost } from "./types";
|
import { PlayerData, ResourceCost } from "../types";
|
||||||
|
|
||||||
export default function getTotalBuyingPower(currentPlayer: PlayerData) {
|
export default function getTotalBuyingPower(currentPlayer: PlayerData) {
|
||||||
let totalBuyingPower = {
|
let totalBuyingPower = {
|
||||||
@@ -13,6 +13,11 @@ export interface CardProps extends StateProps {
|
|||||||
|
|
||||||
export interface CardRowProps extends StateProps {
|
export interface CardRowProps extends StateProps {
|
||||||
tier: number
|
tier: number
|
||||||
|
liftCollapsed: (collapsed: boolean, tier?: number) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NobleProps extends StateProps {
|
||||||
|
liftCollapsed: (collapsed: boolean, tier?: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlayerProps extends StateProps {
|
export interface PlayerProps extends StateProps {
|
||||||
|
|||||||
9
src/util/setup/defaultUIState.ts
Normal file
9
src/util/setup/defaultUIState.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { UIState } from "../types";
|
||||||
|
|
||||||
|
export const defaultUIState: UIState = {
|
||||||
|
noblesCollapsed: true,
|
||||||
|
tierThreeCollapsed: true,
|
||||||
|
tierTwoCollapsed: true,
|
||||||
|
tierOneCollapsed: true,
|
||||||
|
playerUICollapsed: false
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { AppState, FullDeck, NobleData, ResourceCost, setStateType } from "./types";
|
import { AppState, FullDeck, NobleData, ResourceCost, setStateType } from "../types";
|
||||||
import NobleStore from '../data/nobles.json';
|
import NobleStore from '../../data/nobles.json';
|
||||||
|
|
||||||
const shuffleDeck = (state: AppState, setState: setStateType) => {
|
const shuffleDeck = (state: AppState, setState: setStateType) => {
|
||||||
if (!state.gameboard.deck) return;
|
if (!state.gameboard.deck) return;
|
||||||
@@ -105,3 +105,11 @@ export interface NobleData {
|
|||||||
points: number,
|
points: number,
|
||||||
resourceCost: ResourceCost
|
resourceCost: ResourceCost
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UIState {
|
||||||
|
noblesCollapsed: boolean
|
||||||
|
tierThreeCollapsed: boolean
|
||||||
|
tierTwoCollapsed: boolean
|
||||||
|
tierOneCollapsed: boolean
|
||||||
|
playerUICollapsed: boolean
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { describe, expect, test } from "vitest"
|
import { describe, expect, test } from "vitest"
|
||||||
import cardTierToKey from "./cardTierToKey";
|
import cardTierToKey from "./mechanics/cardTierToKey";
|
||||||
import { mockPlayerOne, mockState } from "./testUtils";
|
import { mockPlayerOne, mockState } from "./testUtils";
|
||||||
import { turnOrderUtil } from "./turnOrderUtil";
|
import { turnOrderUtil } from "./mechanics/TurnOrderUtil";
|
||||||
import { useCurrentPlayer } from "../hooks/useCurrentPlayer";
|
import { useCurrentPlayer } from "../hooks/useCurrentPlayer";
|
||||||
import getTotalBuyingPower from "./getTotalBuyingPower";
|
import getTotalBuyingPower from "./mechanics/getTotalBuyingPower";
|
||||||
|
|
||||||
describe('app utilities', () => {
|
describe('app utilities', () => {
|
||||||
test('useCurrentPlayer', () => {
|
test('useCurrentPlayer', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user