diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index abcc9dcb..7143e4ed 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -15,6 +15,17 @@ permissions:
pull-requests: write
jobs:
+ style:
+ name: JavaScript Standard Style
+ runs-on: ubuntu-latest
+ environment: testing
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Install dependencies
+ run: npm ci
+ - name: style
+ run: npm run style
test_server:
name: Server
runs-on: ubuntu-latest
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index 06cf9213..cd319f1d 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -18,6 +18,17 @@ permissions:
pull-requests: write
jobs:
+ style:
+ name: JavaScript Standard Style
+ runs-on: ubuntu-latest
+ environment: testing
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Install dependencies
+ run: npm ci
+ - name: style
+ run: npm run style
test_server:
name: Server
runs-on: ubuntu-latest
diff --git a/client/src/ApolloProvider.jsx b/client/src/ApolloProvider.jsx
index 6c2765d0..42028e45 100644
--- a/client/src/ApolloProvider.jsx
+++ b/client/src/ApolloProvider.jsx
@@ -1,21 +1,21 @@
-import React from "react";
-import App from "./App";
-import ApolloClient from "apollo-client";
-import { InMemoryCache } from "apollo-cache-inmemory";
-import { createHttpLink } from "apollo-link-http";
-import { ApolloProvider } from "@apollo/react-hooks";
+import React from 'react'
+import App from './App'
+import ApolloClient from 'apollo-client'
+import { InMemoryCache } from 'apollo-cache-inmemory'
+import { createHttpLink } from 'apollo-link-http'
+import { ApolloProvider } from '@apollo/react-hooks'
const httpLink = createHttpLink({
- uri: process.env.REACT_APP_HTTP_LINK,
-});
+ uri: process.env.REACT_APP_HTTP_LINK
+})
const client = new ApolloClient({
link: httpLink,
- cache: new InMemoryCache(),
-});
+ cache: new InMemoryCache()
+})
export default (
-);
+)
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 7b3b5a10..eca66245 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -1,23 +1,23 @@
-import { BrowserRouter as Router, Route } from "react-router-dom";
-import "semantic-ui-css/semantic.min.css";
-import { Container } from "semantic-ui-react";
-import { AuthProvider } from "./context/auth";
-import { Home, Login, MenuBar, Register } from "./pages";
-import AuthRoute from "./utilites/AuthRoute";
+import { BrowserRouter as Router, Route } from 'react-router-dom'
+import 'semantic-ui-css/semantic.min.css'
+import { Container } from 'semantic-ui-react'
+import { AuthProvider } from './context/auth'
+import { Home, Login, MenuBar, Register } from './pages'
+import AuthRoute from './utilites/AuthRoute'
-function App() {
+function App () {
return (
-
-
-
+
+
+
- );
+ )
}
-export default App;
+export default App
diff --git a/client/src/__tests__/demo.spec.js b/client/src/__tests__/demo.spec.js
index 3bc738d6..d0c3b4ff 100644
--- a/client/src/__tests__/demo.spec.js
+++ b/client/src/__tests__/demo.spec.js
@@ -1,12 +1,12 @@
-import { beforeEach, describe, it } from "vitest";
+import { beforeEach, describe, it } from 'vitest'
-describe("demo", () => {
+describe('demo', () => {
beforeEach(async (context) => {
// extend context
- context.foo = "bar";
- });
+ context.foo = 'bar'
+ })
- it("should work", ({ foo }) => {
- console.log(foo); // 'bar'
- });
-});
+ it('should work', ({ foo }) => {
+ console.log(foo) // 'bar'
+ })
+})
diff --git a/client/src/context/auth.jsx b/client/src/context/auth.jsx
index a415ad1a..4e568bcf 100644
--- a/client/src/context/auth.jsx
+++ b/client/src/context/auth.jsx
@@ -1,58 +1,58 @@
-import React, { createContext, useReducer } from "react";
-import jwtDecode from "jwt-decode";
+import React, { createContext, useReducer } from 'react'
+import jwtDecode from 'jwt-decode'
const initialState = {
- user: null,
-};
+ user: null
+}
-if (localStorage.getItem("AUTH_TOKEN")) {
- const decodeToken = jwtDecode(localStorage.getItem("AUTH_TOKEN"));
+if (window.localStorage.getItem('AUTH_TOKEN')) {
+ const decodeToken = jwtDecode(window.localStorage.getItem('AUTH_TOKEN'))
if (decodeToken.exp * 1000 < Date.now()) {
- localStorage.removeItem("AUTH_TOKEN");
+ window.localStorage.removeItem('AUTH_TOKEN')
} else {
- initialState.user = decodeToken;
+ initialState.user = decodeToken
}
}
const AuthContext = createContext({
user: null,
login: (userLogin) => {},
- logout: () => {},
-});
+ logout: () => {}
+})
-function authReducer(state, action) {
+function authReducer (state, action) {
switch (action.type) {
- case "LOGIN":
- return { ...state, user: action.payload };
- case "LOGOUT":
- return { ...state, user: null };
+ case 'LOGIN':
+ return { ...state, user: action.payload }
+ case 'LOGOUT':
+ return { ...state, user: null }
default:
- return state;
+ return state
}
}
-function AuthProvider(props) {
- const [state, dispatch] = useReducer(authReducer, initialState);
+function AuthProvider (props) {
+ const [state, dispatch] = useReducer(authReducer, initialState)
- function login(userLogin) {
- localStorage.setItem("AUTH_TOKEN", userLogin.token);
+ function login (userLogin) {
+ window.localStorage.setItem('AUTH_TOKEN', userLogin.token)
dispatch({
- type: "LOGIN",
- payload: userLogin,
- });
+ type: 'LOGIN',
+ payload: userLogin
+ })
}
- function logout() {
- localStorage.removeItem("AUTH_TOKEN");
- dispatch({ type: "LOGOUT" });
+ function logout () {
+ window.localStorage.removeItem('AUTH_TOKEN')
+ dispatch({ type: 'LOGOUT' })
}
return (
- );
+ />
+ )
}
-export { AuthContext, AuthProvider };
+export { AuthContext, AuthProvider }
diff --git a/client/src/index.js b/client/src/index.js
index 26aeaccc..9a6d5b28 100644
--- a/client/src/index.js
+++ b/client/src/index.js
@@ -1,4 +1,4 @@
-import ReactDOM from "react-dom";
-import ApolloProvider from "./ApolloProvider";
+import ReactDOM from 'react-dom'
+import ApolloProvider from './ApolloProvider'
-ReactDOM.render(ApolloProvider, document.getElementById("root"));
+ReactDOM.render(ApolloProvider, document.getElementById('root'))
diff --git a/client/src/pages/Home.jsx b/client/src/pages/Home.jsx
index 1d8eb4e7..41385480 100644
--- a/client/src/pages/Home.jsx
+++ b/client/src/pages/Home.jsx
@@ -1,16 +1,15 @@
-import React from "react";
-import { useQuery, gql } from "@apollo/client";
-import { Grid } from "semantic-ui-react";
-import PostCard from "./PostCard";
+import React from 'react'
+import { useQuery, gql } from '@apollo/client'
+import { Grid } from 'semantic-ui-react'
+import PostCard from './PostCard'
-function Home() {
+function Home () {
const {
loading,
- data,
- } = useQuery(FETCH_POSTS_QUERY);
-
- console.log(data);
+ data
+ } = useQuery(FETCH_POSTS_QUERY)
+ console.log(data)
return (
@@ -18,19 +17,21 @@ function Home() {
Recent Posts
- {loading ? (
- loading posts ...
- ) : (
- data &&
+ {loading
+ ? (
+ loading posts ...
+ )
+ : (
+ data &&
data.getPosts?.map((post) => (
))
- )}
+ )}
- );
+ )
}
const FETCH_POSTS_QUERY = gql`
@@ -42,5 +43,5 @@ const FETCH_POSTS_QUERY = gql`
createdAt
}
}
-`;
-export default Home;
+`
+export default Home
diff --git a/client/src/pages/Login.jsx b/client/src/pages/Login.jsx
index fbd08e2d..3d3fb97d 100644
--- a/client/src/pages/Login.jsx
+++ b/client/src/pages/Login.jsx
@@ -1,62 +1,62 @@
-import React, { useContext, useState } from "react";
-import { Button, Form } from "semantic-ui-react";
-import { useMutation, gql } from "@apollo/client";
-import { useForm } from "../utilites/hooks";
-import { AuthContext } from "../context/auth";
+import React, { useContext, useState } from 'react'
+import { Button, Form } from 'semantic-ui-react'
+import { useMutation, gql } from '@apollo/client'
+import { useForm } from '../utilites/hooks'
+import { AuthContext } from '../context/auth'
-function Login(props) {
- const context = useContext(AuthContext);
- const [errors, setErrors] = useState("");
+function Login (props) {
+ const context = useContext(AuthContext)
+ const [errors, setErrors] = useState('')
const { onSubmit, onChange, values } = useForm(loginUserCallback, {
- username: "",
- password: "",
- });
+ username: '',
+ password: ''
+ })
const [loginUser, { loading }] = useMutation(LOGIN_USER, {
- update(_, { data: { login: loginUser } }) {
- context.login(loginUser);
- props.history.push("/");
+ update (_, { data: { login: loginUser } }) {
+ context.login(loginUser)
+ props.history.push('/')
},
- onError(err) {
- setErrors(err.graphQLErrors[0].extensions.exception.errors);
+ onError (err) {
+ setErrors(err.graphQLErrors[0].extensions.exception.errors)
},
- variables: values,
- });
+ variables: values
+ })
- function loginUserCallback() {
- loginUser();
+ function loginUserCallback () {
+ loginUser()
}
return (
-
-