-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prompt submission sound and settings
- Loading branch information
1 parent
cd6ed14
commit 0c158ad
Showing
18 changed files
with
128 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import useIsMounted from "./use-is-mounted"; | ||
|
||
export function useStickyState<T>(defaultValue: T, key: string) { | ||
const isMounted = useIsMounted(); | ||
|
||
const [value, setValue] = useState<T>(defaultValue); | ||
|
||
useEffect(() => { | ||
if (isMounted) { | ||
const stickyValue = window.localStorage.getItem(key); | ||
setValue(stickyValue ? JSON.parse(stickyValue) : defaultValue); | ||
} | ||
}, [defaultValue, isMounted, key]); | ||
|
||
useEffect(() => { | ||
if (isMounted) { | ||
window.localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
}, [key, value]); | ||
|
||
return [value, setValue] as const; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import { Dispatch, SetStateAction, createContext } from "react"; | ||
import { useStickyState } from "./hooks/use-sticky-state"; | ||
|
||
export const SoundContext = createContext<{ | ||
soundEnabled: boolean; | ||
setSoundEnabled: Dispatch<SetStateAction<boolean>>; | ||
}>({ | ||
soundEnabled: true, | ||
setSoundEnabled: () => {}, | ||
}); | ||
|
||
export default function SoundProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const [soundEnabled, setSoundEnabled] = useStickyState(true, "soundEnabled"); | ||
|
||
return ( | ||
<SoundContext.Provider value={{ soundEnabled, setSoundEnabled }}> | ||
{children} | ||
</SoundContext.Provider> | ||
); | ||
} |
Oops, something went wrong.