|
1 | 1 | import { sql } from "drizzle-orm"; |
| 2 | +import { Form } from "react-router"; |
2 | 3 | import { getAuth } from "~/lib/auth"; |
3 | 4 | import { getDB } from "~/lib/db"; |
4 | 5 | import { hai, haiyama } from "~/lib/db/schema"; |
5 | | -import { dbHaiToHai } from "~/lib/hai"; |
| 6 | +import { dbHaiToHai, sortTehai } from "~/lib/hai"; |
6 | 7 | import { type GameState, getRedisClient, init } from "~/lib/redis"; |
7 | 8 | import type { Route } from "./+types/play"; |
8 | 9 |
|
@@ -70,15 +71,73 @@ export async function loader({ |
70 | 71 | } |
71 | 72 |
|
72 | 73 | export default function Page({ loaderData }: Route.ComponentProps) { |
73 | | - const exampleHai = loaderData.haiyama[0]; |
| 74 | + let { haiyama, sutehai, tsumohai, junme, kyoku, tehai } = loaderData; |
| 75 | + tehai = sortTehai(tehai); |
| 76 | + const indexedSutehai = sutehai.map((hai, index) => ({ |
| 77 | + ...hai, |
| 78 | + index: index, |
| 79 | + })); |
| 80 | + const indexedTehai = tehai.map((hai, index) => ({ |
| 81 | + ...hai, |
| 82 | + index: index, |
| 83 | + })); |
| 84 | + |
74 | 85 | return ( |
75 | | - <> |
76 | | - <p>Play Page</p> |
77 | | - <img |
78 | | - src={`/hai/${exampleHai.kind}_${exampleHai.value}.png`} |
79 | | - alt={`${hai.kind} ${hai.value}`} |
80 | | - className="cursor-pointer" |
81 | | - /> |
82 | | - </> |
| 86 | + <div className="p-4"> |
| 87 | + <p className="text-xl mb-4"> |
| 88 | + Play Page - 局 {kyoku} 巡目 {junme} |
| 89 | + </p> |
| 90 | + |
| 91 | + {/* Sutehai grid (3x6) */} |
| 92 | + <div className="mb-6"> |
| 93 | + <h3 className="text-lg mb-2">捨て牌</h3> |
| 94 | + <div className="grid grid-cols-6 gap-0 w-max min-h-48"> |
| 95 | + {indexedSutehai.map((hai) => ( |
| 96 | + <img |
| 97 | + key={hai.index} |
| 98 | + src={`/hai/${hai.kind}_${hai.value}.png`} |
| 99 | + alt={`${hai.kind} ${hai.value}`} |
| 100 | + className="w-12 h-16" |
| 101 | + /> |
| 102 | + ))} |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + |
| 106 | + {/* Tehai and Tsumohai */} |
| 107 | + <div className="flex items-center gap-4"> |
| 108 | + <div> |
| 109 | + <h3 className="text-lg mb-2">手牌</h3> |
| 110 | + <div className="flex gap-0"> |
| 111 | + {indexedTehai.map((hai) => ( |
| 112 | + <Form key={hai.index} method="post" action="/play/tedashi"> |
| 113 | + <input type="hidden" name="index" value={hai.index} /> |
| 114 | + <button type="submit"> |
| 115 | + <img |
| 116 | + src={`/hai/${hai.kind}_${hai.value}.png`} |
| 117 | + alt={`${hai.kind} ${hai.value}`} |
| 118 | + className="w-12 h-16 cursor-pointer hover:scale-105 transition-transform" |
| 119 | + /> |
| 120 | + </button> |
| 121 | + </Form> |
| 122 | + ))} |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + |
| 126 | + {tsumohai && ( |
| 127 | + <div> |
| 128 | + <h3 className="text-lg mb-2">ツモ牌</h3> |
| 129 | + <Form method="post" action="/play/tsumogiri"> |
| 130 | + <button type="submit"> |
| 131 | + <img |
| 132 | + src={`/hai/${tsumohai.kind}_${tsumohai.value}.png`} |
| 133 | + alt={`${tsumohai.kind} ${tsumohai.value}`} |
| 134 | + className="w-12 h-16 object-contain cursor-pointer hover:scale-105 transition-transform" |
| 135 | + /> |
| 136 | + </button> |
| 137 | + </Form> |
| 138 | + </div> |
| 139 | + )} |
| 140 | + </div> |
| 141 | + </div> |
83 | 142 | ); |
84 | 143 | } |
0 commit comments