Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | /**
* @file useAppSettingsForm.ts
* @module app/settings/hooks/useAppSettingsForm
*
* @summary
* Custom hook for managing application settings form state and submission.
* Encapsulates user preferences and system info state management.
*
* @enterprise
* - Separates form logic from UI components
* - Integrates with useSettings hook for data persistence
* - Provides callbacks for form submission and defaults reset
* - Type-safe form state management
* - Full TypeDoc coverage for all exported functions
*/
import { useSettings } from '../../../hooks/useSettings';
import type { DateFormat, NumberFormat, TableDensity } from '../../../context/settings';
interface FormState {
dateFormat: DateFormat;
numberFormat: NumberFormat;
tableDensity: TableDensity;
}
/**
* Hook for managing application settings form state and submission.
*
* Provides form state, callbacks for updating preferences, and system info loading.
* Handles persistence through useSettings hook integration.
*
* @returns Object containing form state, callbacks, and loading state
*
* @example
* ```tsx
* const { formState, handleDateFormatChange, isLoading } = useAppSettingsForm();
* ```
*/
export function useAppSettingsForm() {
const { userPreferences, systemInfo, setUserPreferences, resetToDefaults, isLoading } =
useSettings();
/**
* Current form state derived from user preferences.
*/
const formState: FormState = {
dateFormat: userPreferences.dateFormat,
numberFormat: userPreferences.numberFormat,
tableDensity: userPreferences.tableDensity,
};
/**
* Handle date format change.
* Updates user preferences and persists to storage.
*
* @param newFormat - New date format value
*/
const handleDateFormatChange = (newFormat: DateFormat) => {
setUserPreferences({ dateFormat: newFormat });
};
/**
* Handle number format change.
* Updates user preferences and persists to storage.
*
* @param newFormat - New number format value
*/
const handleNumberFormatChange = (newFormat: NumberFormat) => {
setUserPreferences({ numberFormat: newFormat });
};
/**
* Handle table density change.
* Updates user preferences and persists to storage.
*
* @param newDensity - New table density value
*/
const handleTableDensityChange = (newDensity: TableDensity) => {
setUserPreferences({ tableDensity: newDensity });
};
/**
* Reset all settings to default values.
* Clears user preferences and resets to application defaults.
*/
const handleResetDefaults = () => {
resetToDefaults();
};
return {
formState,
systemInfo,
isLoading,
handleDateFormatChange,
handleNumberFormatChange,
handleTableDensityChange,
handleResetDefaults,
};
}
|