This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Akkarapon Phikulsri
committed
May 10, 2022
1 parent
0525863
commit b19bb38
Showing
41 changed files
with
4,610 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,95 @@ | ||
# next-app-init | ||
next redux | ||
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). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
|
||
``` | ||
|
||
## Project structure | ||
``` | ||
next-app-init | ||
┣ components | ||
┃ ┗ Layout.jsx | ||
┣ helpers | ||
┃ ┗ useLocalStorage.js | ||
┣ pages | ||
┃ ┣ index.jsx | ||
┃ ┗ _app.jsx | ||
┣ public | ||
┃ ┣ android-chrome-192x192.png | ||
┃ ┣ android-chrome-512x512.png | ||
┃ ┣ apple-touch-icon.png | ||
┃ ┣ billowdev.png | ||
┃ ┣ favicon-16x16.png | ||
┃ ┣ favicon-32x32.png | ||
┃ ┣ favicon.ico | ||
┃ ┗ site.webmanifest | ||
┣ redux | ||
┃ ┣ actions | ||
┃ ┃ ┣ aticles.js | ||
┃ ┃ ┗ ui.js | ||
┃ ┣ middleware | ||
┃ ┃ ┣ articles.js | ||
┃ ┃ ┣ index.js | ||
┃ ┃ ┗ ui.js | ||
┃ ┣ reducers | ||
┃ ┃ ┣ articles.js | ||
┃ ┃ ┣ index.js | ||
┃ ┃ ┗ ui.js | ||
┃ ┣ selectors | ||
┃ ┃ ┣ articles.js | ||
┃ ┃ ┗ ui.js | ||
┃ ┗ store.js | ||
┣ services | ||
┃ ┣ api | ||
┃ ┃ ┣ articles.js | ||
┃ ┃ ┗ index.js | ||
┃ ┣ logger | ||
┃ ┃ ┣ console.js | ||
┃ ┃ ┗ elasticSearch.js | ||
┃ ┗ index.js | ||
┣ styles | ||
┃ ┣ globals.css | ||
┃ ┗ Home.module.css | ||
┣ tests | ||
┃ ┣ articles.test.js | ||
┃ ┗ ui.test.js | ||
┣ .env.local | ||
┣ .eslintrc.json | ||
┣ .gitignore | ||
┣ config.js | ||
┣ jest.config.js | ||
┣ next.config.js | ||
┣ package.json | ||
┣ README.md | ||
┗ yarn.lock | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. | ||
|
||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. | ||
|
||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
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. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default { | ||
env: process.env.NEXT_PUBLIC_NODE_ENV, | ||
API_ENDPOINT: process.env.NEXT_PUBLIC_API_ENDPOINT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_API_ENDPOINT= " YOUR API ENDPOINT" | ||
NEXT_PUBLIC_NODE_ENV= " production || development" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import log from "../services/logger/console"; | ||
|
||
export const loadLocalStorage = (key) => { | ||
try { | ||
const serializedState = localStorage.getItem(key); | ||
if (!serializedState) { | ||
return undefined; | ||
} else { | ||
return JSON.parse(serializedState); | ||
} | ||
} catch (err) { | ||
log({ success: false, msg: "error on load state persist", error: err }); | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const saveLocalStorage = async (key, state) => { | ||
try { | ||
const serializedState = JSON.stringify(state); | ||
localStorage.setItem(key, serializedState); | ||
} catch (err) { | ||
log({ success: false, msg: "on persist state", err }) | ||
} | ||
}; | ||
|
||
export const clearLocalStorageWithKey = (key) => { | ||
try { | ||
const serializedState = localStorage.removeItem(key); | ||
if (!serializedState) { | ||
return undefined; | ||
} else { | ||
return JSON.parse(serializedState); | ||
} | ||
} catch (err) { | ||
log({ success: false, msg: "error on load state persist", error: err }); | ||
return undefined; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// jest.config.js | ||
const nextJest = require('next/jest') | ||
|
||
const createJestConfig = nextJest() | ||
|
||
const customJestConfig = { | ||
// ...your custom config | ||
} | ||
|
||
// createJestConfig returns an async function that returns a jest config - | ||
// so instead of doing this: | ||
// module.exports = createJestConfig(customJestConfig) | ||
|
||
// Take the returned async function... | ||
const asyncConfig = createJestConfig(customJestConfig) | ||
|
||
// and wrap it... | ||
module.exports = async () => { | ||
const config = await asyncConfig() | ||
config.transformIgnorePatterns = [ | ||
// ...your ignore patterns | ||
] | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('next').NextConfig} */ | ||
|
||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
|
||
module.exports = nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "billowdev-client", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint", | ||
"test": "jest --watch" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"next": "12.1.6", | ||
"react": "18.1.0", | ||
"react-dom": "18.1.0", | ||
"react-redux": "^8.0.1", | ||
"redux": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.17.10", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.2.0", | ||
"eslint": "8.15.0", | ||
"eslint-config-next": "12.1.6", | ||
"jest": "^28.1.0" | ||
}, | ||
"repository": "https://github.com/billowdev/next-redux-app-init", | ||
"license": "ISC", | ||
"description": "next.js react-redux axios", | ||
"main": "index.js", | ||
"author": "Akkarapon Phikulsri <[email protected]>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import "../styles/globals.css"; | ||
import { Provider } from "react-redux"; | ||
import { configureStore } from "../redux/store"; | ||
import services from "../services"; | ||
|
||
const App = ({ Component, pageProps }) => { | ||
return ( | ||
<> | ||
<Provider store={configureStore(services)}> | ||
<Component {...pageProps} /> | ||
</Provider> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import Head from "next/head"; | ||
import Image from "next/image"; | ||
import styles from "../styles/Home.module.css"; | ||
import { useEffect, useState } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { pageLoaded } from "../redux/actions/ui"; | ||
import { loadArticles } from "../redux/actions/aticles"; | ||
import { | ||
getArticlesData, | ||
getArticlesIncluded, | ||
} from "../redux/selectors/articles"; | ||
import { loadLocalStorage } from "../helpers/useLocalStorage"; | ||
|
||
export default function Home() { | ||
const dispatch = useDispatch(); | ||
const articleData = useSelector(getArticlesData); | ||
const articleIncluded = useSelector(getArticlesIncluded); | ||
const [dataLocal, setDataLocal] = useState(""); | ||
useEffect(() => { | ||
return () => { | ||
dispatch(pageLoaded); | ||
dispatch(loadArticles()); | ||
}; | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
setDataLocal(loadLocalStorage("action")); | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Head> | ||
<title>next app init redux</title> | ||
<meta name="description" content="Generated by create next app" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</Head> | ||
|
||
<main className={styles.main}> | ||
<h1 className={styles.title}> | ||
Launch | ||
<a href="https://github.com/billowdev/next-redux-app-init"> | ||
next-redux-app-init | ||
</a> | ||
</h1> | ||
|
||
<p className={styles.description}> | ||
Get started by editing | ||
<code className={styles.code}>pages/index.js</code> | ||
</p> | ||
|
||
<p className={styles.description}> | ||
example use localstorage <br /> | ||
<code className={styles.code}> | ||
key: action value:{dataLocal} <br/> | ||
</code> | ||
</p> | ||
|
||
<p className={styles.description}> | ||
Project structure <br /> | ||
<code className={styles.code}> | ||
|
||
</code> | ||
</p> | ||
|
||
<div className={styles.jsonApi}> | ||
<h2>GitHub JSON API →</h2> | ||
<p>test dispatch data</p> | ||
<div> | ||
{articleData?.map((data, idx) => { | ||
return ( | ||
<p key={data.id}> | ||
id: {data.id} <br /> | ||
type: {data.type} <br /> | ||
title: {data.attributes?.title} <br /> | ||
body: {data.attributes?.body} <br /> | ||
- Relationship - <br /> | ||
id:{articleIncluded[idx].id} <br /> | ||
type: {articleIncluded[idx].type} <br /> | ||
name: {articleIncluded[idx].attributes.name} | ||
</p> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
|
||
<div className={styles.grid}> | ||
<a href="https://nextjs.org/docs" className={styles.card}> | ||
<h2>Next.js →</h2> | ||
<p>Find in-depth information about Next.js features and API.</p> | ||
</a> | ||
|
||
<a href="https://redux.js.org/" className={styles.card}> | ||
<h2>Redux →</h2> | ||
<p>Discover and deploy boilerplate example Next.js projects.</p> | ||
</a> | ||
|
||
<a href="https://axios-http.com/docs/intro" className={styles.card}> | ||
<h2>Axios →</h2> | ||
<p> | ||
Axios is a promise-based HTTP Client for node.js and the browser. | ||
</p> | ||
</a> | ||
|
||
<a href="https://jestjs.io/" className={styles.card}> | ||
<h2>Jest →</h2> | ||
<p> | ||
Jest is a delightful JavaScript Testing Framework with a focus on | ||
simplicity. | ||
</p> | ||
</a> | ||
</div> | ||
</main> | ||
|
||
<footer className={styles.footer}> | ||
<a | ||
href="https://github.com/billowdev/next-redux-app-init" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
© 2022 billowdev All Rights Reserved | ||
</a>{" "} | ||
</footer> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} |
Oops, something went wrong.