diff --git a/.vscode/settings.json b/.vscode/settings.json index 966c51a4..b21272f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,7 +29,7 @@ "tryer", "urlparams" ], - "files.autoSave": "onWindowChange", + "files.autoSave": "off", "npm-scripts.showStartNotification": false, "editor.suggest.snippetsPreventQuickSuggestions": false, "aiXcoder.showTrayIcon": true, diff --git a/src/assets/svg/noise.svg b/src/assets/svg/noise.svg new file mode 100644 index 00000000..df85e7d2 --- /dev/null +++ b/src/assets/svg/noise.svg @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/src/components/hooks/useRandomInterval/index.jsx b/src/components/hooks/useRandomInterval/index.jsx new file mode 100644 index 00000000..7c827bcf --- /dev/null +++ b/src/components/hooks/useRandomInterval/index.jsx @@ -0,0 +1,41 @@ +import React from 'react' +// Utility helper for random number generation +const random = (min, max) => Math.floor(Math.random() * (max - min)) + min + +const useRandomInterval = (callback, minDelay, maxDelay) => { + const timeoutId = React.useRef(null) + const savedCallback = React.useRef(callback) + + React.useEffect(() => { + savedCallback.current = callback + }, [callback]) + + React.useEffect(() => { + let isEnabled = typeof minDelay === 'number' && typeof maxDelay === 'number' + + if (isEnabled) { + const handleTick = () => { + const nextTickAt = random(minDelay, maxDelay) + + timeoutId.current = window.setTimeout(() => { + savedCallback.current() + handleTick() + }, nextTickAt) + } + + handleTick() + } + + return () => window.clearTimeout(timeoutId.current) + }, [minDelay, maxDelay]) + + const cancel = React.useCallback(function () { + window.clearTimeout(timeoutId.current) + }, []) + + return cancel +} + +// const [value, setValue] = React.useState([400, 1000]); +// const [key, setKey] = React.useState(null); +// useRandomInterval(() => setKey(Math.random()), ...value); diff --git a/src/utils/publicFn/index.jsx b/src/utils/publicFn/index.jsx index 085bf0ea..87c97d58 100644 --- a/src/utils/publicFn/index.jsx +++ b/src/utils/publicFn/index.jsx @@ -173,3 +173,15 @@ export const openInNewTab = (url) => { win.focus() return win } + +export const range = (start, end, step = 1) => { + let output = [] + if (typeof end === 'undefined') { + end = start + start = 0 + } + for (let i = start; i < end; i += step) { + output.push(i) + } + return output +}