Skip to content

Commit 6509300

Browse files
committed
add context
1 parent 5d2ee45 commit 6509300

File tree

9 files changed

+45
-24
lines changed

9 files changed

+45
-24
lines changed

eslint.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export default [
1010
files: ['**/*.{js,jsx}'],
1111
languageOptions: {
1212
ecmaVersion: 2020,
13-
globals: globals.browser,
13+
globals: {
14+
...globals.browser,
15+
__dirname: true
16+
},
1417
parserOptions: {
1518
ecmaVersion: 'latest',
1619
ecmaFeatures: { jsx: true },
@@ -30,7 +33,7 @@ export default [
3033
...reactHooks.configs.recommended.rules,
3134
'react/jsx-no-target-blank': 'off',
3235
'react-refresh/only-export-components': [
33-
'warn',
36+
'off',
3437
{ allowConstantExport: true },
3538
],
3639
},

jsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@*": [
5+
"./src/*"
6+
]
7+
}
8+
}
9+
}

src/components/FanMonitor.jsx src/components/FanMonitor/FanMonitor.jsx

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import PropTypes from 'prop-types';
2-
import { useFanStrategy } from '../contexts/FanStrategyContext';
3-
4-
const useFanMonitor = (strategyHook) => {
5-
const strategy = strategyHook();
6-
const { state, setSpeed, reset, validateSpeed } = strategy;
7-
const { speed, isRunning, warning } = state;
8-
9-
return {
10-
speed,
11-
isRunning,
12-
warning,
13-
reset,
14-
setSpeed,
15-
validateSpeed
16-
};
17-
};
2+
import { useFanStrategy } from './FanStrategyContext';
3+
import useFanMonitor from './useFanMonitor';
184

195
export const FanMonitor = ({ strategy }) => {
206
const contextStrategy = useFanStrategy;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const useFanMonitor = (strategyHook) => {
2+
const strategy = strategyHook();
3+
const { state, setSpeed, reset, validateSpeed } = strategy;
4+
const { speed, isRunning, warning } = state;
5+
6+
return {
7+
speed,
8+
isRunning,
9+
warning,
10+
reset,
11+
setSpeed,
12+
validateSpeed
13+
};
14+
};
15+
16+
export default useFanMonitor;

src/devices/desktop/DesktopFan.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FanMonitor } from '../../components/FanMonitor';
1+
import { FanMonitor } from '@components/FanMonitor/FanMonitor';
22
import { useDesktopFanStrategy } from './desktopFanStrategy';
3-
import { FanStrategyProvider } from '../../contexts/FanStrategyContext';
3+
import { FanStrategyProvider } from '@components/FanMonitor/FanStrategyContext';
44

55
export const DesktopFan = () => {
66
return (

src/devices/laptop/LaptopFan.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FanMonitor } from '../../components/FanMonitor';
1+
import { FanMonitor } from '@components/FanMonitor/FanMonitor';
22
import { useLaptopFanStrategy } from './laptopFanStrategy';
3-
import { FanStrategyProvider } from '../../contexts/FanStrategyContext';
3+
import { FanStrategyProvider } from '@components/FanMonitor/FanStrategyContext';
44

55
export const LaptopFan = () => {
66
return (

src/devices/server/ServerFan.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FanMonitor } from '../../components/FanMonitor';
1+
import { FanMonitor } from '@components/FanMonitor/FanMonitor';
22
import { useServerFanStrategy } from './serverFanStrategy';
3-
import { FanStrategyProvider } from '../../contexts/FanStrategyContext';
3+
import { FanStrategyProvider } from '@components/FanMonitor/FanStrategyContext';
44

55
export const ServerFan = () => {
66
return (

vite.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
3+
import path from 'path';
4+
35

46
// https://vite.dev/config/
57
export default defineConfig({
68
plugins: [react()],
9+
resolve: {
10+
alias: {
11+
'@components': path.resolve(__dirname, './src/components')
12+
}
13+
}
714
})

0 commit comments

Comments
 (0)