fix(sse): Live-Update der Channel-Auswahl in allen Tabs (Ref gegen stale closure)
This commit is contained in:
parent
e83954624c
commit
c86f4f5875
1 changed files with 6 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ export default function App() {
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const [fuzzy, setFuzzy] = useState<boolean>(false);
|
const [fuzzy, setFuzzy] = useState<boolean>(false);
|
||||||
const [selected, setSelected] = useState<string>('');
|
const [selected, setSelected] = useState<string>('');
|
||||||
|
const selectedRef = useRef<string>('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [info, setInfo] = useState<string | null>(null);
|
const [info, setInfo] = useState<string | null>(null);
|
||||||
|
|
@ -55,6 +56,7 @@ export default function App() {
|
||||||
const chaosTimeoutRef = useRef<number | null>(null);
|
const chaosTimeoutRef = useRef<number | null>(null);
|
||||||
const chaosModeRef = useRef<boolean>(false);
|
const chaosModeRef = useRef<boolean>(false);
|
||||||
useEffect(() => { chaosModeRef.current = chaosMode; }, [chaosMode]);
|
useEffect(() => { chaosModeRef.current = chaosMode; }, [chaosMode]);
|
||||||
|
useEffect(() => { selectedRef.current = selected; }, [selected]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -97,7 +99,8 @@ export default function App() {
|
||||||
setPartyActiveGuilds(Array.isArray(msg.party) ? msg.party : []);
|
setPartyActiveGuilds(Array.isArray(msg.party) ? msg.party : []);
|
||||||
try {
|
try {
|
||||||
const sel = msg?.selected || {};
|
const sel = msg?.selected || {};
|
||||||
const gid = selected ? selected.split(':')[0] : '';
|
const currentSelected = selectedRef.current || '';
|
||||||
|
const gid = currentSelected ? currentSelected.split(':')[0] : '';
|
||||||
if (gid && sel[gid]) {
|
if (gid && sel[gid]) {
|
||||||
const newVal = `${gid}:${sel[gid]}`;
|
const newVal = `${gid}:${sel[gid]}`;
|
||||||
setSelected(newVal);
|
setSelected(newVal);
|
||||||
|
|
@ -108,7 +111,8 @@ export default function App() {
|
||||||
const gid = msg.guildId;
|
const gid = msg.guildId;
|
||||||
const cid = msg.channelId;
|
const cid = msg.channelId;
|
||||||
if (gid && cid) {
|
if (gid && cid) {
|
||||||
const curGid = selected ? selected.split(':')[0] : '';
|
const currentSelected = selectedRef.current || '';
|
||||||
|
const curGid = currentSelected ? currentSelected.split(':')[0] : '';
|
||||||
if (curGid === gid) setSelected(`${gid}:${cid}`);
|
if (curGid === gid) setSelected(`${gid}:${cid}`);
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue