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

Function BootDataProvider

packages/shared/src/contexts/BootProvider.tsx:116–433  ·  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 // `daily` is client-owned for the session: seeded from the server on the
158 // first boot response and mutated only via `setDaily`. It lives in memory
159 // (never written to the persisted boot cache) so background refetches don't
160 // revert the daily-as-default view mid-session; a full refresh re-seeds it.
161 const [dailyOverride, setDailyOverride] = useState<boolean>();
162
163 const {
164 data: remoteData,
165 error,
166 refetch,
167 isFetched,
168 isError,
169 dataUpdatedAt,
170 } = useQuery<Partial<Boot>>({
171 queryKey: BOOT_QUERY_KEY,
172 queryFn: async () => {
173 const pathname = globalThis?.location?.pathname;

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