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