mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
Feature/floating notifications calling and twitter (#112)
* Add floating notifications :O * Add phone notifications and refactor calling ui * This is unsafe * Fix controls null check * Remove go to alert * Fix phone stuck after call * Remove lazy mount for Phone * Fix open/close cl_main * Use effect for notification visibility * Remove all alerts when phone closes * Avoid re-render useNuiEvent * It works now :c
This commit is contained in:
1 parent
4633146d40
commit
f6d7a3dbe1
42 files changed
+869
-679
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { useDuration } from '../hooks/useDuration';
|
||||
|
||||
|
||||
const runTimer = (updatedTime, setDuration) => {
|
||||
let newTime = { ...updatedTime.current };
|
||||
if (newTime.m >= 60) {
|
||||
newTime = { ...newTime, h: newTime.h + 1, m: 0 };
|
||||
}
|
||||
if (newTime.s >= 60) {
|
||||
newTime = { ...newTime, m: newTime.m + 1, s: 0 };
|
||||
}
|
||||
if (newTime.ms >= 100) {
|
||||
newTime = { ...newTime, s: newTime.s + 1, ms: 0 };
|
||||
}
|
||||
|
||||
newTime = { ...newTime, ms: newTime.ms + 1 };
|
||||
updatedTime.current = newTime;
|
||||
setDuration(newTime);
|
||||
}
|
||||
|
||||
function CallTimer({ isAccepted }) {
|
||||
const { duration, setDuration } = useDuration();
|
||||
const updatedTime = useRef({ ms: 0, s: 0, m: 0, h: 0 });
|
||||
const timer = useRef(null)
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (isAccepted) {
|
||||
runTimer(updatedTime, setDuration)
|
||||
timer.current = setInterval(() => {
|
||||
runTimer(updatedTime, setDuration)
|
||||
}, 10);
|
||||
} else {
|
||||
clearInterval(timer.current);
|
||||
timer.current = null;
|
||||
}
|
||||
return () => clearInterval(timer.current)
|
||||
}, [isAccepted, setDuration]);
|
||||
|
||||
if (!duration) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
textAlign: 'center',
|
||||
marginTop: '2em',
|
||||
fontSize: 30,
|
||||
}}
|
||||
>
|
||||
<span>{duration.h >= 10 ? duration.h : '0' + duration.h}</span>
|
||||
:
|
||||
<span>{duration.m >= 10 ? duration.m : '0' + duration.m}</span>
|
||||
:
|
||||
<span>{duration.s >= 10 ? duration.s : '0' + duration.s}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default CallTimer;
|
||||
Reference in new issue
Block a user