Update appConfig to load synchronously (#14)

This commit is contained in:
mattherzog 2024-01-17 08:53:28 -08:00 committed by GitHub
parent aff08a2530
commit 26720c3389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,4 @@
import jsYaml from "js-yaml"; import jsYaml from "js-yaml";
import { useEffect, useState } from "react";
const APP_CONFIG = process.env.NEXT_PUBLIC_APP_CONFIG; const APP_CONFIG = process.env.NEXT_PUBLIC_APP_CONFIG;
@ -22,8 +21,8 @@ export type AppConfig = {
// Fallback if NEXT_PUBLIC_APP_CONFIG is not set // Fallback if NEXT_PUBLIC_APP_CONFIG is not set
const defaultConfig: AppConfig = { const defaultConfig: AppConfig = {
title: "Agent Playground", title: "Agents Playground",
description: "A playground for testing LiveKit agents", description: "A playground for testing LiveKit Agents",
theme_color: "cyan", theme_color: "cyan",
outputs: { outputs: {
audio: true, audio: true,
@ -38,20 +37,16 @@ const defaultConfig: AppConfig = {
}; };
export const useAppConfig = (): AppConfig => { export const useAppConfig = (): AppConfig => {
const [config, setConfig] = useState<any>(null); if (APP_CONFIG) {
useEffect(() => {
try { try {
if (APP_CONFIG) { const parsedConfig = jsYaml.load(APP_CONFIG);
const parsedConfig = jsYaml.load(APP_CONFIG); console.log("parsedConfig:", parsedConfig);
setConfig(parsedConfig); return parsedConfig as AppConfig;
console.log("parsedConfig:", parsedConfig); } catch (e) {
} else { console.error("Error parsing app config:", e);
setConfig(defaultConfig); return defaultConfig;
}
} catch (error) {
console.error("Error parsing NEXT_PUBLIC_APP_CONFIG:", error);
} }
}, []); } else {
return defaultConfig;
return config; }
}; };