Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init the static page of the article list (hieunv) (Ex1) #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IDE files/folders
.idea
18 changes: 18 additions & 0 deletions web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
30 changes: 30 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
22 changes: 22 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Training react</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap"
rel="stylesheet"
/>
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined"
rel="stylesheet"
/>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
1 change: 1 addition & 0 deletions web/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions web/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
.header {
background-color: #fff;
height: 56px;
padding: 8px 0;
}

.search {
width: 480px;
position: relative;
margin: auto;
}

.search-input {
height: 40px;
width: 480px;
border-radius: 5px;
border: 1px solid rgb(212, 212, 212);
padding: 0 8px;
}

.btn-search {
position: absolute;
background-color: #fff;
border: none;
top: 7px;
right: 2px;
}

.container {
max-width: 1024px;
margin: auto;
padding: 20px;
}

.list-article {
display: flex;
flex-direction: column;
gap: 10px;
}

.article {
width: 736px;
min-height: 194px;
background-color: #fff;
margin: auto;
padding: 20px;
border-radius: 5px;
display: flex;
flex-direction: column;
justify-content: space-between;
}

.author {
display: flex;
gap: 20px;
}

.author-avatar {
border-radius: 50%;
width: 32px;
height: 32px;
}

.author-name {
font-size: 14px;
color: #3d3d3d;
}

.author-published {
font-size: 12px;
color: #525252;
}

.article-body {
margin-left: 60px;
}

.article-title {
font-weight: 700;
color: #171717;
font-size: 24px;
line-height: 30px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}

.article-tags {
display: flex;
gap: 5px;
}

.tag {
color: #404040;
font-size: 14px;
line-height: 21px;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
padding: 4px 7px;
}

.tag:hover {
background-color: rgb(229, 229, 229);
border-radius: 5px;
}

.article-footer {
display: flex;
justify-content: space-between;
margin-left: 60px;
}

.article-social {
display: flex;
gap: 5px;
}

.social {
color: #404040;
font-size: 14px;
line-height: 21px;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
gap: 5px;
padding: 4px 7px;
}

.social:hover {
background-color: rgb(229, 229, 229);
border-radius: 5px;
cursor: pointer;
}

.social .article-icon {
font-size: 16px;
}

.article-bookmark:hover {
background-color: rgb(229, 229, 229);
border-radius: 5px;
cursor: pointer;
}

.article-bookmark .material-symbols-outlined {
font-size: 20px;
display: flex;
justify-content: center;
align-items: center;
padding: 4px;
}
79 changes: 79 additions & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import './App.css'
import sampleData from '../../exercise/data.js'

function App() {
const articles = sampleData.map((article) =>
<div key={article.id} className="article">
<div className="article-header">
<div className="author">
<img
src={article.avatar}
alt="Author avatar"
className="author-avatar"
/>
<div className="author-info">
<p className="author-name">{article.username}</p>
<p className="author-published">{formatDate(article.publishedAt)}</p>
</div>
</div>
</div>
<div className="article-body">
<p className="article-title">{article.title}</p>
<ul className="article-tags">
{article.tags.map((tag, id) =>
<li key={id} className="article-tag">
<a href="#" className="tag">
#{tag}
</a>
</li>
)}
</ul>
</div>
<div className="article-footer">
<div className="article-social">
<span className="social">
<span className="article-icon material-symbols-outlined">
add_reaction
</span>
<span>{article.reactions} reactions</span>
</span>
<span className="social">
<span className="article-icon material-symbols-outlined">
chat_bubble
</span>
<span>{article.comments} comments</span>
</span>
</div>
<div className="article-bookmark">
<span className="article-icon material-symbols-outlined">
bookmark
</span>
</div>
</div>
</div>
);

return (
<>
<header className="header">
<div className="search">
<input type="text" className="search-input" />
<button className="btn-search">
<span className="material-symbols-outlined search__icon">search</span>
</button>
</div>
</header>
<div className="container">
<div className="list-article">
{articles}
</div>
</div>
</>
)
}

function formatDate(date: string) {
return new Date(date).toLocaleDateString('en-US', { year: '2-digit', month: 'short', day: '2-digit' });
}

export default App
1 change: 1 addition & 0 deletions web/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading