🆙 Update Rare-Value page and fix the loading of the json

This commit is contained in:
duckietm
2026-05-29 08:31:18 +02:00
parent 47e8338570
commit fbcda88cd3
4 changed files with 84 additions and 44 deletions
+3 -1
View File
@@ -31,7 +31,9 @@ const useRadioState = () =>
if(loadStartedRef.current) return;
loadStartedRef.current = true;
const url = GetConfigurationValue<string>('radio.stations.url') || 'configuration/radio-stations.json5';
const url = GetConfigurationValue<string>('radio.url')
|| GetConfigurationValue<string>('radio.stations.url')
|| 'configuration/radio-stations.json5';
(async () =>
{
@@ -32,18 +32,6 @@ const CLIENT_COMMANDS: { key: string; descriptionKey: string }[] = [
{ key: 'nitro', descriptionKey: 'chatcmd.client.info' },
];
/**
* Server-pushed command cache. Lives in a Zustand store (instead of
* module-level `let` variables) so the React Compiler can analyze the
* surrounding hook cleanly, and so a future test can `setState({…})`
* a deterministic fixture without monkey-patching the module.
*
* The `isListenerRegistered` flag prevents the renderer from getting
* two AvailableCommandsEvent listeners — one from the module-level
* pre-mount registration (which captures the server's reply that lands
* during login, BEFORE any React widget mounts) and one from the
* in-hook `useMessageEvent` (which covers later rank-change refreshes).
*/
interface ChatCommandStore
{
serverCommands: CommandDefinition[];
@@ -74,15 +62,9 @@ const ensureGlobalListener = (): void =>
GetCommunication().registerMessageEvent(event);
useChatCommandStore.getState().markListenerRegistered();
}
catch
{
// Communication not ready yet — the in-hook useMessageEvent
// below covers later mounts.
}
catch {}
};
// Try once at module load so the server's response landing before any
// React mount still hits the cache.
ensureGlobalListener();
export const useChatCommandSelector = (chatValue: string) =>
@@ -94,13 +76,9 @@ export const useChatCommandSelector = (chatValue: string) =>
useEffect(() =>
{
// Cover the case where the module-level registration failed
// because GetCommunication() wasn't ready at import time.
ensureGlobalListener();
}, []);
// Late updates (rank change, etc.) — go through the store so all
// consumers see the same data.
useMessageEvent<AvailableCommandsEvent>(AvailableCommandsEvent, event =>
{
const parser = event.getParser();
@@ -164,13 +142,11 @@ export const useChatCommandSelector = (chatValue: string) =>
setDismissed(true);
}, []);
// Reset dismissed when chatValue changes to a new command start
useEffect(() =>
{
if(chatValue === ':' || chatValue === '') setDismissed(false);
}, [ chatValue ]);
// Reset selectedIndex when filtered list changes
useEffect(() =>
{
setSelectedIndex(0);
+3 -1
View File
@@ -65,7 +65,9 @@ const useSoundboardState = () =>
if(!enabled || serverSounds.length || fileLoadStartedRef.current) return;
fileLoadStartedRef.current = true;
const url = GetConfigurationValue<string>('soundboard.sounds.url') || 'configuration/soundboard-sounds.json5';
const url = GetConfigurationValue<string>('soundboard.url')
|| GetConfigurationValue<string>('soundboard.sounds.url')
|| 'configuration/soundboard-sounds.json5';
(async () =>
{