UNPKG

@oxyhq/services

Version:

OxyHQ Expo/React Native SDK — UI components, screens, and native features

148 lines (145 loc) 5.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../components/index.js"); var _useI18n = require("../hooks/useI18n.js"); var _useThemeStyles = require("../hooks/useThemeStyles.js"); var _useSettingToggle = require("../hooks/useSettingToggle.js"); var _themeUtils = require("../utils/themeUtils.js"); var _OxyContext = require("../context/OxyContext.js"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const SearchSettingsScreen = ({ onClose, theme, goBack }) => { const { oxyServices, user } = (0, _OxyContext.useOxy)(); const { t } = (0, _useI18n.useI18n)(); const [isLoading, setIsLoading] = (0, _react.useState)(true); // Use the existing useSettingToggles hook for toggle management const { values: settings, toggle, savingKeys, setValues } = (0, _useSettingToggle.useSettingToggles)({ initialValues: { safeSearch: false, searchPersonalization: true }, onSave: async (key, value) => { if (!user?.id || !oxyServices) return; const fieldMap = { safeSearch: 'autoFilter', searchPersonalization: 'dataSharing' }; await oxyServices.updateProfile({ privacySettings: { [fieldMap[key]]: value } }); }, errorMessage: key => t(`searchSettings.${key}.error`) || `Failed to update ${key}` }); const isSaving = savingKeys.size > 0; // Load initial settings (0, _react.useEffect)(() => { const loadSettings = async () => { try { setIsLoading(true); if (user?.id && oxyServices) { const userData = await oxyServices.getCurrentUser(); const privacySettings = userData?.privacySettings || {}; setValues({ safeSearch: privacySettings.autoFilter ?? false, searchPersonalization: privacySettings.dataSharing ?? true }); } } catch (error) { if (__DEV__) { console.error('Failed to load search settings:', error); } } finally { setIsLoading(false); } }; loadSettings(); }, [user?.id, oxyServices, setValues]); const normalizedTheme = (0, _themeUtils.normalizeTheme)(theme); const themeStyles = (0, _useThemeStyles.useThemeStyles)(normalizedTheme); if (isLoading) { return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor: themeStyles.backgroundColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Header, { title: t('searchSettings.title') || 'Search Settings', onBack: goBack || onClose, variant: "minimal", elevation: "subtle" }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.LoadingState, { color: themeStyles.textColor })] }); } return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor: themeStyles.backgroundColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Header, { title: t('searchSettings.title') || 'Search Settings', onBack: goBack || onClose, variant: "minimal", elevation: "subtle" }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, { style: styles.content, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: t('searchSettings.safeSearch.title') || 'SafeSearch', isFirst: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SettingRow, { title: t('searchSettings.safeSearch.label') || 'Enable SafeSearch', description: t('searchSettings.safeSearch.description') || 'Filter out explicit content from search results', value: settings.safeSearch, onValueChange: () => toggle('safeSearch'), disabled: isSaving, textColor: themeStyles.textColor, mutedTextColor: themeStyles.mutedTextColor, borderColor: themeStyles.borderColor }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: t('searchSettings.personalization.title') || 'Search Personalization', children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SettingRow, { title: t('searchSettings.personalization.label') || 'Personalized Search', description: t('searchSettings.personalization.description') || 'Use your activity to improve search results', value: settings.searchPersonalization, onValueChange: () => toggle('searchPersonalization'), disabled: isSaving, textColor: themeStyles.textColor, mutedTextColor: themeStyles.mutedTextColor, borderColor: themeStyles.borderColor }) })] })] }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, content: { flex: 1, padding: 16 } }); var _default = exports.default = /*#__PURE__*/_react.default.memo(SearchSettingsScreen); //# sourceMappingURL=SearchSettingsScreen.js.map