Skip to content

Commit

Permalink
adding keyboard sound on search
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Faber authored and Cesar Faber committed Feb 9, 2024
1 parent dd0c21c commit bb1b661
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
31 changes: 7 additions & 24 deletions src/components/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from "classnames";
import Mousetrap from "mousetrap";

// Components
import { FiCoffee } from "@react-icons/all-files/fi/FiCoffee";
import { FiThumbsDown } from "@react-icons/all-files/fi/FiThumbsDown";

// Context
import { State } from "../Layout";
Expand All @@ -21,6 +21,7 @@ const Modal = () => {
const [list, setList] = React.useState(quickActionList);
const [cursor, setCursor] = React.useState(0);
const [typeListener, setTypeListener] = React.useState(null);
const [sound, setSound] = React.useState(new Audio(keytype));

const { modalIsOpened, setModalIsOpened, setCopied } =
React.useContext(State);
Expand Down Expand Up @@ -65,7 +66,7 @@ const Modal = () => {

Mousetrap.bind("enter", (e) => {
e.preventDefault();
if (cursor === 0) {
if (cursor === 0 && list.length > 1) {
return copyLink(list[0].textToCopy);
} else {
const link = document.querySelector(`#tablist-${cursor} a`);
Expand All @@ -79,6 +80,9 @@ const Modal = () => {

const onSearch = (e) => {
const value = e?.target?.value;
sound.currentTime = 0;
sound.volume = 0.05;
sound.play();
const newList = quickActionList.filter((item) =>
item?.text?.includes(value)
);
Expand Down Expand Up @@ -109,27 +113,6 @@ const Modal = () => {
setCursor(cursor + 1);
};

// React.useEffect(() => {
// const sound = new Audio(keytype);
// if (
// modalIsOpened &&
// document.activeElement.id === "shortcutid" &&
// !typeListener
// ) {
// const listener = document.addEventListener("keydown", (e) => {
// sound.currentTime = 0;
// sound.volume = 0.2;
// sound.play();
// });

// setTypeListener(listener);
// }

// if (!modalIsOpened) {
// document.removeEventListener("keydown", typeListener);
// }
// }, [modalIsOpened, typeListener]);

return (
<div
className={classNames("modal", {
Expand Down Expand Up @@ -198,7 +181,7 @@ const Modal = () => {
})
) : (
<div className="empty">
<FiCoffee /> nothing here, try again
<FiThumbsDown /> nothing here, try again
</div>
)}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

.empty {
padding: 10px 20px 30px 20px;
color: #6f7785;
color: #808080;
display: flex;
align-items: center;

Expand Down
2 changes: 1 addition & 1 deletion src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ button,
&.-toggle {
padding: 0;
font-size: 16px;
color: #6b717d;
color: #777777;

&:hover {
background: none;
Expand Down

0 comments on commit bb1b661

Please sign in to comment.