feat(mobile): add kill switch gate in root layout

This commit is contained in:
saravanakumardb1 2026-03-30 23:58:03 -07:00
parent 8162a086d1
commit acdedbcb9a

View File

@ -1,19 +1,43 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import { Text, View } from 'react-native';
import { useAuthStore, type AuthState } from '../store/auth-store';
import { useInboxStore, type InboxState } from '../store/inbox-store';
import { useNotesStore, type NotesState } from '../store/notes-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() {
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 hydrateInbox = useInboxStore((state: InboxState) => state.hydrate);
const hydrateNotes = useNotesStore((state: NotesState) => state.hydrate);
const hydrateWorkspaces = useWorkspaceStore((state: WorkspaceState) => state.hydrate);
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 initPlatform();
void hydrateNotes();
@ -21,6 +45,29 @@ export default function RootLayout() {
void hydrateInbox();
}, [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 (
<>
<StatusBar style="light" />