Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit 17eca9c

Browse files
author
Akkarapon Phikulsri
committed
update v1.1
1 parent 57d639e commit 17eca9c

27 files changed

+471
-52
lines changed

.babelrc

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": [
6+
"inline-dotenv",
7+
["styled-components", { "ssr": true }],
8+
["module-resolver", {
9+
"root": ["./src"]
10+
}]
11+
],
12+
"env": {
13+
"test": {
14+
"presets": [
15+
["next/babel", {
16+
"preset-env": {
17+
"modules": "commonjs"
18+
}
19+
}]
20+
]
21+
}
22+
}
23+
}
24+

.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NEXT_PUBLIC_API_ENDPOINT=https://raw.githubusercontent.com/billowdev/json/main/
2+
NEXT_PUBLIC_NODE_ENV=production

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
"scripts": {
66
"dev": "next dev",
77
"build": "next build",
8+
"build-html": "next build && next export",
89
"start": "next start",
910
"lint": "next lint",
10-
"test": "jest --watch"
11+
"test": "jest --watch",
12+
"clean": "rimraf node_modules/.cache .next"
1113
},
1214
"dependencies": {
1315
"axios": "^0.27.2",
1416
"next": "12.1.6",
17+
"next-redux-wrapper": "^7.0.5",
1518
"react": "18.1.0",
1619
"react-dom": "18.1.0",
1720
"react-redux": "^8.0.1",
@@ -22,6 +25,12 @@
2225
"@babel/core": "^7.17.10",
2326
"@testing-library/jest-dom": "^5.16.4",
2427
"@testing-library/react": "^13.2.0",
28+
"babel-core": "^6.26.3",
29+
"babel-eslint": "^10.1.0",
30+
"babel-jest": "^28.1.0",
31+
"babel-plugin-inline-dotenv": "^1.7.0",
32+
"babel-plugin-module-resolver": "^4.1.0",
33+
"babel-plugin-styled-components": "^2.0.7",
2534
"eslint": "8.15.0",
2635
"eslint-config-next": "12.1.6",
2736
"jest": "^28.1.0"

pages/_app.jsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import "../styles/globals.css";
2-
import { Provider } from "react-redux";
3-
import { configureStore } from "../redux/store";
4-
import services from "../services";
5-
2+
import { wrapper } from "redux/store";
63
const App = ({ Component, pageProps }) => {
74
return (
85
<>
9-
<Provider store={configureStore(services)}>
10-
<Component {...pageProps} />
11-
</Provider>
6+
<Component {...pageProps} />
127
</>
138
);
149
};
1510

16-
export default App;
11+
export default wrapper.withRedux(App);

pages/index.jsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@ import Image from "next/image";
33
import styles from "../styles/Home.module.css";
44
import { useEffect, useState } from "react";
55
import { useDispatch, useSelector } from "react-redux";
6-
import { pageLoaded } from "../redux/actions/ui";
7-
import { loadArticles } from "../redux/actions/aticles";
8-
import {
9-
getArticlesData,
10-
getArticlesIncluded,
11-
} from "../redux/selectors/articles";
12-
import { loadLocalStorage } from "../helpers/useLocalStorage";
6+
import { pageLoaded } from "redux/actions/ui";
7+
import { loadArticles } from "redux/actions/aticles";
8+
import { getArticlesData, getArticlesIncluded } from "redux/selectors/articles";
9+
import { loadLocalStorage } from "helpers/useLocalStorage";
1310

1411
export default function Home() {
1512
const dispatch = useDispatch();
1613
const articleData = useSelector(getArticlesData);
1714
const articleIncluded = useSelector(getArticlesIncluded);
1815
const [dataLocal, setDataLocal] = useState("");
1916
useEffect(() => {
20-
return () => {
21-
dispatch(pageLoaded);
22-
dispatch(loadArticles());
23-
};
17+
dispatch(pageLoaded);
18+
dispatch(loadArticles());
2419
}, [dispatch]);
2520

2621
useEffect(() => {

redux/store.js

-16
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/redux/store.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { compose, applyMiddleware, createStore } from "redux";
2+
import rootReducers from "./reducers"
3+
import middleware from "./middleware";
4+
import config from "../../config";
5+
import services from "../services"
6+
import { createWrapper } from "next-redux-wrapper";
7+
8+
9+
const composeEnhancers = (
10+
config.env === "development"
11+
&&
12+
(typeof window !== "undefined") ?
13+
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
14+
: f => f) || compose;
15+
16+
const initialStore = () => {
17+
return createStore(rootReducers, composeEnhancers(
18+
applyMiddleware(...middleware.map(f => f(services)))))
19+
}
20+
21+
export const wrapper = createWrapper(initialStore)
22+

services/api/articles.js renamed to src/services/api/articles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios";
2-
import config from "../../config"
2+
import config from "../../../config"
33
const BASE_URL = config.API_ENDPOINT;
44
export default {
55
getArticles: async () => {
File renamed without changes.

services/index.js renamed to src/services/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import consoleLogger from "./logger/console";
22
import elasticSearch from "./logger/elasticSearch"
33
import api from "./api"
4-
import config from "../config";
4+
import config from "../../config";
55

66
const services = {
77
log: config.env === "development" ? consoleLogger : elasticSearch,
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)