feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
Alert,
|
||||
Linking,
|
||||
|
|
@ -11,6 +11,7 @@ import {
|
|||
import { useNavigation } from '@react-navigation/native'
|
||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
||||
import { useI18n, type TranslationKey } from '@d3ro/i18n'
|
||||
import { LOCALE_META } from '@d3ro/i18n/shared'
|
||||
import { SITE_URLS } from '@d3ro/core/web-urls'
|
||||
import { useAuth } from '../lib/auth-context'
|
||||
import { useEntitlement } from '../lib/entitlement-context'
|
||||
|
|
@ -75,6 +76,8 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
updatePreferences,
|
||||
retrySync,
|
||||
} = useMobilePreferences()
|
||||
const mountedRef = useRef(true)
|
||||
const localeRequestRef = useRef(0)
|
||||
const [savingPreference, setSavingPreference] = useState<SavingPreference>(null)
|
||||
const [loggingOut, setLoggingOut] = useState(false)
|
||||
const [retrying, setRetrying] = useState(false)
|
||||
|
|
@ -83,6 +86,14 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
const { currentDevice } = useDevice()
|
||||
const adminRole = currentAdminRole(user?.app_metadata)
|
||||
|
||||
useEffect(() => {
|
||||
mountedRef.current = true
|
||||
return () => {
|
||||
mountedRef.current = false
|
||||
localeRequestRef.current += 1
|
||||
}
|
||||
}, [])
|
||||
|
||||
const initials = user?.email
|
||||
? user.email.substring(0, 2).toUpperCase()
|
||||
: 'US'
|
||||
|
|
@ -95,23 +106,38 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
async function persistPreference(
|
||||
key: Exclude<SavingPreference, null>,
|
||||
patch: MobilePreferencesPatch,
|
||||
): Promise<void> {
|
||||
if (savingPreference !== null) return
|
||||
): Promise<boolean> {
|
||||
if (savingPreference !== null) return false
|
||||
setSavingPreference(key)
|
||||
const result = await updatePreferences(patch)
|
||||
setSavingPreference(null)
|
||||
if (!result.localSaved) {
|
||||
let saved = false
|
||||
try {
|
||||
const result = await updatePreferences(patch)
|
||||
saved = result.localSaved
|
||||
} catch {
|
||||
saved = false
|
||||
} finally {
|
||||
if (mountedRef.current) setSavingPreference(null)
|
||||
}
|
||||
if (!mountedRef.current) return false
|
||||
if (!saved) {
|
||||
Alert.alert(
|
||||
t('mobile.preferences.saveFailedTitle'),
|
||||
t('mobile.preferences.cacheWriteError'),
|
||||
)
|
||||
}
|
||||
return saved
|
||||
}
|
||||
|
||||
async function applyLocaleSelection(nextLocale: SupportedMobileLocale): Promise<void> {
|
||||
const request = ++localeRequestRef.current
|
||||
const saved = await persistPreference('locale', { locale: nextLocale })
|
||||
if (!saved || !mountedRef.current || localeRequestRef.current !== request) return
|
||||
setLocale(nextLocale)
|
||||
}
|
||||
|
||||
function selectLocale(nextLocale: SupportedMobileLocale): void {
|
||||
if (locale === nextLocale || savingPreference !== null) return
|
||||
setLocale(nextLocale)
|
||||
void persistPreference('locale', { locale: nextLocale })
|
||||
void applyLocaleSelection(nextLocale)
|
||||
}
|
||||
|
||||
async function performLogout(): Promise<void> {
|
||||
|
|
@ -124,9 +150,11 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
purgeLocalSession,
|
||||
})
|
||||
} catch {
|
||||
Alert.alert(t('mobile.auth.errorTitle'), t('mobile.auth.logoutFailed'))
|
||||
if (mountedRef.current) {
|
||||
Alert.alert(t('mobile.auth.errorTitle'), t('mobile.auth.logoutFailed'))
|
||||
}
|
||||
} finally {
|
||||
setLoggingOut(false)
|
||||
if (mountedRef.current) setLoggingOut(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,13 +172,16 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
async function handleRetry(): Promise<void> {
|
||||
if (retrying) return
|
||||
setRetrying(true)
|
||||
await retrySync()
|
||||
setRetrying(false)
|
||||
try {
|
||||
await retrySync()
|
||||
} finally {
|
||||
if (mountedRef.current) setRetrying(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function openAdPrivacyOptions(): Promise<void> {
|
||||
const opened = await mobileAds.showPrivacyOptions()
|
||||
if (!opened) {
|
||||
if (!opened && mountedRef.current) {
|
||||
Alert.alert(
|
||||
t('mobile.set.adPrivacy'),
|
||||
t('mobile.set.adPrivacyUnavailable'),
|
||||
|
|
@ -326,24 +357,33 @@ export default function SettingsScreen(): React.ReactElement {
|
|||
description={t('mobile.set.languageDesc')}
|
||||
/>
|
||||
<View
|
||||
style={styles.segmentRow}
|
||||
style={styles.localeGrid}
|
||||
accessibilityRole="radiogroup"
|
||||
accessibilityLabel={t('mobile.set.language')}
|
||||
>
|
||||
<SegmentOption
|
||||
label="한국어"
|
||||
selected={locale === 'ko'}
|
||||
disabled={savingPreference !== null}
|
||||
testID="settings-language-ko"
|
||||
onPress={() => selectLocale('ko')}
|
||||
/>
|
||||
<SegmentOption
|
||||
label="English"
|
||||
selected={locale === 'en'}
|
||||
disabled={savingPreference !== null}
|
||||
testID="settings-language-en"
|
||||
onPress={() => selectLocale('en')}
|
||||
/>
|
||||
{LOCALE_META.map((item) => (
|
||||
<Pressable
|
||||
key={item.code}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ selected: locale === item.code, disabled: savingPreference !== null }}
|
||||
accessibilityLabel={item.nativeName}
|
||||
disabled={savingPreference !== null}
|
||||
testID={`settings-language-${item.code}`}
|
||||
onPress={() => selectLocale(item.code)}
|
||||
style={({ pressed }) => [
|
||||
styles.localeOption,
|
||||
{
|
||||
borderColor: locale === item.code ? palette.accent.main : palette.border.default,
|
||||
backgroundColor: locale === item.code ? palette.accent.dim : palette.bg.inset,
|
||||
opacity: savingPreference !== null ? 0.5 : pressed ? 0.72 : 1,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<ThemeText variant="small" color={locale === item.code ? 'accent' : 'primary'}>
|
||||
{item.nativeName}
|
||||
</ThemeText>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
</ThemeCard>
|
||||
|
|
@ -760,6 +800,17 @@ const styles = StyleSheet.create({
|
|||
settingHeader: { gap: 4, padding: 15, paddingBottom: 10 },
|
||||
settingBlock: { borderTopWidth: 1, marginTop: 15, paddingTop: 2 },
|
||||
segmentRow: { flexDirection: 'row', gap: 8, paddingHorizontal: 15, paddingBottom: 15 },
|
||||
localeGrid: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, paddingHorizontal: 15, paddingBottom: 15 },
|
||||
localeOption: {
|
||||
minHeight: 48,
|
||||
minWidth: '30%',
|
||||
flexGrow: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
borderWidth: 1,
|
||||
borderRadius: 9,
|
||||
paddingHorizontal: 8,
|
||||
},
|
||||
segmentOption: {
|
||||
minHeight: 48,
|
||||
flex: 1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue