-
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.
feat: add standard style workflow (#29)
- Loading branch information
1 parent
ed99e86
commit 2db6832
Showing
22 changed files
with
4,131 additions
and
472 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
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
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,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 ( | ||
<ApolloProvider client={client}> | ||
<App /> | ||
</ApolloProvider> | ||
); | ||
) |
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,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 ( | ||
<AuthProvider> | ||
<Router> | ||
<Container> | ||
<MenuBar /> | ||
<Route exact path="/" component={Home} /> | ||
<AuthRoute exact path="/login" component={Login} /> | ||
<AuthRoute exact path="/register" component={Register} /> | ||
<Route exact path='/' component={Home} /> | ||
<AuthRoute exact path='/login' component={Login} /> | ||
<AuthRoute exact path='/register' component={Register} /> | ||
</Container> | ||
</Router> | ||
</AuthProvider> | ||
); | ||
) | ||
} | ||
|
||
export default App; | ||
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 |
---|---|---|
@@ -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' | ||
}) | ||
}) |
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,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 ( | ||
<AuthContext.Provider | ||
value={{ user: state.user, login, logout }} | ||
{...props} | ||
></AuthContext.Provider> | ||
); | ||
/> | ||
) | ||
} | ||
|
||
export { AuthContext, AuthProvider }; | ||
export { AuthContext, AuthProvider } |
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,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')) |
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
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
Oops, something went wrong.