({
children,
app,
version,
deviceId,
localBootData,
getRedirectUri,
getPage,
}: BootDataProviderProps)
| 114 | }; |
| 115 | |
| 116 | export const BootDataProvider = ({ |
| 117 | children, |
| 118 | app, |
| 119 | version, |
| 120 | deviceId, |
| 121 | localBootData, |
| 122 | getRedirectUri, |
| 123 | getPage, |
| 124 | }: BootDataProviderProps): ReactElement => { |
| 125 | const queryClient = useQueryClient(); |
| 126 | |
| 127 | const [initialLoad, setInitialLoad] = useState<boolean>(); |
| 128 | const [cachedBootData, setCachedBootData] = useState<Partial<Boot>>(); |
| 129 | |
| 130 | useEffect(() => { |
| 131 | if (localBootData) { |
| 132 | setCachedBootData(localBootData); |
| 133 | |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | const boot = getLocalBootData(); |
| 138 | |
| 139 | if (!boot) { |
| 140 | setCachedBootData(undefined); |
| 141 | |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | if (boot?.settings?.theme) { |
| 146 | applyTheme(themeModes[boot.settings.theme]); |
| 147 | } |
| 148 | |
| 149 | setCachedBootData(boot); |
| 150 | }, [localBootData]); |
| 151 | |
| 152 | const { hostGranted } = useHostStatus(); |
| 153 | const isExtension = checkIsExtension(); |
| 154 | const logged = cachedBootData?.user as LoggedUser; |
| 155 | const shouldRefetch = !!logged?.providers && !!logged?.id; |
| 156 | const lastAppliedChangeRef = useRef<Partial<BootCacheData>>(); |
| 157 | |
| 158 | const { |
| 159 | data: remoteData, |
| 160 | error, |
| 161 | refetch, |
| 162 | isFetched, |
| 163 | isError, |
| 164 | dataUpdatedAt, |
| 165 | } = useQuery<Partial<Boot>>({ |
| 166 | queryKey: BOOT_QUERY_KEY, |
| 167 | queryFn: async () => { |
| 168 | const pathname = globalThis?.location?.pathname; |
| 169 | const result = await getBootData({ app, pathname }); |
| 170 | |
| 171 | return result; |
| 172 | }, |
| 173 | refetchOnWindowFocus: shouldRefetch, |
nothing calls this directly
no test coverage detected