Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/puzzle/check/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
return NextResponse.json({ errors }, { status: 400 });
}

const { puzzleId, guess } = data;
const { date, boardSize, guess } = data;

const currentBoard = await getCurrentBoard({ puzzleId });
const currentBoard = await getCurrentBoard({ date, boardSize });
const isCorrect = checkGuess(currentBoard.board as { x: number, y: number }[], guess);
const updatedUserProgress = await updateUserProgress({ userId: data.userId!, boardSize: currentBoard.boardSize, puzzleId: currentBoard.id, status: isCorrect ? 'CORRECT' : 'WRONG' });
const statistics = await getStatistics(userId!);
Expand Down
5 changes: 2 additions & 3 deletions app/api/puzzle/hint/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export async function GET(request: Request): Promise<NextResponse> {
if (!isValid || !data) {
return NextResponse.json({ errors }, { status: 400 });
}
const { puzzleId, x, y } = data;
const { date, boardSize, x, y } = data;

const currentBoard = await getCurrentBoard({ puzzleId });
console.log("Current board in hint",currentBoard)
const currentBoard = await getCurrentBoard({ date, boardSize });
const board = currentBoard.board as { x: number, y: number }[];

const adjacentCount = getAdjacentCount(board, currentBoard.boardSize, x, y);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"canvas-confetti": "^1.9.3",
"date-fns": "^4.1.0",
"next": "15.0.7",
"node-cache": "^5.1.2",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"react-icons": "^5.3.0",
Expand All @@ -25,6 +26,7 @@
"devDependencies": {
"@types/canvas-confetti": "^1.6.4",
"@types/node": "^20",
"@types/node-cache": "^4.2.5",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
Expand Down
40 changes: 34 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/api/daily-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const getGameStatus = async (date: string, boardSize: number): Promise<Ga
}
}

export const getHint = async (puzzleId: number, x: number, y: number): Promise<getHintResponse> => {
export const getHint = async (date: string, boardSize: number, x: number, y: number): Promise<getHintResponse> => {
try {
const response = await axiosSecure.get(`${API_HINT}?puzzleId=${puzzleId}&x=${x}&y=${y}`);
const response = await axiosSecure.get(`${API_HINT}?date=${date}&boardSize=${boardSize}&x=${x}&y=${y}`);
return response.data;
} catch (error) {
if (error instanceof AxiosError && error.code === "ERR_BAD_RESPONSE") {
Expand All @@ -30,9 +30,9 @@ export const getHint = async (puzzleId: number, x: number, y: number): Promise<g
}
}

export const checkGuess = async (puzzleId: number, guess: string[][], attempts: number): Promise<checkGuessResponse> => {
export const checkGuess = async (date: string, boardSize: number, guess: string[][], attempts: number): Promise<checkGuessResponse> => {
try {
const response = await axiosSecure.post(`${API_CHECK_GUESS}`, { puzzleId, guess, attempts });
const response = await axiosSecure.post(`${API_CHECK_GUESS}`, { date, boardSize, guess, attempts });
return response.data;
} catch (error) {
if (error instanceof AxiosError && error.code === "ERR_BAD_RESPONSE") {
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/puzzle/game-settings-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function GameSettingsProvider({ children }: { children: React.ReactNode }
try {
setLoadingCoordinates({ x, y });
updateSettings({ hints: settings.hints + 1 });
const data = await getHint(settings.puzzleId, x, y);
const data = await getHint(settings.date, settings.boardSize, x, y);
const newBoard = [...settings.board];
newBoard[x][y] = data.adjacentCount.toString();
updateSettings({ board: newBoard });
Expand All @@ -104,7 +104,7 @@ export function GameSettingsProvider({ children }: { children: React.ReactNode }
try {
updateSettings({ gameStatus: "guess-loading" });
const [response,] = await Promise.all([
checkGuess(settings.puzzleId, settings.guess, settings.hints),
checkGuess(settings.date, settings.boardSize, settings.guess, settings.hints),
new Promise(resolve => setTimeout(resolve, 2000))
]);

Expand Down
7 changes: 5 additions & 2 deletions src/lib/validation/guess-check-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const guessCheckSchema = z.object({
userId: z.string({
required_error: 'User ID is required',
}),
puzzleId: z.coerce.number({
required_error: 'Puzzle ID is required',
date: z.string({
required_error: 'Date is required',
}),
boardSize: z.coerce.number({
required_error: 'Board size is required',
}),
guess: z.array(z.array(z.string()))
})
Expand Down
10 changes: 7 additions & 3 deletions src/lib/validation/hint-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ const hintParamsSchema = z.object({
userId: z.string({
required_error: 'User ID is required',
}),
puzzleId: z.coerce.number({
required_error: 'Puzzle ID is required',
date: z.string({
required_error: 'Date is required',
}),
boardSize: z.coerce.number({
required_error: 'Board size is required',
}),
x: z.coerce
.number()
Expand All @@ -22,7 +25,8 @@ export function validateHintParams(searchParams: URLSearchParams, userId: string
} {
const result = hintParamsSchema.safeParse({
userId,
puzzleId: searchParams.get('puzzleId'),
date: searchParams.get('date'),
boardSize: searchParams.get('boardSize'),
x: searchParams.get('x'),
y: searchParams.get('y')
});
Expand Down
Loading