@umituz/react-native-settings 4.20.55 → 4.20.57
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 +145 -3
- package/package.json +1 -2
- 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/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 +461 -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
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
# Settings Mutations
|
|
2
|
+
|
|
3
|
+
Custom TanStack Query mutations for updating user settings in the settings system.
|
|
4
|
+
|
|
5
|
+
## Mutations
|
|
6
|
+
|
|
7
|
+
### useUpdateSettingsMutation
|
|
8
|
+
|
|
9
|
+
Mutation hook for updating user settings.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { useUpdateSettingsMutation } from '@umituz/react-native-settings';
|
|
13
|
+
|
|
14
|
+
function SettingsScreen() {
|
|
15
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
16
|
+
|
|
17
|
+
const handleThemeChange = useCallback((theme: 'light' | 'dark') => {
|
|
18
|
+
updateSettings.mutate(
|
|
19
|
+
{ userId: 'user123', settings: { theme } },
|
|
20
|
+
{
|
|
21
|
+
onSuccess: () => {
|
|
22
|
+
console.log('Settings updated successfully');
|
|
23
|
+
},
|
|
24
|
+
onError: (error) => {
|
|
25
|
+
console.error('Failed to update settings:', error);
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}, [updateSettings]);
|
|
30
|
+
|
|
31
|
+
return <ThemeSelector onThemeChange={handleThemeChange} />;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Returns
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
interface UpdateSettingsMutationResult {
|
|
39
|
+
mutate: (variables: UpdateSettingsVariables) => void;
|
|
40
|
+
mutateAsync: (variables: UpdateSettingsVariables) => Promise<SettingsResult>;
|
|
41
|
+
isLoading: boolean;
|
|
42
|
+
isError: boolean;
|
|
43
|
+
error: Error | null;
|
|
44
|
+
data: SettingsResult | undefined;
|
|
45
|
+
reset: () => void;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Mutation Variables
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
interface UpdateSettingsVariables {
|
|
53
|
+
userId: string;
|
|
54
|
+
settings: Partial<UserSettings>;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Examples
|
|
59
|
+
|
|
60
|
+
**Update Single Setting:**
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
64
|
+
|
|
65
|
+
const toggleNotifications = () => {
|
|
66
|
+
updateSettings.mutate({
|
|
67
|
+
userId: 'user123',
|
|
68
|
+
settings: { notificationsEnabled: !settings.notificationsEnabled },
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Update Multiple Settings:**
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
77
|
+
|
|
78
|
+
const updateMultipleSettings = () => {
|
|
79
|
+
updateSettings.mutate({
|
|
80
|
+
userId: 'user123',
|
|
81
|
+
settings: {
|
|
82
|
+
theme: 'dark',
|
|
83
|
+
language: 'tr-TR',
|
|
84
|
+
notificationsEnabled: true,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**With Optimistic Updates:**
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
94
|
+
|
|
95
|
+
const handleOptimisticUpdate = (newTheme: 'light' | 'dark') => {
|
|
96
|
+
updateSettings.mutate(
|
|
97
|
+
{ userId: 'user123', settings: { theme: newTheme } },
|
|
98
|
+
{
|
|
99
|
+
onMutate: async (newData) => {
|
|
100
|
+
// Cancel ongoing queries
|
|
101
|
+
await queryClient.cancelQueries(['settings', newData.userId]);
|
|
102
|
+
|
|
103
|
+
// Snapshot previous value
|
|
104
|
+
const previousSettings = queryClient.getQueryData(['settings', newData.userId]);
|
|
105
|
+
|
|
106
|
+
// Optimistically update
|
|
107
|
+
queryClient.setQueryData(['settings', newData.userId], (old: any) => ({
|
|
108
|
+
...old,
|
|
109
|
+
...newData.settings,
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
// Return context for rollback
|
|
113
|
+
return { previousSettings };
|
|
114
|
+
},
|
|
115
|
+
onError: (err, newData, context) => {
|
|
116
|
+
// Rollback on error
|
|
117
|
+
queryClient.setQueryData(['settings', newData.userId], context?.previousSettings);
|
|
118
|
+
},
|
|
119
|
+
onSettled: (data, error, newData) => {
|
|
120
|
+
// Refetch on success or error
|
|
121
|
+
queryClient.invalidateQueries(['settings', newData.userId]);
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### useResetSettingsMutation
|
|
129
|
+
|
|
130
|
+
Mutation hook for resetting user settings to defaults.
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { useResetSettingsMutation } from '@umituz/react-native-settings';
|
|
134
|
+
|
|
135
|
+
function SettingsScreen() {
|
|
136
|
+
const resetSettings = useResetSettingsMutation();
|
|
137
|
+
|
|
138
|
+
const handleReset = useCallback(() => {
|
|
139
|
+
Alert.alert(
|
|
140
|
+
'Reset Settings',
|
|
141
|
+
'Are you sure you want to reset all settings to default?',
|
|
142
|
+
[
|
|
143
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
144
|
+
{
|
|
145
|
+
text: 'Reset',
|
|
146
|
+
style: 'destructive',
|
|
147
|
+
onPress: () => {
|
|
148
|
+
resetSettings.mutate('user123', {
|
|
149
|
+
onSuccess: () => {
|
|
150
|
+
Alert.alert('Success', 'Settings have been reset');
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
]
|
|
156
|
+
);
|
|
157
|
+
}, [resetSettings]);
|
|
158
|
+
|
|
159
|
+
return <Button onPress={handleReset} title="Reset Settings" />;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Returns
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
interface ResetSettingsMutationResult {
|
|
167
|
+
mutate: (variables: string) => void;
|
|
168
|
+
mutateAsync: (variables: string) => Promise<SettingsResult>;
|
|
169
|
+
isLoading: boolean;
|
|
170
|
+
isError: boolean;
|
|
171
|
+
error: Error | null;
|
|
172
|
+
data: SettingsResult | undefined;
|
|
173
|
+
reset: () => void;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Examples
|
|
178
|
+
|
|
179
|
+
**Simple Reset:**
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
const resetSettings = useResetSettingsMutation();
|
|
183
|
+
|
|
184
|
+
const handleReset = () => {
|
|
185
|
+
resetSettings.mutate('user123');
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**With Confirmation:**
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
const resetSettings = useResetSettingsMutation();
|
|
193
|
+
|
|
194
|
+
const handleReset = () => {
|
|
195
|
+
Alert.alert(
|
|
196
|
+
'Confirm Reset',
|
|
197
|
+
'This will reset all settings to default. Continue?',
|
|
198
|
+
[
|
|
199
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
200
|
+
{
|
|
201
|
+
text: 'Reset',
|
|
202
|
+
style: 'destructive',
|
|
203
|
+
onPress: () => resetSettings.mutate('user123'),
|
|
204
|
+
},
|
|
205
|
+
]
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**With Post-Reset Actions:**
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
const resetSettings = useResetSettingsMutation();
|
|
214
|
+
|
|
215
|
+
const handleReset = () => {
|
|
216
|
+
resetSettings.mutate('user123', {
|
|
217
|
+
onSuccess: (data) => {
|
|
218
|
+
// Apply default theme
|
|
219
|
+
applyTheme(data.settings.theme);
|
|
220
|
+
|
|
221
|
+
// Restart app if needed
|
|
222
|
+
if (needsRestart) {
|
|
223
|
+
Updates.reloadAsync();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
Alert.alert('Success', 'Settings reset successfully');
|
|
227
|
+
},
|
|
228
|
+
onError: (error) => {
|
|
229
|
+
Alert.alert('Error', 'Failed to reset settings');
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Mutation Options
|
|
236
|
+
|
|
237
|
+
### onSuccess
|
|
238
|
+
|
|
239
|
+
Callback executed when mutation succeeds.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
243
|
+
|
|
244
|
+
updateSettings.mutate(
|
|
245
|
+
{ userId: 'user123', settings: { theme: 'dark' } },
|
|
246
|
+
{
|
|
247
|
+
onSuccess: (data, variables) => {
|
|
248
|
+
console.log('Updated settings:', data);
|
|
249
|
+
console.log('User ID:', variables.userId);
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### onError
|
|
256
|
+
|
|
257
|
+
Callback executed when mutation fails.
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
261
|
+
|
|
262
|
+
updateSettings.mutate(
|
|
263
|
+
{ userId: 'user123', settings: { theme: 'dark' } },
|
|
264
|
+
{
|
|
265
|
+
onError: (error) => {
|
|
266
|
+
Alert.alert('Error', error.message);
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### onMutate
|
|
273
|
+
|
|
274
|
+
Callback executed before mutation, useful for optimistic updates.
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
updateSettings.mutate(
|
|
278
|
+
{ userId: 'user123', settings: { theme: 'dark' } },
|
|
279
|
+
{
|
|
280
|
+
onMutate: async (variables) => {
|
|
281
|
+
// Cancel related queries
|
|
282
|
+
await queryClient.cancelQueries(['settings', variables.userId]);
|
|
283
|
+
|
|
284
|
+
// Snapshot previous value
|
|
285
|
+
const previous = queryClient.getQueryData(['settings', variables.userId]);
|
|
286
|
+
|
|
287
|
+
// Optimistically update
|
|
288
|
+
queryClient.setQueryData(['settings', variables.userId], (old: any) => ({
|
|
289
|
+
...old,
|
|
290
|
+
...variables.settings,
|
|
291
|
+
}));
|
|
292
|
+
|
|
293
|
+
// Return context with snapshot
|
|
294
|
+
return { previous };
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### onSettled
|
|
301
|
+
|
|
302
|
+
Callback executed after mutation succeeds or fails.
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
updateSettings.mutate(
|
|
306
|
+
{ userId: 'user123', settings: { theme: 'dark' } },
|
|
307
|
+
{
|
|
308
|
+
onSettled: (data, error, variables) => {
|
|
309
|
+
// Always invalidate queries
|
|
310
|
+
queryClient.invalidateQueries(['settings', variables.userId]);
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Usage Examples
|
|
317
|
+
|
|
318
|
+
### Complete Form Handler
|
|
319
|
+
|
|
320
|
+
```tsx
|
|
321
|
+
function SettingsForm() {
|
|
322
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
323
|
+
const [theme, setTheme] = useState('light');
|
|
324
|
+
const [language, setLanguage] = useState('en-US');
|
|
325
|
+
|
|
326
|
+
const handleSubmit = useCallback(() => {
|
|
327
|
+
updateSettings.mutate(
|
|
328
|
+
{
|
|
329
|
+
userId: 'user123',
|
|
330
|
+
settings: {
|
|
331
|
+
theme,
|
|
332
|
+
language,
|
|
333
|
+
notificationsEnabled: true,
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
onSuccess: () => {
|
|
338
|
+
Alert.alert('Success', 'Settings saved successfully');
|
|
339
|
+
},
|
|
340
|
+
onError: (error) => {
|
|
341
|
+
Alert.alert('Error', 'Failed to save settings');
|
|
342
|
+
},
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
}, [theme, language, updateSettings]);
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<View>
|
|
349
|
+
<ThemeSelector value={theme} onChange={setTheme} />
|
|
350
|
+
<LanguagePicker value={language} onChange={setLanguage} />
|
|
351
|
+
<Button
|
|
352
|
+
onPress={handleSubmit}
|
|
353
|
+
loading={updateSettings.isLoading}
|
|
354
|
+
title="Save Settings"
|
|
355
|
+
/>
|
|
356
|
+
</View>
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Batch Updates
|
|
362
|
+
|
|
363
|
+
```tsx
|
|
364
|
+
function BatchUpdateExample() {
|
|
365
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
366
|
+
|
|
367
|
+
const updateMultiplePreferences = async () => {
|
|
368
|
+
const updates = [
|
|
369
|
+
{ theme: 'dark' },
|
|
370
|
+
{ language: 'tr-TR' },
|
|
371
|
+
{ notificationsEnabled: true },
|
|
372
|
+
];
|
|
373
|
+
|
|
374
|
+
// Update sequentially
|
|
375
|
+
for (const update of updates) {
|
|
376
|
+
await updateSettings.mutateAsync({
|
|
377
|
+
userId: 'user123',
|
|
378
|
+
settings: update,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
Alert.alert('Success', 'All settings updated');
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
return <Button onPress={updateMultiplePreferences} title="Update All" />;
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Debounced Updates
|
|
390
|
+
|
|
391
|
+
```tsx
|
|
392
|
+
function DebouncedSettings() {
|
|
393
|
+
const updateSettings = useUpdateSettingsMutation();
|
|
394
|
+
const debouncedUpdate = useMemo(
|
|
395
|
+
() => debounce((settings: Partial<UserSettings>) => {
|
|
396
|
+
updateSettings.mutate({
|
|
397
|
+
userId: 'user123',
|
|
398
|
+
settings,
|
|
399
|
+
});
|
|
400
|
+
}, 500),
|
|
401
|
+
[updateSettings]
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const handleThemeChange = (theme: 'light' | 'dark') => {
|
|
405
|
+
debouncedUpdate({ theme });
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
return <ThemeSelector onChange={handleThemeChange} />;
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Best Practices
|
|
413
|
+
|
|
414
|
+
1. **Optimistic Updates**: Use onMutate for immediate UI feedback
|
|
415
|
+
2. **Error Handling**: Always handle errors gracefully
|
|
416
|
+
3. **Loading States**: Show loading indicators during mutations
|
|
417
|
+
4. **Confirmation**: Confirm destructive operations like reset
|
|
418
|
+
5. **Invalidation**: Invalidate queries after mutations
|
|
419
|
+
6. **Rollback**: Implement rollback for failed optimistic updates
|
|
420
|
+
7. **Type Safety**: Use TypeScript for mutation variables
|
|
421
|
+
|
|
422
|
+
## Related
|
|
423
|
+
|
|
424
|
+
- **Settings Queries**: Query hooks for fetching settings
|
|
425
|
+
- **useSettings**: Combined hook for settings management
|
|
426
|
+
- **Settings Repository**: Data persistence layer
|
|
427
|
+
|
|
428
|
+
## License
|
|
429
|
+
|
|
430
|
+
MIT
|