Only show greeting once userConfig is fetched from server

- Pass userConfig from Home as prop to chatBodyData component with
  loading state
- Pass loading state of userConfig to allow components to handle
  rendering dependent elements once it is loaded
This commit is contained in:
Debanjum Singh Solanky
2024-08-02 20:03:51 +05:30
parent 0adee07d40
commit e62888659f
3 changed files with 26 additions and 11 deletions

View File

@@ -71,9 +71,9 @@ export interface UserConfig {
export function useUserConfig(detailed: boolean = false) {
const url = `/api/settings?detailed=${detailed}`;
const { data, error } = useSWR<UserConfig>(url, fetcher, { revalidateOnFocus: false });
const { data: userConfig, error, isLoading: isLoadingUserConfig } = useSWR<UserConfig>(url, fetcher, { revalidateOnFocus: false });
if (error || !data || data.detail === 'Forbidden') return null;
if (error || !userConfig || userConfig?.detail === 'Forbidden') return {userConfig: null, isLoadingUserConfig};
return data;
return {userConfig, isLoadingUserConfig};
}