feat(volume): serverseitig pro Guild persistieren (state.json), API GET/POST /api/volume; Frontend lädt gespeicherte Lautstärke
This commit is contained in:
parent
fee1feaca4
commit
beeffb7605
3 changed files with 71 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { fetchChannels, fetchSounds, playSound, setVolumeLive } from './api';
|
||||
import { fetchChannels, fetchSounds, playSound, setVolumeLive, getVolume } from './api';
|
||||
import type { VoiceChannelInfo, Sound } from './types';
|
||||
import { getCookie, setCookie } from './cookies';
|
||||
|
||||
|
|
@ -68,7 +68,17 @@ export default function App() {
|
|||
}, [theme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selected) localStorage.setItem('selectedChannel', selected);
|
||||
(async () => {
|
||||
if (selected) {
|
||||
localStorage.setItem('selectedChannel', selected);
|
||||
// gespeicherte Lautstärke vom Server laden
|
||||
try {
|
||||
const [guildId] = selected.split(':');
|
||||
const v = await getVolume(guildId);
|
||||
setVolume(v);
|
||||
} catch {}
|
||||
}
|
||||
})();
|
||||
}, [selected]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,15 @@ export async function setVolumeLive(guildId: string, volume: number): Promise<vo
|
|||
}
|
||||
}
|
||||
|
||||
export async function getVolume(guildId: string): Promise<number> {
|
||||
const url = new URL(`${API_BASE}/volume`, window.location.origin);
|
||||
url.searchParams.set('guildId', guildId);
|
||||
const res = await fetch(url.toString());
|
||||
if (!res.ok) throw new Error('Fehler beim Laden der Lautstärke');
|
||||
const data = await res.json();
|
||||
return typeof data?.volume === 'number' ? data.volume : 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue