|
1 | | -import { useCallback, useSyncExternalStore } from "react"; |
| 1 | +import { useCallback } from "react"; |
2 | 2 | import { SyncApi } from "@web/api/sync.api"; |
3 | 3 | import { getApiErrorCode, isApiError } from "@web/api/util/api.util"; |
4 | | -import { hasUserEverAuthenticated } from "@web/auth/compass/state/auth.state.util"; |
5 | 4 | import { useStartGoogleAuthorization } from "@web/auth/google/authorization/useStartGoogleAuthorization"; |
6 | 5 | import { |
7 | 6 | clearGoogleSyncIndicatorOverride, |
8 | | - getGoogleSyncIndicatorOverride, |
9 | 7 | setRepairingSyncIndicatorOverride, |
10 | | - subscribeToGoogleSyncUIState, |
11 | 8 | } from "@web/auth/google/state/google.sync.state"; |
12 | 9 | import { syncPendingLocalEvents } from "@web/auth/google/util/google.auth.util"; |
13 | | -import { |
14 | | - selectGoogleConnectionState, |
15 | | - selectUserMetadataStatus, |
16 | | - useUserMetadataStore, |
17 | | -} from "@web/auth/state/user-metadata.store"; |
18 | 10 | import { GOOGLE_REPAIR_FAILED_TOAST_ID } from "@web/common/constants/toast.constants"; |
19 | 11 | import { showErrorToast } from "@web/common/utils/toast/error-toast.util"; |
20 | 12 | import { settingsActions } from "@web/settings/settings.store"; |
21 | 13 | import { useIsGoogleAvailable } from "../useIsGoogleAvailable/useIsGoogleAvailable"; |
22 | | -import { |
23 | | - type GoogleUiState, |
24 | | - type UseConnectGoogleResult, |
25 | | -} from "./useConnectGoogle.types"; |
| 14 | +import { type UseConnectGoogleResult } from "./useConnectGoogle.types"; |
26 | 15 | import { getGoogleConnectionConfig } from "./useConnectGoogle.util"; |
27 | | - |
28 | | -// Merges store-derived Google connection state with transient UI overrides from |
29 | | -// google.sync.ui.state.ts; the override is read via useSyncExternalStore so React |
30 | | -// stays aligned with that external store (see comments there). |
| 16 | +import { useGoogleUiState } from "./useGoogleUiState"; |
31 | 17 |
|
32 | 18 | export const useConnectGoogle = (): UseConnectGoogleResult => { |
33 | 19 | const isAvailable = useIsGoogleAvailable(); |
34 | | - const connectionState = useUserMetadataStore(selectGoogleConnectionState); |
35 | | - const userMetadataStatus = useUserMetadataStore(selectUserMetadataStatus); |
36 | | - const syncIndicator = useSyncExternalStore( |
37 | | - subscribeToGoogleSyncUIState, |
38 | | - getGoogleSyncIndicatorOverride, |
39 | | - getGoogleSyncIndicatorOverride, |
40 | | - ); |
| 20 | + const state = useGoogleUiState(); |
41 | 21 | const { startGoogleAuthorization } = useStartGoogleAuthorization({ |
42 | 22 | intent: "connectCalendar", |
43 | 23 | prompt: "consent", |
@@ -88,21 +68,6 @@ export const useConnectGoogle = (): UseConnectGoogleResult => { |
88 | 68 | void startRepair(); |
89 | 69 | }, []); |
90 | 70 |
|
91 | | - // "checking" is a UI-only state until we have loaded metadata from the server. |
92 | | - // Covers both "idle" and "loading" so returning users do not briefly see |
93 | | - // NOT_CONNECTED from the selector default. |
94 | | - const isCheckingStatus = |
95 | | - hasUserEverAuthenticated() && userMetadataStatus !== "loaded"; |
96 | | - |
97 | | - const state: GoogleUiState = |
98 | | - syncIndicator === "repairing" |
99 | | - ? "repairing" |
100 | | - : syncIndicator === "syncing" |
101 | | - ? "IMPORTING" |
102 | | - : isCheckingStatus |
103 | | - ? "checking" |
104 | | - : connectionState; |
105 | | - |
106 | 71 | return { |
107 | 72 | ...getGoogleConnectionConfig(state, onOpenGoogleAuth, onRepairGoogle), |
108 | 73 | isAvailable, |
|
0 commit comments