Skip to content

Commit cee011c

Browse files
committed
Update
1 parent 9f4cc08 commit cee011c

20 files changed

+6323
-2080
lines changed

.github/workflows/main.yaml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Sample workflow for building and deploying a Next.js site to GitHub Pages
2+
#
3+
# To get started with Next.js see: https://nextjs.org/docs/getting-started
4+
#
5+
name: Deploy to Github Pages
6+
7+
on:
8+
# Runs on pushes targeting the default branch
9+
push:
10+
branches: ['main']
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16+
permissions:
17+
contents: read
18+
pages: write
19+
id-token: write
20+
21+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
23+
concurrency:
24+
group: 'pages'
25+
cancel-in-progress: false
26+
27+
jobs:
28+
# Build job
29+
build:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Detect package manager
35+
id: detect-package-manager
36+
run: |
37+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
38+
echo "manager=yarn" >> $GITHUB_OUTPUT
39+
echo "command=install" >> $GITHUB_OUTPUT
40+
echo "runner=yarn" >> $GITHUB_OUTPUT
41+
exit 0
42+
elif [ -f "${{ github.workspace }}/package.json" ]; then
43+
echo "manager=npm" >> $GITHUB_OUTPUT
44+
echo "command=ci" >> $GITHUB_OUTPUT
45+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46+
exit 0
47+
else
48+
echo "Unable to determine package manager"
49+
exit 1
50+
fi
51+
- name: Setup Node
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: '20'
55+
cache: ${{ steps.detect-package-manager.outputs.manager }}
56+
- name: Setup Pages
57+
uses: actions/configure-pages@v4
58+
with:
59+
# Automatically inject basePath in your Next.js configuration file and disable
60+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
61+
#
62+
# You may remove this line if you want to manage the configuration yourself.
63+
static_site_generator: next
64+
- name: Restore cache
65+
uses: actions/cache@v4
66+
with:
67+
path: |
68+
.next/cache
69+
# Generate a new cache whenever packages or source files change.
70+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
71+
# If source files changed but packages didn't, rebuild from a prior cache.
72+
restore-keys: |
73+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
74+
- name: Install dependencies
75+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
76+
- name: Build with Next.js
77+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
78+
- name: Upload artifact
79+
uses: actions/upload-pages-artifact@v3
80+
with:
81+
path: ./out
82+
83+
# Deployment job
84+
deploy:
85+
environment:
86+
name: github-pages
87+
url: ${{ steps.deployment.outputs.page_url }}
88+
runs-on: ubuntu-latest
89+
needs: build
90+
steps:
91+
- name: Deploy to GitHub Pages
92+
id: deployment
93+
uses: actions/deploy-pages@v4

README.md

+1-36
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2-
3-
## Getting Started
4-
5-
First, run the development server:
6-
7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
15-
```
16-
17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18-
19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20-
21-
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22-
23-
## Learn More
24-
25-
To learn more about Next.js, take a look at the following resources:
26-
27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29-
30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31-
32-
## Deploy on Vercel
33-
34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35-
36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
1+
# Word games

app/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

app/hangman/data.ts

-17
This file was deleted.

app/hangman/data/words.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const words = [
2+
'Jackhammer',
3+
'Blacksmith',
4+
'Helicopter',
5+
'Exacerbate',
6+
'Earthquake',
7+
'Conclusive',
8+
'Encyclopedia',
9+
'Handwriting',
10+
'Holography',
11+
'Jackrabbit',
12+
];

app/hangman/hangman.tsx

+21-33
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,49 @@
1-
"use client";
2-
import { useState } from "react";
3-
import cx from "clsx";
4-
import { randomWord } from "./data";
5-
6-
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1+
'use client';
2+
import { useState } from 'react';
3+
import cx from 'clsx';
4+
import { ALPHABET } from '@/app/common/constants';
5+
import _ from 'lodash';
6+
import { words } from '@/app/hangman/data/words';
77

88
export function Hangman({ initialWord }: { initialWord: string }) {
99
const [guesses, setGuesses] = useState<string[]>([]);
1010
const [word, setWord] = useState(initialWord);
1111
const [failures, setFailuresLeft] = useState(7);
1212

1313
const getClassName = (letter: string) =>
14-
cx("rounded w-10 uppercase disabled:cursor-not-allowed bg-slate-200", {
15-
["bg-green-200"]: guesses.includes(letter) && word.includes(letter),
16-
["bg-red-200"]: guesses.includes(letter) && !word.includes(letter),
14+
cx('rounded w-10 uppercase disabled:cursor-not-allowed ', {
15+
['bg-emerald-200']: guesses.includes(letter) && word.includes(letter),
16+
['bg-rose-200']: guesses.includes(letter) && !word.includes(letter),
17+
['bg-slate-200']: !guesses.includes(letter),
1718
});
1819

19-
const isGuessed =
20-
word != "" &&
21-
word
22-
.split("")
23-
.every((letter) => guesses.includes(letter.toLocaleUpperCase()));
20+
const isGuessed = _.every(word, (letter) => guesses.includes(letter.toLocaleUpperCase()));
2421

2522
const handleGuess = (letter: string) => {
2623
setGuesses((p) => p.concat(letter));
24+
2725
if (!word.includes(letter)) {
2826
setFailuresLeft((p) => p - 1);
2927
}
3028
};
3129

3230
const handleReset = () => {
33-
setWord(randomWord());
31+
setWord(_.sample(words)!.toLocaleUpperCase());
3432
setGuesses([]);
3533
setFailuresLeft(7);
3634
};
3735

3836
return (
3937
<main className="flex justify-center items-center mt-40 flex-col">
4038
<ul className="flex uppercase gap-4 text-3xl mb-6">
41-
{word
42-
.split("")
43-
.map((letter, index) =>
44-
guesses.includes(letter.toLocaleUpperCase()) ? (
45-
<li key={index}>{letter}</li>
46-
) : (
47-
<li key={index}>_</li>
48-
)
49-
)}
39+
{_.map(word, (letter, index) =>
40+
guesses.includes(letter.toLocaleUpperCase()) ? <li key={index}>{letter}</li> : <li key={index}>_</li>,
41+
)}
5042
</ul>
43+
5144
{failures > 0 && (
5245
<ul className="flex gap-2 text-2xl flex-wrap px-4 mb-6 max-w-[680px]">
53-
{ALPHABET.split("").map((letter, index) => (
46+
{_.map(ALPHABET, (letter, index) => (
5447
<li key={index}>
5548
<button
5649
className={getClassName(letter.toLocaleUpperCase())}
@@ -70,22 +63,17 @@ export function Hangman({ initialWord }: { initialWord: string }) {
7063
<p>
7164
You lose!
7265
<br />
73-
<button
74-
className="bg-red-500 text-white px-2 py-1 rounded"
75-
onClick={handleReset}
76-
>
66+
<button className="bg-red-500 text-white px-2 py-1 rounded" onClick={handleReset}>
7767
Play again
7868
</button>
7969
</p>
8070
)}
71+
8172
{isGuessed && (
8273
<p className="text-2xl mt-2">
8374
You win!
8475
<br />
85-
<button
86-
className="ml-2 bg-green-500 text-white px-2 py-1 rounded"
87-
onClick={handleReset}
88-
>
76+
<button className="ml-2 bg-green-500 text-white px-2 py-1 rounded" onClick={handleReset}>
8977
Play again
9078
</button>
9179
</p>

app/hangman/page.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Hangman } from "./hangman";
2-
import { randomWord } from "./data";
1+
import { Hangman } from './hangman';
2+
import { words } from '@/app/hangman/data/words';
3+
import _ from 'lodash';
34

45
export default function Home() {
5-
return <Hangman initialWord={randomWord()} />;
6+
return <Hangman initialWord={_.sample(words)!.toLocaleUpperCase()} />;
67
}

app/layout.tsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { Metadata } from "next";
2-
import { Inter } from "next/font/google";
3-
import "./globals.css";
1+
import type { Metadata } from 'next';
2+
import { Inter } from 'next/font/google';
3+
import './globals.css';
44

5-
const inter = Inter({ subsets: ["latin"] });
5+
const inter = Inter({ subsets: ['latin'] });
66

77
export const metadata: Metadata = {
8-
title: "Create Next App",
9-
description: "Generated by create next app",
8+
title: 'Word Games',
109
};
1110

1211
export default function RootLayout({
@@ -16,7 +15,20 @@ export default function RootLayout({
1615
}>) {
1716
return (
1817
<html lang="en">
19-
<body className={inter.className}>{children}</body>
18+
<body className={inter.className}>
19+
<nav>
20+
<ul className="flex gap-4 m-2 uppercase">
21+
<li>
22+
<a href="hangman">Hangman</a>
23+
</li>
24+
<li>
25+
<a href="wordle">Wordle</a>
26+
</li>
27+
</ul>
28+
</nav>
29+
30+
{children}
31+
</body>
2032
</html>
2133
);
2234
}

app/page.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <div className="m-4 text-sm">Select a game above</div>;
3+
}

0 commit comments

Comments
 (0)