@umituz/react-native-settings 4.20.56 â 4.20.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -4
- package/package.json +1 -2
- package/src/__tests__/setup.ts +1 -4
- package/src/application/README.md +322 -0
- package/src/domains/about/README.md +452 -0
- package/src/domains/about/presentation/hooks/README.md +350 -0
- package/src/domains/appearance/README.md +596 -0
- package/src/domains/appearance/hooks/README.md +366 -0
- package/src/domains/appearance/infrastructure/services/README.md +455 -0
- package/src/domains/appearance/presentation/components/README.md +493 -0
- package/src/domains/cloud-sync/README.md +451 -0
- package/src/domains/cloud-sync/presentation/components/README.md +493 -0
- package/src/domains/dev/README.md +477 -0
- package/src/domains/disclaimer/README.md +421 -0
- package/src/domains/disclaimer/presentation/components/README.md +394 -0
- package/src/domains/faqs/README.md +586 -0
- package/src/domains/feedback/README.md +565 -0
- package/src/domains/feedback/presentation/hooks/README.md +428 -0
- package/src/domains/legal/README.md +549 -0
- package/src/domains/rating/README.md +452 -0
- package/src/domains/rating/presentation/components/README.md +475 -0
- package/src/domains/video-tutorials/README.md +482 -0
- package/src/domains/video-tutorials/presentation/components/README.md +433 -0
- package/src/infrastructure/README.md +509 -0
- package/src/infrastructure/repositories/README.md +475 -0
- package/src/infrastructure/services/README.md +510 -0
- package/src/presentation/components/README.md +482 -0
- package/src/presentation/components/SettingsErrorBoundary/README.md +455 -0
- package/src/presentation/components/SettingsFooter/README.md +446 -0
- package/src/presentation/components/SettingsItemCard/README.md +457 -0
- package/src/presentation/components/SettingsSection/README.md +421 -0
- package/src/presentation/hooks/README.md +413 -0
- package/src/presentation/hooks/mutations/README.md +430 -0
- package/src/presentation/hooks/queries/README.md +441 -0
- package/src/presentation/navigation/README.md +532 -0
- package/src/presentation/navigation/components/README.md +330 -0
- package/src/presentation/navigation/hooks/README.md +399 -0
- package/src/presentation/navigation/utils/README.md +442 -0
- package/src/presentation/screens/README.md +525 -0
- package/src/presentation/screens/components/SettingsContent/README.md +404 -0
- package/src/presentation/screens/components/SettingsHeader/README.md +322 -0
- package/src/presentation/screens/components/sections/CustomSettingsList/README.md +388 -0
- package/src/presentation/screens/components/sections/FeatureSettingsSection/README.md +232 -0
- package/src/presentation/screens/components/sections/IdentitySettingsSection/README.md +325 -0
- package/src/presentation/screens/components/sections/ProfileSectionLoader/README.md +480 -0
- package/src/presentation/screens/components/sections/SupportSettingsSection/README.md +391 -0
- package/src/presentation/screens/hooks/README.md +383 -0
- package/src/presentation/screens/types/README.md +439 -0
- package/src/presentation/screens/utils/README.md +288 -0
package/README.md
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
# @umituz/react-native-settings
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Comprehensive settings management for React Native apps with modular domain-based architecture.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
5
|
+
## đ Features
|
|
6
6
|
|
|
7
|
+
### Core Features
|
|
7
8
|
- â
**User Settings Management** - Theme, language, notifications, privacy settings
|
|
8
9
|
- â
**Zustand State Management** - Global settings state with Zustand
|
|
9
10
|
- â
**Persistent Storage** - Uses @umituz/react-native-storage for persistence
|
|
10
|
-
- â
**Settings Screens** - Pre-built settings screens
|
|
11
|
+
- â
**Settings Screens** - Pre-built settings screens with modular architecture
|
|
11
12
|
- â
**Setting Components** - Reusable setting item components
|
|
12
13
|
- â
**Type-Safe** - Full TypeScript support
|
|
13
14
|
|
|
15
|
+
### Domain Features
|
|
16
|
+
- đ¨ **Appearance** - Theme customization (light/dark mode), custom color schemes
|
|
17
|
+
- âšī¸ **About** - App information, version details, developer contact
|
|
18
|
+
- âī¸ **Legal** - Privacy policy, terms of service, legal documents
|
|
19
|
+
- â ī¸ **Disclaimer** - Legal notices, warnings, important information
|
|
20
|
+
- đŦ **Feedback** - User feedback forms, support resources
|
|
21
|
+
- â **FAQs** - Searchable frequently asked questions
|
|
22
|
+
- â **Rating** - Star rating system with statistics
|
|
23
|
+
- đĨ **Video Tutorials** - Tutorial browser with featured content
|
|
24
|
+
- âī¸ **Cloud Sync** - Sync status and management
|
|
25
|
+
- đ ī¸ **Dev Tools** - Development utilities (DEV mode only)
|
|
26
|
+
|
|
14
27
|
## Installation
|
|
15
28
|
|
|
16
29
|
```bash
|
|
@@ -20,7 +33,7 @@ npm install @umituz/react-native-settings
|
|
|
20
33
|
## Peer Dependencies
|
|
21
34
|
|
|
22
35
|
```bash
|
|
23
|
-
npm install zustand @umituz/react-native-storage @umituz/react-native-design-system @umituz/react-native-localization @react-navigation/native @react-navigation/stack react-native-safe-area-context
|
|
36
|
+
npm install zustand @umituz/react-native-storage @umituz/react-native-design-system @umituz/react-native-localization @react-navigation/native @react-navigation/stack react-native-safe-area-context
|
|
24
37
|
```
|
|
25
38
|
|
|
26
39
|
## Usage
|
|
@@ -373,13 +386,138 @@ This package follows **Domain-Driven Design (DDD)** principles:
|
|
|
373
386
|
- â
**Error Boundaries**: Prevent crashes and provide graceful fallbacks
|
|
374
387
|
- â
**Development Logs**: __DEV__ only logging for production safety
|
|
375
388
|
|
|
389
|
+
## Domain Documentation
|
|
390
|
+
|
|
391
|
+
Each domain has comprehensive documentation with usage examples, API references, and best practices:
|
|
392
|
+
|
|
393
|
+
- **[About Domain Documentation](./src/domains/about/README.md)** - App information, version details, contact information
|
|
394
|
+
- **[Appearance Domain Documentation](./src/domains/appearance/README.md)** - Theme management, dark mode, custom colors
|
|
395
|
+
- **[Legal Domain Documentation](./src/domains/legal/README.md)** - Privacy policy, terms of service, legal documents
|
|
396
|
+
- **[Disclaimer Domain Documentation](./src/domains/disclaimer/README.md)** - Legal notices, warnings, important information
|
|
397
|
+
- **[Feedback Domain Documentation](./src/domains/feedback/README.md)** - Feedback forms, support resources
|
|
398
|
+
- **[FAQs Domain Documentation](./src/domains/faqs/README.md)** - Searchable FAQ system
|
|
399
|
+
- **[Rating Domain Documentation](./src/domains/rating/README.md)** - Star rating component
|
|
400
|
+
- **[Video Tutorials Domain Documentation](./src/domains/video-tutorials/README.md)** - Video tutorial browser
|
|
401
|
+
- **[Cloud Sync Domain Documentation](./src/domains/cloud-sync/README.md)** - Cloud sync status and management
|
|
402
|
+
- **[Dev Domain Documentation](./src/domains/dev/README.md)** - Development utilities (DEV mode only)
|
|
403
|
+
|
|
404
|
+
## Quick Start Examples
|
|
405
|
+
|
|
406
|
+
### Complete Settings App
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
import React from 'react';
|
|
410
|
+
import { NavigationContainer } from '@react-navigation/native';
|
|
411
|
+
import { createStackNavigator } from '@react-navigation/stack';
|
|
412
|
+
import {
|
|
413
|
+
SettingsScreen,
|
|
414
|
+
AppearanceScreen,
|
|
415
|
+
AboutScreen,
|
|
416
|
+
LegalScreen,
|
|
417
|
+
FAQScreen,
|
|
418
|
+
} from '@umituz/react-native-settings';
|
|
419
|
+
|
|
420
|
+
const Stack = createStackNavigator();
|
|
421
|
+
|
|
422
|
+
function App() {
|
|
423
|
+
return (
|
|
424
|
+
<NavigationContainer>
|
|
425
|
+
<Stack.Navigator>
|
|
426
|
+
<Stack.Screen name="Settings" component={SettingsScreen} />
|
|
427
|
+
<Stack.Screen name="Appearance" component={AppearanceScreen} />
|
|
428
|
+
<Stack.Screen name="About" component={AboutScreen} />
|
|
429
|
+
<Stack.Screen name="Legal" component={LegalScreen} />
|
|
430
|
+
<Stack.Screen name="FAQ" component={FAQScreen} />
|
|
431
|
+
</Stack.Navigator>
|
|
432
|
+
</NavigationContainer>
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Custom Settings Screen
|
|
438
|
+
|
|
439
|
+
```tsx
|
|
440
|
+
import { SettingsSection, SettingsItemCard } from '@umituz/react-native-settings';
|
|
441
|
+
|
|
442
|
+
function CustomSettingsScreen() {
|
|
443
|
+
return (
|
|
444
|
+
<ScreenLayout>
|
|
445
|
+
<SettingsSection title="PREFERENCES">
|
|
446
|
+
<SettingsItemCard
|
|
447
|
+
icon="moon-outline"
|
|
448
|
+
title="Dark Mode"
|
|
449
|
+
showSwitch={true}
|
|
450
|
+
switchValue={isDarkMode}
|
|
451
|
+
onSwitchChange={setDarkMode}
|
|
452
|
+
/>
|
|
453
|
+
<SettingsItemCard
|
|
454
|
+
icon="globe-outline"
|
|
455
|
+
title="Language"
|
|
456
|
+
description="English"
|
|
457
|
+
onPress={() => {}}
|
|
458
|
+
/>
|
|
459
|
+
</SettingsSection>
|
|
460
|
+
|
|
461
|
+
<SettingsSection title="SUPPORT">
|
|
462
|
+
<SettingsItemCard
|
|
463
|
+
icon="help-circle-outline"
|
|
464
|
+
title="Help & FAQs"
|
|
465
|
+
onPress={() => navigation.navigate('FAQ')}
|
|
466
|
+
/>
|
|
467
|
+
<SettingsItemCard
|
|
468
|
+
icon="chatbubble-outline"
|
|
469
|
+
title="Send Feedback"
|
|
470
|
+
onPress={() => navigation.navigate('Feedback')}
|
|
471
|
+
/>
|
|
472
|
+
</SettingsSection>
|
|
473
|
+
</ScreenLayout>
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
## Project Structure
|
|
479
|
+
|
|
480
|
+
```
|
|
481
|
+
src/
|
|
482
|
+
âââ domains/ # Feature domains (DDD architecture)
|
|
483
|
+
â âââ about/ # App information & about
|
|
484
|
+
â âââ appearance/ # Theme & appearance settings
|
|
485
|
+
â âââ legal/ # Privacy policy & terms
|
|
486
|
+
â âââ disclaimer/ # Legal disclaimers
|
|
487
|
+
â âââ feedback/ # User feedback system
|
|
488
|
+
â âââ faqs/ # FAQ management
|
|
489
|
+
â âââ rating/ # Rating system
|
|
490
|
+
â âââ video-tutorials/ # Video tutorials
|
|
491
|
+
â âââ cloud-sync/ # Cloud synchronization
|
|
492
|
+
â âââ dev/ # Development tools
|
|
493
|
+
âââ presentation/ # Shared UI components
|
|
494
|
+
â âââ screens/ # Settings screens
|
|
495
|
+
â âââ components/ # Reusable components
|
|
496
|
+
â âââ hooks/ # Shared hooks
|
|
497
|
+
âââ application/ # Application logic
|
|
498
|
+
âââ infrastructure/ # External dependencies
|
|
499
|
+
âââ index.ts # Main exports
|
|
500
|
+
```
|
|
501
|
+
|
|
376
502
|
## Version History
|
|
377
503
|
|
|
504
|
+
- **v4.20.56**: Added comprehensive domain documentation with README files for each feature
|
|
505
|
+
- **v4.20.55**: Enhanced domain structure with individual README documentation
|
|
506
|
+
- **v4.20.54**: Refactored package structure - split files under 200 lines
|
|
378
507
|
- **v2.2.0**: Major refactor - removed hardcoded text, improved architecture, added comprehensive tests
|
|
379
508
|
- **v2.1.0**: Enhanced component structure and TypeScript support
|
|
380
509
|
- **v2.0.0**: Breaking changes - removed LanguageSelectionScreen, improved API
|
|
381
510
|
- **v1.x.x**: Initial releases with basic settings functionality
|
|
382
511
|
|
|
512
|
+
## Contributing
|
|
513
|
+
|
|
514
|
+
When contributing to this package:
|
|
515
|
+
1. Follow the domain-driven design structure
|
|
516
|
+
2. Keep files under 200 lines
|
|
517
|
+
3. Add tests for new features
|
|
518
|
+
4. Update relevant domain README
|
|
519
|
+
5. Follow TypeScript best practices
|
|
520
|
+
|
|
383
521
|
## License
|
|
384
522
|
|
|
385
523
|
MIT
|
|
@@ -388,3 +526,7 @@ MIT
|
|
|
388
526
|
|
|
389
527
|
Ãmit UZ <umit@umituz.com>
|
|
390
528
|
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
**Made with â¤ī¸ for the React Native community**
|
|
532
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-settings",
|
|
3
|
-
"version": "4.20.
|
|
3
|
+
"version": "4.20.58",
|
|
4
4
|
"description": "Complete settings hub for React Native apps - consolidated package with settings, about, legal, appearance, feedback, FAQs, and rating",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -93,7 +93,6 @@
|
|
|
93
93
|
"expo-file-system": "^19.0.21",
|
|
94
94
|
"expo-haptics": "^15.0.8",
|
|
95
95
|
"expo-image": "^3.0.11",
|
|
96
|
-
"expo-linear-gradient": "^15.0.8",
|
|
97
96
|
"expo-localization": "^17.0.8",
|
|
98
97
|
"expo-notifications": "^0.32.15",
|
|
99
98
|
"expo-sharing": "^14.0.8",
|
package/src/__tests__/setup.ts
CHANGED
|
@@ -122,10 +122,7 @@ jest.mock('react-native-safe-area-context', () => ({
|
|
|
122
122
|
}),
|
|
123
123
|
}));
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
jest.mock('expo-linear-gradient', () => ({
|
|
127
|
-
LinearGradient: ({ children }: any) => children,
|
|
128
|
-
}));
|
|
125
|
+
|
|
129
126
|
|
|
130
127
|
// Mock notification service
|
|
131
128
|
jest.mock('@umituz/react-native-notifications', () => ({
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Application Layer
|
|
2
|
+
|
|
3
|
+
The application layer defines the core business logic, interfaces, and types for the settings domain following Domain-Driven Design (DDD) principles.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The application layer serves as the bridge between the presentation and infrastructure layers, defining the contracts that both layers must follow.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
application/
|
|
11
|
+
âââ ports/
|
|
12
|
+
âââ ISettingsRepository.ts # Repository interface and types
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Core Types
|
|
16
|
+
|
|
17
|
+
### UserSettings
|
|
18
|
+
|
|
19
|
+
The main data structure for user settings.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
interface UserSettings {
|
|
23
|
+
userId: string; // Unique user identifier
|
|
24
|
+
theme: 'light' | 'dark' | 'auto'; // Theme preference
|
|
25
|
+
language: string; // Language code (e.g., 'en-US')
|
|
26
|
+
notificationsEnabled: boolean; // Master notification switch
|
|
27
|
+
emailNotifications: boolean; // Email notification preference
|
|
28
|
+
pushNotifications: boolean; // Push notification preference
|
|
29
|
+
soundEnabled: boolean; // Sound effects toggle
|
|
30
|
+
vibrationEnabled: boolean; // Haptic feedback toggle
|
|
31
|
+
privacyMode: boolean; // Privacy/screen shield mode
|
|
32
|
+
disclaimerAccepted: boolean; // Legal disclaimer acceptance
|
|
33
|
+
updatedAt: Date; // Last update timestamp
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### SettingsResult
|
|
38
|
+
|
|
39
|
+
Result wrapper for settings operations.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
interface SettingsResult<T> {
|
|
43
|
+
success: boolean; // Operation success flag
|
|
44
|
+
data?: T; // Result data (if successful)
|
|
45
|
+
error?: SettingsError; // Error details (if failed)
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### SettingsError
|
|
50
|
+
|
|
51
|
+
Error structure for settings operations.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
interface SettingsError {
|
|
55
|
+
code: string; // Error code for identification
|
|
56
|
+
message: string; // Human-readable error message
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Repository Interface
|
|
61
|
+
|
|
62
|
+
### ISettingsRepository
|
|
63
|
+
|
|
64
|
+
The contract that all settings repository implementations must follow.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface ISettingsRepository {
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve settings for a user
|
|
70
|
+
* @param userId - Unique user identifier
|
|
71
|
+
* @returns Promise resolving to settings result
|
|
72
|
+
*/
|
|
73
|
+
getSettings(userId: string): Promise<SettingsResult<UserSettings>>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Save settings for a user
|
|
77
|
+
* @param settings - Complete settings object to save
|
|
78
|
+
* @returns Promise resolving to operation result
|
|
79
|
+
*/
|
|
80
|
+
saveSettings(settings: UserSettings): Promise<SettingsResult<void>>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Delete settings for a user
|
|
84
|
+
* @param userId - Unique user identifier
|
|
85
|
+
* @returns Promise resolving to operation result
|
|
86
|
+
*/
|
|
87
|
+
deleteSettings(userId: string): Promise<SettingsResult<void>>;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage Examples
|
|
92
|
+
|
|
93
|
+
### Defining a Custom Repository
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import type { ISettingsRepository, UserSettings, SettingsResult } from '@umituz/react-native-settings';
|
|
97
|
+
|
|
98
|
+
class CustomSettingsRepository implements ISettingsRepository {
|
|
99
|
+
async getSettings(userId: string): Promise<SettingsResult<UserSettings>> {
|
|
100
|
+
try {
|
|
101
|
+
// Your custom implementation
|
|
102
|
+
const settings = await fetchFromAPI(userId);
|
|
103
|
+
return { success: true, data: settings };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
error: {
|
|
108
|
+
code: 'FETCH_FAILED',
|
|
109
|
+
message: error.message,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async saveSettings(settings: UserSettings): Promise<SettingsResult<void>> {
|
|
116
|
+
// Your implementation
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async deleteSettings(userId: string): Promise<SettingsResult<void>> {
|
|
120
|
+
// Your implementation
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Using Repository Interface
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import type { ISettingsRepository } from '@umituz/react-native-settings';
|
|
129
|
+
|
|
130
|
+
class SettingsService {
|
|
131
|
+
constructor(private repository: ISettingsRepository) {}
|
|
132
|
+
|
|
133
|
+
async getUserSettings(userId: string) {
|
|
134
|
+
const result = await this.repository.getSettings(userId);
|
|
135
|
+
|
|
136
|
+
if (!result.success) {
|
|
137
|
+
throw new Error(result.error?.message);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result.data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async updateUserPreferences(userId: string, preferences: Partial<UserSettings>) {
|
|
144
|
+
const current = await this.getUserSettings(userId);
|
|
145
|
+
const updated = { ...current, ...preferences, updatedAt: new Date() };
|
|
146
|
+
|
|
147
|
+
return this.repository.saveSettings(updated);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Testing with Mock Repository
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
class MockSettingsRepository implements ISettingsRepository {
|
|
156
|
+
private settings: Map<string, UserSettings> = new Map();
|
|
157
|
+
|
|
158
|
+
async getSettings(userId: string): Promise<SettingsResult<UserSettings>> {
|
|
159
|
+
const settings = this.settings.get(userId);
|
|
160
|
+
if (!settings) {
|
|
161
|
+
return {
|
|
162
|
+
success: false,
|
|
163
|
+
error: { code: 'NOT_FOUND', message: 'Settings not found' },
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return { success: true, data: settings };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async saveSettings(settings: UserSettings): Promise<SettingsResult<void>> {
|
|
170
|
+
this.settings.set(settings.userId, settings);
|
|
171
|
+
return { success: true };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async deleteSettings(userId: string): Promise<SettingsResult<void>> {
|
|
175
|
+
this.settings.delete(userId);
|
|
176
|
+
return { success: true };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Usage in tests
|
|
181
|
+
const mockRepo = new MockSettingsRepository();
|
|
182
|
+
const service = new SettingsService(mockRepo);
|
|
183
|
+
|
|
184
|
+
await service.updateUserPreferences('user123', { theme: 'dark' });
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Default Settings
|
|
188
|
+
|
|
189
|
+
When no settings exist, the following defaults are used:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const defaultSettings: UserSettings = {
|
|
193
|
+
userId: '',
|
|
194
|
+
theme: 'auto', // Follow system theme
|
|
195
|
+
language: 'en-US', // English (US)
|
|
196
|
+
notificationsEnabled: true, // Notifications on
|
|
197
|
+
emailNotifications: true, // Email notifications on
|
|
198
|
+
pushNotifications: true, // Push notifications on
|
|
199
|
+
soundEnabled: true, // Sound on
|
|
200
|
+
vibrationEnabled: true, // Vibration on
|
|
201
|
+
privacyMode: false, // Privacy mode off
|
|
202
|
+
disclaimerAccepted: false, // Disclaimer not accepted
|
|
203
|
+
updatedAt: new Date(),
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Error Handling
|
|
208
|
+
|
|
209
|
+
### Error Codes
|
|
210
|
+
|
|
211
|
+
Common error codes used throughout the application:
|
|
212
|
+
|
|
213
|
+
| Code | Description |
|
|
214
|
+
|------|-------------|
|
|
215
|
+
| `GET_SETTINGS_FAILED` | Failed to retrieve settings |
|
|
216
|
+
| `SAVE_SETTINGS_FAILED` | Failed to save settings |
|
|
217
|
+
| `DELETE_SETTINGS_FAILED` | Failed to delete settings |
|
|
218
|
+
| `INVALID_USER_ID` | Invalid user identifier |
|
|
219
|
+
| `VALIDATION_ERROR` | Settings validation failed |
|
|
220
|
+
| `NOT_FOUND` | Settings not found for user |
|
|
221
|
+
| `STORAGE_ERROR` | Underlying storage error |
|
|
222
|
+
| `NETWORK_ERROR` | Network communication error |
|
|
223
|
+
|
|
224
|
+
### Error Handling Pattern
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
async function handleSettingsOperation<T>(
|
|
228
|
+
operation: () => Promise<SettingsResult<T>>
|
|
229
|
+
): Promise<T> {
|
|
230
|
+
const result = await operation();
|
|
231
|
+
|
|
232
|
+
if (!result.success) {
|
|
233
|
+
throw new SettingsError(
|
|
234
|
+
result.error?.code || 'UNKNOWN_ERROR',
|
|
235
|
+
result.error?.message || 'An unknown error occurred'
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return result.data!;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Usage
|
|
243
|
+
try {
|
|
244
|
+
const settings = await handleSettingsOperation(() =>
|
|
245
|
+
repository.getSettings(userId)
|
|
246
|
+
);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
if (error instanceof SettingsError) {
|
|
249
|
+
console.error(`[${error.code}] ${error.message}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Best Practices
|
|
255
|
+
|
|
256
|
+
1. **Type Safety**: Always use the defined interfaces
|
|
257
|
+
2. **Error Handling**: Check `success` flag before accessing data
|
|
258
|
+
3. **Immutability**: Return new objects, don't mutate existing ones
|
|
259
|
+
4. **Validation**: Validate settings before saving
|
|
260
|
+
5. **Default Values**: Always provide sensible defaults
|
|
261
|
+
6. **Timestamp Updates**: Update `updatedAt` on every change
|
|
262
|
+
7. **Partial Updates**: Support partial updates when possible
|
|
263
|
+
8. **Repository Pattern**: Always program to the interface, not implementation
|
|
264
|
+
|
|
265
|
+
## Testing Utilities
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Test factory for creating test settings
|
|
269
|
+
function createTestSettings(overrides?: Partial<UserSettings>): UserSettings {
|
|
270
|
+
return {
|
|
271
|
+
userId: 'test-user',
|
|
272
|
+
theme: 'light',
|
|
273
|
+
language: 'en-US',
|
|
274
|
+
notificationsEnabled: true,
|
|
275
|
+
emailNotifications: true,
|
|
276
|
+
pushNotifications: true,
|
|
277
|
+
soundEnabled: true,
|
|
278
|
+
vibrationEnabled: true,
|
|
279
|
+
privacyMode: false,
|
|
280
|
+
disclaimerAccepted: true,
|
|
281
|
+
updatedAt: new Date(),
|
|
282
|
+
...overrides,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Test factory for creating error results
|
|
287
|
+
function createErrorResult<T>(
|
|
288
|
+
code: string,
|
|
289
|
+
message: string
|
|
290
|
+
): SettingsResult<T> {
|
|
291
|
+
return {
|
|
292
|
+
success: false,
|
|
293
|
+
error: { code, message },
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Test factory for creating success results
|
|
298
|
+
function createSuccessResult<T>(data?: T): SettingsResult<T> {
|
|
299
|
+
return {
|
|
300
|
+
success: true,
|
|
301
|
+
data,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Integration Points
|
|
307
|
+
|
|
308
|
+
The application layer integrates with:
|
|
309
|
+
|
|
310
|
+
- **Presentation Layer**: Provides interfaces for UI components
|
|
311
|
+
- **Infrastructure Layer**: Defines contracts for storage implementation
|
|
312
|
+
- **Domain Layer**: Contains business logic and entities
|
|
313
|
+
|
|
314
|
+
## Related
|
|
315
|
+
|
|
316
|
+
- **Infrastructure**: Repository implementations
|
|
317
|
+
- **Presentation Hooks**: React hooks for UI
|
|
318
|
+
- **Type Definitions**: Complete type definitions
|
|
319
|
+
|
|
320
|
+
## License
|
|
321
|
+
|
|
322
|
+
MIT
|