Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 6: Add sound for send-message and toggle button #161

Merged
merged 6 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-icons": "^4.4.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"use-sound": "^4.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/components/BottomInputComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { BsFillArrowUpSquareFill } from "react-icons/bs"
import Container from "react-bootstrap/Container"
import Navbar from "react-bootstrap/Navbar"
import { ThemeContext } from "../context.js"
// import use-sound React hook for sound effects
import useSound from "use-sound"
import buttonSound from "../sounds/stories_sounds_boop.mp3"

function BottomInputComponent({ currentUser, isFocused }) {
const [message, setMessage] = useState("")
Expand Down Expand Up @@ -34,7 +37,7 @@ function BottomInputComponent({ currentUser, isFocused }) {
}
}

// ========================================================
// ========================================================
// add character limit & prevent page reload on space submission
// ========================================================
const handleSubmitMessage = (e) => {
Expand All @@ -44,9 +47,12 @@ function BottomInputComponent({ currentUser, isFocused }) {
e.preventDefault()
saveMessage(message)
setMessage("")
buttonSfx()
}
}

const [buttonSfx] = useSound(buttonSound)

// Perform focus on input field's element via the DOM API when component renders/dependency changes
// (imperative approach)
const inputRef = React.useRef()
Expand Down
1 change: 1 addition & 0 deletions src/components/TopNavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import UserLogo from "../assets/sparrow-user-profile.svg"

function TopNavigationBar({ currentUser }) {
const { toggle } = useContext(ThemeContext)

// When signing out removes user from 'users' collection and signs out user.
const handleSignOutUser = () => {
removeUser(currentUser)
Expand Down
4 changes: 4 additions & 0 deletions src/context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect } from "react"
import { createContext, useState } from "react"
import useSound from "use-sound"
import toggleSound from "./sounds/stories_sounds_switch-off.mp3"

//theme object
const themes = {
Expand Down Expand Up @@ -43,7 +45,9 @@ function ThemeContextProvider({ children }) {
localStorage.setItem("light", JSON.stringify(isLight))
setLight(isLight)
setToggleOn(!toggleOn)
toggleSfx()
}
const [toggleSfx] = useSound(toggleSound)

const theme = light ? themes.light : themes.dark

Expand Down
Binary file added src/sounds/arcade-button.mp3
Binary file not shown.
Binary file added src/sounds/beep-error.mp3
Binary file not shown.
Binary file added src/sounds/login.mp3
Binary file not shown.
Binary file added src/sounds/logout.mp3
Binary file not shown.
Binary file added src/sounds/stories_sounds_boop.mp3
Binary file not shown.
Binary file added src/sounds/stories_sounds_switch-off.mp3
Binary file not shown.