Skip to content

Commit

Permalink
feat: husky
Browse files Browse the repository at this point in the history
  • Loading branch information
yarre-uk committed Oct 26, 2023
1 parent 86b627f commit f900d32
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo test
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-i18next": "^13.3.0",
"react-redux": "^8.1.3",
"react-router-dom": "^6.16.0",
"redux-persist": "^6.0.0",
"styled-components": "^6.1.0",
"vite-tsconfig-paths": "^4.2.1",
"yup": "^1.3.2"
Expand All @@ -34,6 +35,7 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"husky": "^8.0.3",
"prettier": "3.0.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
Expand Down
12 changes: 10 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';

import App from './App';
import { persistor, store } from './store';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>
</React.StrictMode>,
);
14 changes: 14 additions & 0 deletions src/mocks/getMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function getMessages(
message: string,
amount: number,
seconds: number = 1,
): Promise<string[]> {
return new Promise((resolve) => {
setTimeout(
() => resolve(new Array<string>(amount).fill(message)),
seconds * 1000,
);
});
}

export default getMessages;
1 change: 1 addition & 0 deletions src/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as getMessages } from './getMessages';
10 changes: 10 additions & 0 deletions src/store/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {
TypedUseSelectorHook,
useDispatch as useAppDispatch,
useSelector as useAppSelector,
} from 'react-redux';

import type { AppDispatch, RootState } from './store';

export const useDispatch = (): AppDispatch => useAppDispatch<AppDispatch>();
export const useSelector: TypedUseSelectorHook<RootState> = useAppSelector;
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { useDispatch, useSelector } from './hooks';
export { store, persistor, type RootState, type AppStore } from './store';
5 changes: 5 additions & 0 deletions src/store/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { combineReducers } from '@reduxjs/toolkit';

export const rootReducer = combineReducers({
// [AUTH_SLICE_NAME]: authReducer,
});
27 changes: 27 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { configureStore } from '@reduxjs/toolkit';
import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

import { rootReducer } from './rootReducer';

const persistConfig = {
key: 'root',
storage,
whitelist: [],
};

const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) => {
return getDefaultMiddleware({
serializableCheck: false,
});
},
});

export const persistor = persistStore(store);

export type AppStore = typeof store;
export type AppDispatch = AppStore['dispatch'];
export type RootState = ReturnType<AppStore['getState']>;
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"paths": {
"@/modules/*": ["./modules/*"],
"@constants/*": ["./shared/constants/*"],
"@styles/*": ["./shared/styles/*"]
"@styles/*": ["./shared/styles/*"],
"@/store": ["./store"],
"@/mocks": ["./mocks"]
}
},
"include": ["src"],
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,11 @@ html-parse-stringify@^3.0.1:
dependencies:
void-elements "3.1.0"

husky@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184"
integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==

i18next@^23.5.1:
version "23.5.1"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-23.5.1.tgz#7f7c35ffaa907618d9489f106d5006b09fbca3d3"
Expand Down Expand Up @@ -2255,6 +2260,11 @@ react@^18.2.0:
dependencies:
loose-envify "^1.1.0"

redux-persist@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8"
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==

redux-thunk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.4.2.tgz#b9d05d11994b99f7a91ea223e8b04cf0afa5ef3b"
Expand Down

0 comments on commit f900d32

Please sign in to comment.