mirror of
https://dev.azure.com/tstanciu94/PhantomMind/_git/Bitip
synced 2025-10-13 01:52:19 +03:00
refactor: add DEBOUNCE_MS to runtime configuration and update usage in Home component
This commit is contained in:
parent
91f667e4c3
commit
e3e77e3d98
@ -34,6 +34,7 @@ export function generateRuntimeConfig(
|
|||||||
const envConfig = {
|
const envConfig = {
|
||||||
BASE_PATH: basePath || '/',
|
BASE_PATH: basePath || '/',
|
||||||
FRONTEND_API_KEY: config.apiKeys.frontend,
|
FRONTEND_API_KEY: config.apiKeys.frontend,
|
||||||
|
DEBOUNCE_MS: config.debounceMs,
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
window.env = {
|
window.env = {
|
||||||
"BASE_PATH": "/",
|
"BASE_PATH": "/",
|
||||||
"FRONTEND_API_KEY": "frontend-dev-key"
|
"FRONTEND_API_KEY": "frontend-dev-key",
|
||||||
|
"DEBOUNCE_MS": 2000
|
||||||
};
|
};
|
||||||
|
@ -3,9 +3,7 @@ import MapComponent from '../components/MapComponent';
|
|||||||
import BitipAPI from '../services/api';
|
import BitipAPI from '../services/api';
|
||||||
import { SimplifiedGeoIPResponse } from '../types';
|
import { SimplifiedGeoIPResponse } from '../types';
|
||||||
import './Home.css';
|
import './Home.css';
|
||||||
|
import config from '../services/config';
|
||||||
const DEBOUNCE_MS =
|
|
||||||
parseInt(import.meta.env.VITE_DEBOUNCE_MS as string) || 2000;
|
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
const [inputIP, setInputIP] = useState<string>('');
|
const [inputIP, setInputIP] = useState<string>('');
|
||||||
@ -31,7 +29,7 @@ const Home: React.FC = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, DEBOUNCE_MS),
|
}, config.DEBOUNCE_MS),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
12
src/frontend/src/services/config.ts
Normal file
12
src/frontend/src/services/config.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const runtimeEnv = window.env || {};
|
||||||
|
const compileEnv = import.meta.env;
|
||||||
|
|
||||||
|
const DEBOUNCE_MS =
|
||||||
|
runtimeEnv.DEBOUNCE_MS || parseInt(compileEnv.VITE_DEBOUNCE_MS);
|
||||||
|
|
||||||
|
const processedEnv = {
|
||||||
|
DEBOUNCE_MS,
|
||||||
|
};
|
||||||
|
|
||||||
|
const env = { ...compileEnv, ...runtimeEnv, ...processedEnv };
|
||||||
|
export default env;
|
1
src/frontend/src/types/globals.d.ts
vendored
1
src/frontend/src/types/globals.d.ts
vendored
@ -12,6 +12,7 @@ declare global {
|
|||||||
env: {
|
env: {
|
||||||
BASE_PATH: string;
|
BASE_PATH: string;
|
||||||
FRONTEND_API_KEY: string;
|
FRONTEND_API_KEY: string;
|
||||||
|
DEBOUNCE_MS: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user