setGameState(
produce((state) => {
- state.hand.push(state.pile.pop()!);
+ state.hand.push(state.deck.pop()!);
})
)
}
diff --git a/src/components/Hand.tsx b/src/components/Hand.tsx
index 8277be1..3ef62c2 100644
--- a/src/components/Hand.tsx
+++ b/src/components/Hand.tsx
@@ -1,11 +1,19 @@
-import { Component, For } from "solid-js";
+import { Component, For, useContext } from "solid-js";
import Card from "./Card";
import { Hand } from "../types/cards";
+import { GameContext } from "./Game";
+import { produce } from "solid-js/store";
export default ((props) => {
+ const { setGameState } = useContext(GameContext)!;
+
return (
{
gap: "5px",
}}
>
- {(card) => }
+
+ {(card) => (
+
+ setGameState(
+ produce((state) => {
+ const index = state.hand.indexOf(card);
+ console.log(index);
+ state.deck.push(
+ state.hand.splice(
+ props.hand.indexOf(card),
+ 1
+ )[0]!
+ );
+ })
+ )
+ }
+ />
+ )}
+
);
}) satisfies Component<{ hand: Hand }>;
diff --git a/src/components/Pile.tsx b/src/components/Pile.tsx
index 2dea2d3..41350b1 100644
--- a/src/components/Pile.tsx
+++ b/src/components/Pile.tsx
@@ -1,12 +1,19 @@
import { Component, For, JSX } from "solid-js";
import Card from "./Card";
import { Pile } from "../types/cards";
+import { type ComponentProps } from "solid-js";
+import { Clickable, Stylable } from "./toolbox";
export default ((props) => {
return (
@@ -31,14 +38,9 @@ export default ((props) => {
);
-}) satisfies Component<{
- pile: Pile;
- style?: JSX.CSSProperties;
- onClick?:
- | JSX.EventHandlerUnion<
- HTMLDivElement,
- MouseEvent,
- JSX.EventHandler
- >
- | undefined;
-}>;
+}) satisfies Component<
+ {
+ pile: Pile;
+ } & Stylable &
+ Clickable
+>;
diff --git a/src/components/toolbox.tsx b/src/components/toolbox.tsx
new file mode 100644
index 0000000..ca2ae98
--- /dev/null
+++ b/src/components/toolbox.tsx
@@ -0,0 +1,16 @@
+import { JSX } from "solid-js";
+
+export type Stylable = {
+ class?: string;
+ style?: JSX.CSSProperties;
+};
+
+export type Clickable = {
+ onClick?:
+ | JSX.EventHandlerUnion<
+ HTMLDivElement,
+ MouseEvent,
+ JSX.EventHandler
+ >
+ | undefined;
+};
diff --git a/src/types/cards.ts b/src/types/cards.ts
index 029680d..5b75a48 100644
--- a/src/types/cards.ts
+++ b/src/types/cards.ts
@@ -55,3 +55,8 @@ export const shuffle = (cards: Card[]) => {
}
return cards;
};
+
+export type GameState = {
+ deck: Pile;
+ hand: Hand;
+};