diff --git a/ui/src/elements.tsx b/ui/src/elements.tsx
index 61dd780..26b0bcf 100644
--- a/ui/src/elements.tsx
+++ b/ui/src/elements.tsx
@@ -1,6 +1,17 @@
import * as React from "react";
import {Letter as LetterData} from "word_grid";
+export enum LocationType {
+ GRID,
+ TRAY
+}
+
+export interface CoordinateData {
+ location: LocationType;
+ index: number;
+}
+
+export type PlayableLetterData = LetterData & CoordinateData;
export function Letter(props: { data: LetterData }): React.JSX.Element {
return
@@ -9,16 +20,21 @@ export function Letter(props: { data: LetterData }): React.JSX.Element {
}
-export function TileTray(props: { letters: Array }): React.JSX.Element {
- let elements = props.letters.map((ld, i) => {
- if (ld === undefined) {
- return ;
- } else {
- return
+export function TileTray(props: { letters: Array, trayLength: number }): React.JSX.Element {
+
+ let elements: JSX.Element[] = [];
+ for (let i=0; i
+ );
+ }
+
+ for (let letter of props.letters) {
+ if (letter.location === LocationType.TRAY) {
+ elements[letter.index] =
}
- })
- .concat();
+ }
return (
diff --git a/ui/src/index.tsx b/ui/src/index.tsx
index c3714fc..c975ce1 100644
--- a/ui/src/index.tsx
+++ b/ui/src/index.tsx
@@ -1,5 +1,5 @@
import init, {greet, GameWasm} from '../node_modules/word_grid/word_grid.js';
-import {TileTray} from "./elements";
+import {LocationType, PlayableLetterData, TileTray} from "./elements";
import {createRoot} from "react-dom/client";
import {Tray} from "word_grid";
@@ -37,12 +37,17 @@ async function run() {
let game = new GameWasm(BigInt(1234));
let tray: Tray = game.get_tray();
+ // initial state
+ let letters: PlayableLetterData[] = tray.letters.map((ld, i) => {
+ ld["location"] = LocationType.TRAY;
+ ld["index"] = i;
+ return ld as PlayableLetterData;
+ })
+
console.log({tray});
const root = createRoot(document.getElementById("root"));
- root.render();
-
- // And afterwards we can use all the functionality defined in wasm.
+ root.render();
}
diff --git a/ui/src/style.less b/ui/src/style.less
index e47a171..1bc03bb 100644
--- a/ui/src/style.less
+++ b/ui/src/style.less
@@ -14,6 +14,7 @@
.letter {
background-color: #e5cca9;
position: relative; // Used for the positioning of the sub-components
+ user-select: none;
.text {
position: absolute;