-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8108fbb
commit 08ae9bf
Showing
2 changed files
with
70 additions
and
60 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/plugins/customSounds/components/SoundOverrideComponent.tsx
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,68 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2023 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import { makeRange } from "@components/PluginSettings/components"; | ||
import { Margins } from "@utils/margins"; | ||
import { findByCodeLazy } from "@webpack"; | ||
import { Button, Card, Forms, Slider, Switch, TextInput, useRef } from "@webpack/common"; | ||
|
||
import { SoundOverride, SoundPlayer, SoundType } from "../types"; | ||
|
||
const playSound: (id: string) => SoundPlayer = findByCodeLazy(".playWithListener().then"); | ||
|
||
export function SoundComponent({ type, override }: { type: SoundType; override: SoundOverride; }) { | ||
const sound: React.MutableRefObject<SoundPlayer | null> = useRef(null); | ||
return ( | ||
<Card style={{ padding: "1em 1em 0" }}> | ||
<Switch | ||
value={override.enabled} | ||
onChange={value => override.enabled = value} | ||
hideBorder={true} | ||
> | ||
{type.name} <span style={{ color: "var(--text-muted)" }}>({type.id})</span> | ||
</Switch> | ||
<Button | ||
color={Button.Colors.PRIMARY} | ||
className={Margins.bottom16} | ||
onClick={() => { | ||
if (sound.current != null) | ||
sound.current.stop(); | ||
sound.current = playSound(type.id); | ||
}} | ||
disabled={!override.enabled} | ||
> | ||
Preview | ||
</Button> | ||
<Forms.FormTitle>File</Forms.FormTitle> | ||
<TextInput | ||
type="text" | ||
value={override.url} | ||
onChange={value => override.url = value} | ||
placeholder="Use default" | ||
className={Margins.bottom16} | ||
disabled={!override.enabled} | ||
/> | ||
<Button | ||
color={Button.Colors.PRIMARY} | ||
className={Margins.bottom16} | ||
size={Button.Sizes.MEDIUM} | ||
onClick={() => { | ||
}} | ||
disabled={!override.enabled} | ||
> | ||
Preview | ||
</Button> | ||
<Forms.FormTitle>Volume</Forms.FormTitle> | ||
<Slider | ||
markers={makeRange(0, 100, 10)} | ||
initialValue={override.volume} | ||
onValueChange={value => override.volume = value} | ||
className={Margins.bottom16} | ||
disabled={!override.enabled} | ||
/> | ||
</Card> | ||
); | ||
} |
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