轻松聘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

295 lines
7.7 KiB

import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router';
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Switch,
Text,
TextInput,
View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useDndSetting } from '../../../src/hooks';
import { colors } from '../../../src/theme';
/* ===================== 子组件:顶部导航 ===================== */
function Header({ onBack }: { onBack: () => void }) {
return (
<View style={styles.header}>
<Pressable style={styles.headerBtn} onPress={onBack} hitSlop={8}>
<Ionicons name="chevron-back" size={24} color={colors.textPrimary} />
</Pressable>
<Text style={styles.headerTitle}>勿扰模式</Text>
<View style={styles.headerBtn} />
</View>
);
}
/* ===================== 子组件:时间输入行 ===================== */
function TimeRow({
label,
value,
onChange,
}: {
label: string;
value: string;
onChange: (text: string) => void;
}) {
return (
<View style={styles.row}>
<Text style={styles.rowTitle}>{label}</Text>
<TextInput
style={styles.timeInput}
value={value}
onChangeText={onChange}
placeholder="00:00"
placeholderTextColor={colors.textHint}
keyboardType="numbers-and-punctuation"
/>
</View>
);
}
/* ===================== 页面 ===================== */
export default function DndSettingScreen() {
const router = useRouter();
const { setting, loading, error, refresh, update } = useDndSetting();
if (loading) {
return (
<SafeAreaView style={styles.safeArea} edges={['top']}>
<Header onBack={() => router.back()} />
<View style={styles.stateBox}>
<ActivityIndicator size="large" color={colors.primary} />
</View>
</SafeAreaView>
);
}
if (error || !setting) {
return (
<SafeAreaView style={styles.safeArea} edges={['top']}>
<Header onBack={() => router.back()} />
<View style={styles.stateBox}>
<Ionicons name="alert-circle-outline" size={40} color={colors.danger} />
<Text style={styles.stateText}>加载失败,请重试</Text>
<Pressable style={styles.retryBtn} onPress={refresh}>
<Text style={styles.retryText}>重试</Text>
</Pressable>
</View>
</SafeAreaView>
);
}
return (
<SafeAreaView style={styles.safeArea} edges={['top', 'bottom']}>
<Header onBack={() => router.back()} />
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<View style={[styles.statCard, { backgroundColor: colors.primaryLight }]}>
<Text style={[styles.statValue, { color: colors.primary }]}>{setting.blockedCount}</Text>
<Text style={styles.statLabel}>累计拦截的通知条数</Text>
</View>
<View style={styles.section}>
<Text style={styles.sectionTitle}>基础设置</Text>
<View style={styles.card}>
<View style={[styles.row, styles.rowBorder]}>
<View style={styles.rowBody}>
<Text style={styles.rowTitle}>开启勿扰模式</Text>
</View>
<Switch
value={setting.enabled}
onValueChange={(next) => update({ enabled: next })}
trackColor={{ false: colors.border, true: colors.primaryBorder }}
thumbColor={setting.enabled ? colors.primary : colors.white}
/>
</View>
<TimeRow
label="开始时间"
value={setting.startTime}
onChange={(text) => update({ startTime: text })}
/>
<View style={styles.rowBorder} />
<TimeRow
label="结束时间"
value={setting.endTime}
onChange={(text) => update({ endTime: text })}
/>
</View>
</View>
<View style={styles.section}>
<Text style={styles.sectionTitle}>高级设置</Text>
<View style={styles.card}>
<View style={styles.row}>
<View style={styles.rowBody}>
<Text style={styles.rowTitle}>允许重要通知穿透</Text>
<Text style={styles.rowDesc}>面试邀约等与企业的重要沟通仍会提醒你</Text>
</View>
<Switch
value={setting.allowUrgent}
onValueChange={(next) => update({ allowUrgent: next })}
trackColor={{ false: colors.border, true: colors.primaryBorder }}
thumbColor={setting.allowUrgent ? colors.primary : colors.white}
/>
</View>
</View>
</View>
<View style={styles.noteCard}>
<Ionicons name="information-circle-outline" size={18} color={colors.info} />
<Text style={styles.noteText}>
开启勿扰模式后,{setting.startTime} 至 {setting.endTime} 期间的非重要通知将被静音。你仍可在「企业沟通」中查看错过的消息。
</Text>
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: colors.pageBg,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 8,
height: 48,
backgroundColor: colors.white,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
headerBtn: {
width: 40,
height: 40,
alignItems: 'center',
justifyContent: 'center',
},
headerTitle: {
flex: 1,
textAlign: 'center',
fontSize: 17,
fontWeight: '700',
color: colors.textPrimary,
},
scroll: {
flex: 1,
},
content: {
padding: 8,
paddingBottom: 24,
},
stateBox: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
gap: 12,
},
stateText: {
marginTop: 12,
fontSize: 14,
color: colors.textSecondary,
},
retryBtn: {
marginTop: 16,
paddingHorizontal: 24,
paddingVertical: 8,
borderRadius: 18,
backgroundColor: colors.primaryBtn,
},
retryText: {
fontSize: 13,
fontWeight: '600',
color: colors.white,
},
statCard: {
borderRadius: 8,
padding: 8,
alignItems: 'center',
marginBottom: 8,
},
statValue: {
fontSize: 32,
fontWeight: '800',
},
statLabel: {
marginTop: 4,
fontSize: 13,
color: colors.textSecondary,
},
section: {
marginBottom: 16,
},
sectionTitle: {
fontSize: 14,
fontWeight: '700',
color: colors.textPrimary,
marginBottom: 10,
},
card: {
backgroundColor: colors.white,
borderRadius: 8,
overflow: 'hidden',
},
row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 14,
paddingVertical: 14,
},
rowBorder: {
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
rowBody: {
flex: 1,
marginRight: 12,
},
rowTitle: {
fontSize: 15,
fontWeight: '600',
color: colors.textPrimary,
},
rowDesc: {
marginTop: 3,
fontSize: 12,
lineHeight: 16,
color: colors.textSecondary,
},
timeInput: {
minWidth: 64,
textAlign: 'right',
fontSize: 15,
fontWeight: '600',
color: colors.primary,
paddingVertical: 4,
paddingHorizontal: 8,
},
noteCard: {
flexDirection: 'row',
alignItems: 'flex-start',
backgroundColor: colors.white,
borderRadius: 8,
padding: 8,
gap: 8,
},
noteText: {
flex: 1,
fontSize: 12,
lineHeight: 18,
color: colors.textSecondary,
},
});