Skip to content

Commit f1d0958

Browse files
committed
Tic Tav Toe
1 parent 220f390 commit f1d0958

37 files changed

+40042
-65
lines changed

hackernews/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hackernews/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "Hacker News",
2+
"name": "boilerplate",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {

hackernews/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react"
2-
import { HNHomePage } from "./HNHomePage"
2+
import {HNHomePage} from "./HNHomePage"
33

44
function App() {
55
return (
6-
<div>
6+
<div className="App">
77
<HNHomePage />
88
</div>
99
)

hackernews/src/HNBody.tsx

+6-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import React, { useState, useEffect } from "react"
2-
import { Story } from "./types"
1+
import React, { useEffect, useState } from "react"
32
import { NewsItem } from "./NewsItem"
4-
import { fetchStories, fetchTopStoriesIds } from "./utils/api"
3+
import { Story } from "./types"
4+
import { fetchStories, fetchTopStoriesIds} from "./utils/api"
55

66
export function HNBody() {
7-
const [topStoriesIds, setTopStoriesIds] = useState([] as number[])
87
const [stories, setStories] = useState([] as Story[])
9-
const [page, setPage] = useState(0)
8+
const [topStoriesIds, setTopStoriesIds] = useState([] as number[])
109

1110
const loadStories = async () => {
1211
const topStoriesIdsData = await fetchTopStoriesIds()
@@ -19,32 +18,11 @@ export function HNBody() {
1918
loadStories()
2019
}, [])
2120

22-
const loadMore = async () => {
23-
const storiesData = await fetchStories(
24-
topStoriesIds.slice(page + 10, page + 20)
25-
)
26-
setStories([...stories, ...storiesData])
27-
setPage(page + 10)
28-
}
29-
3021
return (
3122
<div className="pl-48 pt-24 bg-white border-b-8 border-gray-50">
3223
{stories.map((it, index) => (
33-
<NewsItem
34-
key={it.id}
35-
id={it.id}
36-
index={index}
37-
title={it.title}
38-
url={it.url}
39-
/>
24+
<NewsItem key={it.id} id={it.id} title={it.title} url={it.url} index={index}/>
4025
))}
41-
<button
42-
type="button"
43-
onClick={loadMore}
44-
className="border border-gray-400 px-4 py-3 bg-gray-50 text-gray-800 rounded-sm mb-12 ml-8"
45-
>
46-
Load more
47-
</button>
4826
</div>
4927
)
50-
}
28+
}

hackernews/src/HNHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22

33
export function HNHeader() {
44
return (
5-
<div className="border-t-4 border-hn-orange bg-gray-100 pl-48 p-8">
5+
<div className="border-t-4 border-hn-orange bg-gray-100 pl-48 p-8">
66
<h1 className="text-7xl">HN Top Stories</h1>
77
</div>
88
)

hackernews/src/HNHomePage.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import React, { useEffect, useState } from "react"
2-
import { HNHeader } from "./HNHeader"
1+
import React from "react"
32
import { HNBody } from "./HNBody"
3+
import { HNHeader } from "./HNHeader"
44

55
export function HNHomePage() {
6-
return (
7-
<div>
8-
<HNHeader />
9-
<HNBody />
10-
</div>
11-
)
12-
}
6+
7+
return <div><HNHeader /><HNBody /></div>
8+
}

hackernews/src/NewsItem.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type NewsItemProps = {
77
index: number
88
}
99

10-
export function NewsItem({ index, id, title, url }: NewsItemProps) {
10+
export function NewsItem({ id, title, url, index }: NewsItemProps) {
1111
return (
1212
<div className="mb-12">
1313
<div>
@@ -20,12 +20,11 @@ export function NewsItem({ index, id, title, url }: NewsItemProps) {
2020
{index}. {title}
2121
</a>
2222
</div>
23-
<div className={`${index < 10 ? "ml-8" : "ml-11"} text-xl text-gray-500`}>
23+
<div className="ml-8 text-xl text-gray-500">
2424
<span>({new URL(url).hostname})</span>
2525
<span> | </span>
2626
<span>
2727
<a
28-
className="cursor-pointer hover:underline"
2928
href={`https://news.ycombinator.com/item?id=${id}`}
3029
target="_blank"
3130
rel="noreferrer"
@@ -36,4 +35,4 @@ export function NewsItem({ index, id, title, url }: NewsItemProps) {
3635
</div>
3736
</div>
3837
)
39-
}
38+
}

hackernews/src/index.css

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
@tailwind base;
22
@tailwind components;
3-
@tailwind utilities;
4-
5-
:root {
6-
font-size: 12px;
7-
}
3+
@tailwind utilities;

hackernews/src/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type Story = {
2-
id: number
3-
by: string
4-
title: string
5-
url: string
6-
}
2+
id: number
3+
by: string
4+
title: string
5+
url: string
6+
}

hackernews/src/utils/api.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const HN_HOST = "https://hacker-news.firebaseio.com/v0"
55
export const fetchTopStoriesIds = async (): Promise<number[]> => {
66
const response = await fetch(`${HN_HOST}/topstories.json`)
77
const topStoriesIds = await response.json()
8-
// console.log(topStoriesIds)
8+
console.log(topStoriesIds)
99
return topStoriesIds
1010
}
1111

@@ -20,16 +20,15 @@ export const fetchStory = async (id: number): Promise<Story> => {
2020
title: storyData.title,
2121
url: storyData.url,
2222
}
23-
// console.log(story)
2423
return story
2524
}
2625

2726
export const fetchStories = async (ids: number[]): Promise<Story[]> => {
28-
const stories: Story[] = await Promise.all(ids.map(fetchStory))
29-
27+
const stories = await Promise.all(ids.map(fetchStory))
3028
// console.log(stories)
3129
return stories
3230
}
31+
3332
// fetchTopStoriesIds()
34-
// fetchStory(28507350)
35-
// fetchStories([28507350, 28508497])
33+
// fetchStory(28554565)
34+
// fetchStories([28554565, 28554565])

hackernews/tailwind.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module.exports = {
44
theme: {
55
extend: {
66
colors: {
7-
'hn-orange': '#FF6600',
7+
'hn-orange': '#FF6600'
88
}
9-
}
9+
},
1010
},
1111
variants: {
1212
extend: {},

tictactoe/.eslintrc.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:react/recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaFeatures": {
14+
"jsx": true
15+
},
16+
"ecmaVersion": 12,
17+
"sourceType": "module"
18+
},
19+
"plugins": [
20+
"react",
21+
"react-hooks",
22+
"@typescript-eslint"
23+
],
24+
"rules": {
25+
"react/react-in-jsx-scope": "off",
26+
"react/display-name": "off",
27+
"react-hooks/exhaustive-deps": "off",
28+
"@typescript-eslint/ban-ts-comment": "off",
29+
"prefer-const": "off",
30+
"@typescript-eslint/no-extra-semi": "off",
31+
"@typescript-eslint/explicit-module-boundary-types": "off",
32+
"@typescript-eslint/no-unused-vars": "off",
33+
"@typescript-eslint/no-explicit-any": "off",
34+
"@typescript-eslint/no-non-null-assertion": "off",
35+
"@typescript-eslint/no-empty-interface": "off",
36+
"react/prop-types": "off",
37+
"@typescript-eslint/no-empty-function": "off",
38+
"prefer-rest-params": "off",
39+
"@typescript-eslint/no-this-alias": "off"
40+
}
41+
}

tictactoe/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

tictactoe/.prettierrc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "lf",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 80,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": false,
14+
"singleQuote": false,
15+
"tabWidth": 2,
16+
"trailingComma": "es5",
17+
"useTabs": false,
18+
"vueIndentScriptAndStyle": false,
19+
"parser": "typescript"
20+
}

tictactoe/README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).

tictactoe/craco.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
style: {
3+
postcss: {
4+
plugins: [
5+
require('tailwindcss'),
6+
require('autoprefixer'),
7+
],
8+
},
9+
},
10+
}

0 commit comments

Comments
 (0)