Skip to content

Commit

Permalink
fix: added active-class and removed old loader
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 authored and martinstark committed Apr 19, 2024
1 parent a0f360b commit 7c84c3b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/production-line/long-press-to-talk-button.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { useEffect, useState } from "react";
import styled from "@emotion/styled";
import { ActionButton } from "../landing-page/form-elements";
import { PulseLoader } from "../loader/loader";
import { isMobile } from "../../bowser";

type TLongPressToTalkButton = {
micMute: boolean;
setMicMute: (input: boolean) => void;
};

const Button = styled(ActionButton)`
position: relative;
&:active {
&.active-btn {
color: rgba(255, 255, 255, 0);
animation: pulse 0.7s ease-in-out infinite alternate;
}
Expand All @@ -32,9 +30,9 @@ const Button = styled(ActionButton)`
`;

export const LongPressToTalkButton = ({
micMute,
setMicMute,
}: TLongPressToTalkButton) => {
const [isToggled, setIsToggled] = useState(false);
const [longPressTimeout, setLongPressTimeout] =
useState<ReturnType<typeof setTimeout>>();

Expand All @@ -57,10 +55,12 @@ export const LongPressToTalkButton = ({
case "pointerdown":
timeoutId = setTimeout(() => {
setMicMute(false);
setIsToggled(true);
}, 300);
setLongPressTimeout(timeoutId);
break;
case "pointerup":
setIsToggled(false);
setMicMute(true);
clearTimeout(longPressTimeout);
break;
Expand All @@ -71,7 +71,7 @@ export const LongPressToTalkButton = ({

return (
<Button
className={isMobile ? "mobile" : ""}
className={`${isMobile ? "mobile" : ""} ${isToggled ? "active-btn" : ""}`}
type="button"
onPointerDown={(e) => {
toggleMuteAfterTimeout(e);
Expand All @@ -81,7 +81,6 @@ export const LongPressToTalkButton = ({
}}
>
Press to Talk
{!micMute && <PulseLoader />}
</Button>
);
};

0 comments on commit 7c84c3b

Please sign in to comment.