UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

239 lines (236 loc) • 9.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _OxyContext = require("../context/OxyContext"); var _sonner = require("../../lib/sonner"); var _components = require("../components"); var _useI18n = require("../hooks/useI18n"); 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 [safeSearch, setSafeSearch] = (0, _react.useState)(false); const [searchPersonalization, setSearchPersonalization] = (0, _react.useState)(true); const [isLoading, setIsLoading] = (0, _react.useState)(true); const [isSaving, setIsSaving] = (0, _react.useState)(false); // Load settings (0, _react.useEffect)(() => { const loadSettings = async () => { try { setIsLoading(true); if (user?.id && oxyServices) { // Load from user's privacy settings const userData = await oxyServices.getCurrentUser(); const privacySettings = userData?.privacySettings || {}; // SafeSearch is typically stored in privacySettings.autoFilter or a separate field setSafeSearch(privacySettings.autoFilter ?? false); setSearchPersonalization(privacySettings.dataSharing ?? true); } } catch (error) { console.error('Failed to load search settings:', error); } finally { setIsLoading(false); } }; loadSettings(); }, [user?.id, oxyServices]); const handleSafeSearchToggle = (0, _react.useCallback)(async value => { try { setIsSaving(true); setSafeSearch(value); if (user?.id && oxyServices) { // Update privacy settings await oxyServices.updateProfile({ privacySettings: { autoFilter: value } }); _sonner.toast.success(t('searchSettings.safeSearch.updated') || 'SafeSearch setting updated'); } } catch (error) { console.error('Failed to update SafeSearch:', error); _sonner.toast.error(t('searchSettings.safeSearch.error') || 'Failed to update SafeSearch'); setSafeSearch(!value); // Revert on error } finally { setIsSaving(false); } }, [user?.id, oxyServices, t]); const handlePersonalizationToggle = (0, _react.useCallback)(async value => { try { setIsSaving(true); setSearchPersonalization(value); if (user?.id && oxyServices) { // Update privacy settings await oxyServices.updateProfile({ privacySettings: { dataSharing: value } }); _sonner.toast.success(t('searchSettings.personalization.updated') || 'Search personalization updated'); } } catch (error) { console.error('Failed to update personalization:', error); _sonner.toast.error(t('searchSettings.personalization.error') || 'Failed to update personalization'); setSearchPersonalization(!value); // Revert on error } finally { setIsSaving(false); } }, [user?.id, oxyServices, t]); const themeStyles = (0, _react.useMemo)(() => { const isDarkTheme = theme === 'dark'; return { textColor: isDarkTheme ? '#FFFFFF' : '#000000', backgroundColor: isDarkTheme ? '#121212' : '#FFFFFF', secondaryBackgroundColor: isDarkTheme ? '#222222' : '#F5F5F5', borderColor: isDarkTheme ? '#444444' : '#E0E0E0' }; }, [theme]); if (isLoading) { return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor: themeStyles.backgroundColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Header, { title: t('searchSettings.title') || 'Search Settings', theme: theme, onBack: goBack || onClose, variant: "minimal", elevation: "subtle" }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.loadingContainer, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { size: "large", color: themeStyles.textColor }) })] }); } return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor: themeStyles.backgroundColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Header, { title: t('searchSettings.title') || 'Search Settings', theme: theme, onBack: goBack || onClose, variant: "minimal", elevation: "subtle" }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, { style: styles.content, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Section, { title: t('searchSettings.safeSearch.title') || 'SafeSearch', theme: theme, isFirst: true, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.settingRow, { borderBottomColor: themeStyles.borderColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.settingInfo, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.settingTitle, { color: themeStyles.textColor }], children: t('searchSettings.safeSearch.label') || 'Enable SafeSearch' }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.settingDescription, { color: themeStyles.textColor }], children: t('searchSettings.safeSearch.description') || 'Filter out explicit content from search results' })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Switch, { value: safeSearch, onValueChange: handleSafeSearchToggle, disabled: isSaving, trackColor: { false: '#767577', true: '#d169e5' }, thumbColor: safeSearch ? '#fff' : '#f4f3f4' })] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Section, { title: t('searchSettings.personalization.title') || 'Search Personalization', theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.settingRow, { borderBottomColor: themeStyles.borderColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.settingInfo, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.settingTitle, { color: themeStyles.textColor }], children: t('searchSettings.personalization.label') || 'Personalized Search' }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.settingDescription, { color: themeStyles.textColor }], children: t('searchSettings.personalization.description') || 'Use your activity to improve search results' })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Switch, { value: searchPersonalization, onValueChange: handlePersonalizationToggle, disabled: isSaving, trackColor: { false: '#767577', true: '#d169e5' }, thumbColor: searchPersonalization ? '#fff' : '#f4f3f4' })] }) })] })] }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, content: { flex: 1, padding: 16 }, loadingContainer: { flex: 1, alignItems: 'center', justifyContent: 'center' }, settingRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingVertical: 16, borderBottomWidth: 1 }, settingInfo: { flex: 1, marginRight: 16 }, settingTitle: { fontSize: 16, fontWeight: '500', marginBottom: 4 }, settingDescription: { fontSize: 14, opacity: 0.7 } }); var _default = exports.default = /*#__PURE__*/_react.default.memo(SearchSettingsScreen); //# sourceMappingURL=SearchSettingsScreen.js.map