MCPcopy Create free account
hub / github.com/dailydotdev/apps / BootDataProvider

Function BootDataProvider

packages/shared/src/contexts/BootProvider.tsx:116–426  ·  view source on GitHub ↗
({
  children,
  app,
  version,
  deviceId,
  localBootData,
  getRedirectUri,
  getPage,
}: BootDataProviderProps)

Source from the content-addressed store, hash-verified

114};
115
116export 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,

Callers

nothing calls this directly

Calls 15

applyThemeFunction · 0.90
useHostStatusFunction · 0.90
checkIsExtensionFunction · 0.90
getBootDataFunction · 0.90
useRefreshTokenFunction · 0.90
getApiErrorFunction · 0.90
generateQueryKeyFunction · 0.90
getDailyClientPlatformFunction · 0.90
isIOSNativeFunction · 0.90
isConnectionErrorFunction · 0.90
getLocalBootDataFunction · 0.85
useDebounceFnFunction · 0.85

Tested by

no test coverage detected