({
children,
app,
version,
deviceId,
localBootData,
getRedirectUri,
getPage,
}: BootDataProviderProps)
| 141 | }; |
| 142 | |
| 143 | export const BootDataProvider = ({ |
| 144 | children, |
| 145 | app, |
| 146 | version, |
| 147 | deviceId, |
| 148 | localBootData, |
| 149 | getRedirectUri, |
| 150 | getPage, |
| 151 | }: BootDataProviderProps): ReactElement => { |
| 152 | const queryClient = useQueryClient(); |
| 153 | |
| 154 | const [initialLoad, setInitialLoad] = useState<boolean>(); |
| 155 | const [cachedBootData, setCachedBootDataState] = |
| 156 | useState<Partial<BootCacheData>>(); |
| 157 | const cachedBootDataRef = useRef<Partial<BootCacheData>>(); |
| 158 | // Checked once on load, so the feed doesn't lose its query as the cached |
| 159 | // token nears expiry while boot is in flight |
| 160 | const [validTokenCache, setValidTokenCache] = |
| 161 | useState<Partial<BootCacheData>>(); |
| 162 | const [cachedTokenWasInvalid, setCachedTokenWasInvalid] = useState(false); |
| 163 | const setCachedBootData = useCallback( |
| 164 | (data: Partial<BootCacheData> | undefined) => { |
| 165 | cachedBootDataRef.current = data; |
| 166 | setCachedBootDataState(data); |
| 167 | }, |
| 168 | [], |
| 169 | ); |
| 170 | |
| 171 | useEffect(() => { |
| 172 | if (localBootData) { |
| 173 | setCachedBootData(localBootData); |
| 174 | setValidTokenCache( |
| 175 | isCachedTokenValid(localBootData) ? localBootData : undefined, |
| 176 | ); |
| 177 | |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | const boot = getLocalBootData(); |
| 182 | |
| 183 | if (!boot) { |
| 184 | setCachedBootData(undefined); |
| 185 | |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (boot?.settings?.theme) { |
| 190 | applyTheme(themeModes[boot.settings.theme]); |
| 191 | } |
| 192 | |
| 193 | setCachedBootData(boot); |
| 194 | setValidTokenCache(isCachedTokenValid(boot) ? boot : undefined); |
| 195 | }, [localBootData, setCachedBootData]); |
| 196 | |
| 197 | const { hostGranted } = useHostStatus(); |
| 198 | const isExtension = checkIsExtension(); |
| 199 | const logged = cachedBootData?.user as LoggedUser; |
| 200 | const shouldRefetch = !!logged?.providers && !!logged?.id; |
nothing calls this directly
no test coverage detected