New plugin: VoiceMessages (#1380)

Co-authored-by: V <vendicated@riseup.net>
Co-authored-by: Justice Almanzar <superdash993@gmail.com>
This commit is contained in:
V 2023-07-26 01:27:04 +02:00 committed by GitHub
parent 198b35ffdc
commit 8620a1d86d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 660 additions and 37 deletions

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { React, useEffect, useReducer, useState } from "@webpack/common";
import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common";
import { makeLazy } from "./lazy";
import { checkIntersecting } from "./misc";
@ -135,3 +135,24 @@ export function LazyComponent<T extends object = any>(factory: () => React.Compo
return <Component {...props} />;
};
}
interface TimerOpts {
interval?: number;
deps?: unknown[];
}
export function useTimer({ interval = 1000, deps = [] }: TimerOpts) {
const [time, setTime] = useState(0);
const start = useMemo(() => Date.now(), deps);
useEffect(() => {
const intervalId = setInterval(() => setTime(Date.now() - start), interval);
return () => {
setTime(0);
clearInterval(intervalId);
};
}, deps);
return time;
}