feat(mobile): add kill switch gate in root layout
This commit is contained in:
parent
8162a086d1
commit
acdedbcb9a
@ -1,19 +1,43 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Stack } from 'expo-router';
|
import { Stack } from 'expo-router';
|
||||||
import { StatusBar } from 'expo-status-bar';
|
import { StatusBar } from 'expo-status-bar';
|
||||||
|
import { Text, View } from 'react-native';
|
||||||
import { useAuthStore, type AuthState } from '../store/auth-store';
|
import { useAuthStore, type AuthState } from '../store/auth-store';
|
||||||
import { useInboxStore, type InboxState } from '../store/inbox-store';
|
import { useInboxStore, type InboxState } from '../store/inbox-store';
|
||||||
import { useNotesStore, type NotesState } from '../store/notes-store';
|
import { useNotesStore, type NotesState } from '../store/notes-store';
|
||||||
import { useWorkspaceStore, type WorkspaceState } from '../store/workspace-store';
|
import { useWorkspaceStore, type WorkspaceState } from '../store/workspace-store';
|
||||||
import { initPlatform } from '../lib/platform';
|
import { checkKillSwitch, initPlatform } from '../lib/platform';
|
||||||
|
import { colors } from '../theme';
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
|
const [killSwitchState, setKillSwitchState] = useState<{
|
||||||
|
checked: boolean;
|
||||||
|
disabled: boolean;
|
||||||
|
message: string | null;
|
||||||
|
}>({
|
||||||
|
checked: false,
|
||||||
|
disabled: false,
|
||||||
|
message: null,
|
||||||
|
});
|
||||||
|
|
||||||
const bootstrapAuth = useAuthStore((state: AuthState) => state.bootstrap);
|
const bootstrapAuth = useAuthStore((state: AuthState) => state.bootstrap);
|
||||||
const hydrateInbox = useInboxStore((state: InboxState) => state.hydrate);
|
const hydrateInbox = useInboxStore((state: InboxState) => state.hydrate);
|
||||||
const hydrateNotes = useNotesStore((state: NotesState) => state.hydrate);
|
const hydrateNotes = useNotesStore((state: NotesState) => state.hydrate);
|
||||||
const hydrateWorkspaces = useWorkspaceStore((state: WorkspaceState) => state.hydrate);
|
const hydrateWorkspaces = useWorkspaceStore((state: WorkspaceState) => state.hydrate);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
void checkKillSwitch()
|
||||||
|
.then((state) => {
|
||||||
|
setKillSwitchState({
|
||||||
|
checked: true,
|
||||||
|
disabled: state.disabled,
|
||||||
|
message: state.message,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setKillSwitchState({ checked: true, disabled: false, message: null });
|
||||||
|
});
|
||||||
|
|
||||||
void bootstrapAuth();
|
void bootstrapAuth();
|
||||||
void initPlatform();
|
void initPlatform();
|
||||||
void hydrateNotes();
|
void hydrateNotes();
|
||||||
@ -21,6 +45,29 @@ export default function RootLayout() {
|
|||||||
void hydrateInbox();
|
void hydrateInbox();
|
||||||
}, [bootstrapAuth, hydrateInbox, hydrateNotes, hydrateWorkspaces]);
|
}, [bootstrapAuth, hydrateInbox, hydrateNotes, hydrateWorkspaces]);
|
||||||
|
|
||||||
|
if (killSwitchState.checked && killSwitchState.disabled) {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
paddingHorizontal: 24,
|
||||||
|
backgroundColor: colors.bgCanvas,
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<StatusBar style="light" />
|
||||||
|
<Text style={{ color: colors.textPrimary, fontSize: 24, fontWeight: '700', textAlign: 'center' }}>
|
||||||
|
NoteLett is temporarily unavailable
|
||||||
|
</Text>
|
||||||
|
<Text style={{ color: colors.textSecondary, fontSize: 15, textAlign: 'center' }}>
|
||||||
|
{killSwitchState.message ?? 'Service access is currently paused by the platform team. Please try again later.'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StatusBar style="light" />
|
<StatusBar style="light" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user