code review
This commit is contained in:
@@ -48,10 +48,7 @@ const WARNING_AT_SECONDS =
|
|||||||
* the recording into the review step.
|
* the recording into the review step.
|
||||||
*/
|
*/
|
||||||
function useRecordingCountdown(active: boolean) {
|
function useRecordingCountdown(active: boolean) {
|
||||||
const [{ elapsed, isWarning }, setState] = useState({
|
const [elapsed, setElapsed] = useState(0);
|
||||||
elapsed: 0,
|
|
||||||
isWarning: false,
|
|
||||||
});
|
|
||||||
const requestIntent = useComposeIntentStore((s) => s.request);
|
const requestIntent = useComposeIntentStore((s) => s.request);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -59,9 +56,11 @@ function useRecordingCountdown(active: boolean) {
|
|||||||
|
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
|
// Tick faster than 1s so the auto-stop lands within ~250ms of the cap, but
|
||||||
|
// only re-render when the whole-second value actually changes.
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
const seconds = Math.floor((Date.now() - start) / 1000);
|
const seconds = Math.floor((Date.now() - start) / 1000);
|
||||||
setState({ elapsed: seconds, isWarning: seconds >= WARNING_AT_SECONDS });
|
setElapsed((prev) => (prev === seconds ? prev : seconds));
|
||||||
if (seconds >= RECORDING_MAX_DURATION_SECONDS && !stopped) {
|
if (seconds >= RECORDING_MAX_DURATION_SECONDS && !stopped) {
|
||||||
stopped = true;
|
stopped = true;
|
||||||
requestIntent('stop');
|
requestIntent('stop');
|
||||||
@@ -69,11 +68,11 @@ function useRecordingCountdown(active: boolean) {
|
|||||||
}, 250);
|
}, 250);
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
setState({ elapsed: 0, isWarning: false });
|
setElapsed(0);
|
||||||
};
|
};
|
||||||
}, [active, requestIntent]);
|
}, [active, requestIntent]);
|
||||||
|
|
||||||
return { elapsed, isWarning };
|
return { elapsed, isWarning: elapsed >= WARNING_AT_SECONDS };
|
||||||
}
|
}
|
||||||
|
|
||||||
function RecordingTimer({
|
function RecordingTimer({
|
||||||
|
|||||||
Reference in New Issue
Block a user