@oxyhq/services 5.18.1 → 5.18.3
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/lib/commonjs/core/mixins/index.js +36 -13
- package/lib/commonjs/core/mixins/index.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/client.js +170 -0
- package/lib/commonjs/ui/client.js.map +1 -0
- package/lib/commonjs/ui/components/profile/EditFieldModal.js +412 -0
- package/lib/commonjs/ui/components/profile/EditFieldModal.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +63 -1
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAuth.js +115 -0
- package/lib/commonjs/ui/hooks/useAuth.js.map +1 -0
- package/lib/commonjs/ui/hooks/useSettingToggle.js +7 -1
- package/lib/commonjs/ui/hooks/useSettingToggle.js.map +1 -1
- package/lib/commonjs/ui/hooks/useWebSSO.js +75 -0
- package/lib/commonjs/ui/hooks/useWebSSO.js.map +1 -0
- package/lib/commonjs/ui/index.js +17 -2
- package/lib/commonjs/ui/index.js.map +1 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +59 -65
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SearchSettingsScreen.js +38 -58
- package/lib/commonjs/ui/screens/SearchSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/server.js +105 -0
- package/lib/commonjs/ui/server.js.map +1 -0
- package/lib/commonjs/ui/utils/iconNames.js +133 -0
- package/lib/commonjs/ui/utils/iconNames.js.map +1 -0
- package/lib/commonjs/ui/utils/sessionHelpers.js +7 -0
- package/lib/commonjs/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/commonjs/utils/hookUtils.js +31 -13
- package/lib/commonjs/utils/hookUtils.js.map +1 -1
- package/lib/commonjs/utils/requestUtils.js +4 -3
- package/lib/commonjs/utils/requestUtils.js.map +1 -1
- package/lib/module/core/mixins/index.js +36 -13
- package/lib/module/core/mixins/index.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/client.js +47 -0
- package/lib/module/ui/client.js.map +1 -0
- package/lib/module/ui/components/profile/EditFieldModal.js +406 -0
- package/lib/module/ui/components/profile/EditFieldModal.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +63 -1
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/hooks/useAuth.js +106 -0
- package/lib/module/ui/hooks/useAuth.js.map +1 -0
- package/lib/module/ui/hooks/useSettingToggle.js +7 -1
- package/lib/module/ui/hooks/useSettingToggle.js.map +1 -1
- package/lib/module/ui/hooks/useWebSSO.js +71 -0
- package/lib/module/ui/hooks/useWebSSO.js.map +1 -0
- package/lib/module/ui/index.js +17 -3
- package/lib/module/ui/index.js.map +1 -1
- package/lib/module/ui/screens/PrivacySettingsScreen.js +59 -65
- package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/SearchSettingsScreen.js +39 -59
- package/lib/module/ui/screens/SearchSettingsScreen.js.map +1 -1
- package/lib/module/ui/server.js +65 -0
- package/lib/module/ui/server.js.map +1 -0
- package/lib/module/ui/utils/iconNames.js +124 -0
- package/lib/module/ui/utils/iconNames.js.map +1 -0
- package/lib/module/ui/utils/sessionHelpers.js +7 -0
- package/lib/module/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/module/utils/hookUtils.js +31 -13
- package/lib/module/utils/hookUtils.js.map +1 -1
- package/lib/module/utils/requestUtils.js +4 -2
- package/lib/module/utils/requestUtils.js.map +1 -1
- package/lib/typescript/commonjs/core/mixins/index.d.ts +18 -1115
- package/lib/typescript/commonjs/core/mixins/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/client.d.ts +33 -0
- package/lib/typescript/commonjs/ui/client.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/profile/EditFieldModal.d.ts +110 -0
- package/lib/typescript/commonjs/ui/components/profile/EditFieldModal.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts +3 -0
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts +3 -3
- package/lib/typescript/commonjs/ui/hooks/queries/useAccountQueries.d.ts +6 -10
- package/lib/typescript/commonjs/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useSecurityQueries.d.ts +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useSecurityQueries.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useServicesQueries.d.ts +3 -5
- package/lib/typescript/commonjs/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useAssets.d.ts +1 -1
- package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts +69 -0
- package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/useSettingToggle.d.ts +4 -2
- package/lib/typescript/commonjs/ui/hooks/useSettingToggle.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts +34 -0
- package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/index.d.ts +2 -2
- package/lib/typescript/commonjs/ui/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/SearchSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/server.d.ts +43 -0
- package/lib/typescript/commonjs/ui/server.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/iconNames.d.ts +112 -0
- package/lib/typescript/commonjs/ui/utils/iconNames.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/sessionHelpers.d.ts +8 -3
- package/lib/typescript/commonjs/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/hookUtils.d.ts +8 -8
- package/lib/typescript/commonjs/utils/hookUtils.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/requestUtils.d.ts +3 -1
- package/lib/typescript/commonjs/utils/requestUtils.d.ts.map +1 -1
- package/lib/typescript/module/core/mixins/index.d.ts +18 -1115
- package/lib/typescript/module/core/mixins/index.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/client.d.ts +33 -0
- package/lib/typescript/module/ui/client.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/profile/EditFieldModal.d.ts +110 -0
- package/lib/typescript/module/ui/components/profile/EditFieldModal.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/OxyContext.d.ts +3 -0
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts +3 -3
- package/lib/typescript/module/ui/hooks/queries/useAccountQueries.d.ts +6 -10
- package/lib/typescript/module/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/useSecurityQueries.d.ts +1 -1
- package/lib/typescript/module/ui/hooks/queries/useSecurityQueries.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/useServicesQueries.d.ts +3 -5
- package/lib/typescript/module/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useAssets.d.ts +1 -1
- package/lib/typescript/module/ui/hooks/useAuth.d.ts +69 -0
- package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/useSettingToggle.d.ts +4 -2
- package/lib/typescript/module/ui/hooks/useSettingToggle.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useWebSSO.d.ts +34 -0
- package/lib/typescript/module/ui/hooks/useWebSSO.d.ts.map +1 -0
- package/lib/typescript/module/ui/index.d.ts +2 -2
- package/lib/typescript/module/ui/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/SearchSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/server.d.ts +43 -0
- package/lib/typescript/module/ui/server.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/iconNames.d.ts +112 -0
- package/lib/typescript/module/ui/utils/iconNames.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/sessionHelpers.d.ts +8 -3
- package/lib/typescript/module/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/lib/typescript/module/utils/hookUtils.d.ts +8 -8
- package/lib/typescript/module/utils/hookUtils.d.ts.map +1 -1
- package/lib/typescript/module/utils/requestUtils.d.ts +3 -1
- package/lib/typescript/module/utils/requestUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/mixins/index.ts +57 -43
- package/src/index.ts +3 -1
- package/src/ui/client.ts +55 -0
- package/src/ui/components/profile/EditFieldModal.tsx +465 -0
- package/src/ui/context/OxyContext.tsx +69 -0
- package/src/ui/hooks/useAuth.ts +159 -0
- package/src/ui/hooks/useSettingToggle.ts +7 -3
- package/src/ui/hooks/useWebSSO.ts +93 -0
- package/src/ui/index.ts +17 -2
- package/src/ui/screens/PrivacySettingsScreen.tsx +54 -63
- package/src/ui/screens/SearchSettingsScreen.tsx +42 -64
- package/src/ui/server.ts +70 -0
- package/src/ui/utils/iconNames.ts +136 -0
- package/src/ui/utils/sessionHelpers.ts +10 -3
- package/src/utils/hookUtils.ts +38 -14
- package/src/utils/requestUtils.ts +10 -7
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unified Auth Hook
|
|
5
|
+
*
|
|
6
|
+
* Provides a clean, standard interface for authentication across all platforms.
|
|
7
|
+
* This is the recommended way to access auth state in Oxy apps.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useAuth } from '@oxyhq/services';
|
|
12
|
+
*
|
|
13
|
+
* function MyComponent() {
|
|
14
|
+
* const { user, isAuthenticated, isLoading, signIn, signOut } = useAuth();
|
|
15
|
+
*
|
|
16
|
+
* if (isLoading) return <Loading />;
|
|
17
|
+
* if (!isAuthenticated) return <SignInButton onClick={() => signIn()} />;
|
|
18
|
+
* return <Welcome user={user} />;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { useCallback } from 'react';
|
|
24
|
+
import { useOxy } from "../context/OxyContext.js";
|
|
25
|
+
/**
|
|
26
|
+
* Unified auth hook for all Oxy apps
|
|
27
|
+
*
|
|
28
|
+
* Features:
|
|
29
|
+
* - Zero config: Just wrap with OxyProvider and use
|
|
30
|
+
* - Cross-platform: Same API on native and web
|
|
31
|
+
* - Auto SSO: Web apps automatically check for cross-domain sessions
|
|
32
|
+
* - Type-safe: Full TypeScript support
|
|
33
|
+
*/
|
|
34
|
+
export function useAuth() {
|
|
35
|
+
const {
|
|
36
|
+
user,
|
|
37
|
+
isAuthenticated,
|
|
38
|
+
isLoading,
|
|
39
|
+
isTokenReady,
|
|
40
|
+
error,
|
|
41
|
+
signIn: oxySignIn,
|
|
42
|
+
logout,
|
|
43
|
+
logoutAll,
|
|
44
|
+
refreshSessions,
|
|
45
|
+
oxyServices,
|
|
46
|
+
hasIdentity,
|
|
47
|
+
getPublicKey,
|
|
48
|
+
showBottomSheet
|
|
49
|
+
} = useOxy();
|
|
50
|
+
const signIn = useCallback(async publicKey => {
|
|
51
|
+
// If public key provided, use it directly
|
|
52
|
+
if (publicKey) {
|
|
53
|
+
return oxySignIn(publicKey);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Try to get existing identity
|
|
57
|
+
const hasExisting = await hasIdentity();
|
|
58
|
+
if (hasExisting) {
|
|
59
|
+
const existingKey = await getPublicKey();
|
|
60
|
+
if (existingKey) {
|
|
61
|
+
return oxySignIn(existingKey);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// No identity - show auth UI
|
|
66
|
+
// On native: shows bottom sheet for identity creation
|
|
67
|
+
// On web: could trigger popup auth
|
|
68
|
+
showBottomSheet?.('OxyAuth');
|
|
69
|
+
|
|
70
|
+
// Return a promise that resolves when auth completes
|
|
71
|
+
// This is a simplified version - real implementation would
|
|
72
|
+
// wait for the auth flow to complete
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
// For now, just reject - the bottom sheet handles the flow
|
|
75
|
+
reject(new Error('Please complete sign-in in the auth sheet'));
|
|
76
|
+
});
|
|
77
|
+
}, [oxySignIn, hasIdentity, getPublicKey, showBottomSheet]);
|
|
78
|
+
const signOut = useCallback(async () => {
|
|
79
|
+
await logout();
|
|
80
|
+
}, [logout]);
|
|
81
|
+
const signOutAll = useCallback(async () => {
|
|
82
|
+
await logoutAll();
|
|
83
|
+
}, [logoutAll]);
|
|
84
|
+
const refresh = useCallback(async () => {
|
|
85
|
+
await refreshSessions();
|
|
86
|
+
}, [refreshSessions]);
|
|
87
|
+
return {
|
|
88
|
+
// State
|
|
89
|
+
user,
|
|
90
|
+
isAuthenticated,
|
|
91
|
+
isLoading,
|
|
92
|
+
isReady: isTokenReady,
|
|
93
|
+
error,
|
|
94
|
+
// Actions
|
|
95
|
+
signIn,
|
|
96
|
+
signOut,
|
|
97
|
+
signOutAll,
|
|
98
|
+
refresh,
|
|
99
|
+
// Advanced
|
|
100
|
+
oxyServices
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Re-export useOxy for backward compatibility and advanced usage
|
|
105
|
+
export { useOxy } from "../context/OxyContext.js";
|
|
106
|
+
//# sourceMappingURL=useAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useOxy","useAuth","user","isAuthenticated","isLoading","isTokenReady","error","signIn","oxySignIn","logout","logoutAll","refreshSessions","oxyServices","hasIdentity","getPublicKey","showBottomSheet","publicKey","hasExisting","existingKey","Promise","resolve","reject","Error","signOut","signOutAll","refresh","isReady"],"sourceRoot":"../../../../src","sources":["ui/hooks/useAuth.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,OAAO;AACnC,SAASC,MAAM,QAAQ,0BAAuB;AAiD9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAA,EAAkB;EACvC,MAAM;IACJC,IAAI;IACJC,eAAe;IACfC,SAAS;IACTC,YAAY;IACZC,KAAK;IACLC,MAAM,EAAEC,SAAS;IACjBC,MAAM;IACNC,SAAS;IACTC,eAAe;IACfC,WAAW;IACXC,WAAW;IACXC,YAAY;IACZC;EACF,CAAC,GAAGf,MAAM,CAAC,CAAC;EAEZ,MAAMO,MAAM,GAAGR,WAAW,CAAC,MAAOiB,SAAkB,IAAoB;IACtE;IACA,IAAIA,SAAS,EAAE;MACb,OAAOR,SAAS,CAACQ,SAAS,CAAC;IAC7B;;IAEA;IACA,MAAMC,WAAW,GAAG,MAAMJ,WAAW,CAAC,CAAC;IAEvC,IAAII,WAAW,EAAE;MACf,MAAMC,WAAW,GAAG,MAAMJ,YAAY,CAAC,CAAC;MACxC,IAAII,WAAW,EAAE;QACf,OAAOV,SAAS,CAACU,WAAW,CAAC;MAC/B;IACF;;IAEA;IACA;IACA;IACAH,eAAe,GAAG,SAAS,CAAC;;IAE5B;IACA;IACA;IACA,OAAO,IAAII,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC;MACAA,MAAM,CAAC,IAAIC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAChE,CAAC,CAAC;EACJ,CAAC,EAAE,CAACd,SAAS,EAAEK,WAAW,EAAEC,YAAY,EAAEC,eAAe,CAAC,CAAC;EAE3D,MAAMQ,OAAO,GAAGxB,WAAW,CAAC,YAA2B;IACrD,MAAMU,MAAM,CAAC,CAAC;EAChB,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,MAAMe,UAAU,GAAGzB,WAAW,CAAC,YAA2B;IACxD,MAAMW,SAAS,CAAC,CAAC;EACnB,CAAC,EAAE,CAACA,SAAS,CAAC,CAAC;EAEf,MAAMe,OAAO,GAAG1B,WAAW,CAAC,YAA2B;IACrD,MAAMY,eAAe,CAAC,CAAC;EACzB,CAAC,EAAE,CAACA,eAAe,CAAC,CAAC;EAErB,OAAO;IACL;IACAT,IAAI;IACJC,eAAe;IACfC,SAAS;IACTsB,OAAO,EAAErB,YAAY;IACrBC,KAAK;IAEL;IACAC,MAAM;IACNgB,OAAO;IACPC,UAAU;IACVC,OAAO;IAEP;IACAb;EACF,CAAC;AACH;;AAEA;AACA,SAASZ,MAAM,QAAQ,0BAAuB","ignoreList":[]}
|
|
@@ -109,11 +109,17 @@ export function useSettingToggles(options) {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
}, [values, onSave, errorMessage, revertOnError]);
|
|
112
|
+
const setValuesExternal = useCallback(newValues => {
|
|
113
|
+
setValues(prev => ({
|
|
114
|
+
...prev,
|
|
115
|
+
...newValues
|
|
116
|
+
}));
|
|
117
|
+
}, []);
|
|
112
118
|
return {
|
|
113
119
|
values,
|
|
114
120
|
savingKeys,
|
|
115
121
|
toggle,
|
|
116
|
-
setValues
|
|
122
|
+
setValues: setValuesExternal
|
|
117
123
|
};
|
|
118
124
|
}
|
|
119
125
|
export default useSettingToggle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useCallback","useEffect","toast","useSettingToggle","options","initialValue","onSave","successMessage","errorMessage","revertOnError","showSuccessToast","value","setValue","isSaving","setIsSaving","toggle","previousValue","newValue","success","err","error","message","useSettingToggles","initialValues","values","setValues","savingKeys","setSavingKeys","Set","key","prev","add","next","delete"],"sourceRoot":"../../../../src","sources":["ui/hooks/useSettingToggle.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AACxD,SAASC,KAAK,QAAQ,qBAAkB;AA4BxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,OAAgC,EAA0B;EACvF,MAAM;IACFC,YAAY;IACZC,MAAM;IACNC,cAAc;IACdC,YAAY,GAAG,wBAAwB;IACvCC,aAAa,GAAG,IAAI;IACpBC,gBAAgB,GAAG;EACvB,CAAC,GAAGN,OAAO;EAEX,MAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGb,QAAQ,CAACM,YAAY,CAAC;EAChD,MAAM,CAACQ,QAAQ,EAAEC,WAAW,CAAC,GAAGf,QAAQ,CAAC,KAAK,CAAC;;EAE/C;EACAE,SAAS,CAAC,MAAM;IACZW,QAAQ,CAACP,YAAY,CAAC;EAC1B,CAAC,EAAE,CAACA,YAAY,CAAC,CAAC;EAElB,MAAMU,MAAM,GAAGf,WAAW,CAAC,YAAY;IACnC,MAAMgB,aAAa,GAAGL,KAAK;IAC3B,MAAMM,QAAQ,GAAG,CAACN,KAAK;;IAEvB;IACAC,QAAQ,CAACK,QAAQ,CAAC;IAClBH,WAAW,CAAC,IAAI,CAAC;IAEjB,IAAI;MACA,MAAMR,MAAM,CAACW,QAAQ,CAAC;MAEtB,IAAIP,gBAAgB,IAAIH,cAAc,EAAE;QACpCL,KAAK,CAACgB,OAAO,CAACX,cAAc,CAAC;MACjC;IACJ,CAAC,CAAC,OAAOY,GAAQ,EAAE;MACf;MACA,IAAIV,aAAa,EAAE;QACfG,QAAQ,CAACI,aAAa,CAAC;MAC3B;MAEAd,KAAK,CAACkB,KAAK,CAACZ,YAAY,IAAIW,GAAG,EAAEE,OAAO,IAAI,mBAAmB,CAAC;IACpE,CAAC,SAAS;MACNP,WAAW,CAAC,KAAK,CAAC;IACtB;EACJ,CAAC,EAAE,CAACH,KAAK,EAAEL,MAAM,EAAEC,cAAc,EAAEC,YAAY,EAAEC,aAAa,EAAEC,gBAAgB,CAAC,CAAC;EAElF,OAAO;IAAEC,KAAK;IAAEE,QAAQ;IAAEE,MAAM;IAAEH;EAAS,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASU,iBAAiBA,
|
|
1
|
+
{"version":3,"names":["useState","useCallback","useEffect","toast","useSettingToggle","options","initialValue","onSave","successMessage","errorMessage","revertOnError","showSuccessToast","value","setValue","isSaving","setIsSaving","toggle","previousValue","newValue","success","err","error","message","useSettingToggles","initialValues","values","setValues","savingKeys","setSavingKeys","Set","key","prev","add","next","delete","setValuesExternal","newValues"],"sourceRoot":"../../../../src","sources":["ui/hooks/useSettingToggle.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AACxD,SAASC,KAAK,QAAQ,qBAAkB;AA4BxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,OAAgC,EAA0B;EACvF,MAAM;IACFC,YAAY;IACZC,MAAM;IACNC,cAAc;IACdC,YAAY,GAAG,wBAAwB;IACvCC,aAAa,GAAG,IAAI;IACpBC,gBAAgB,GAAG;EACvB,CAAC,GAAGN,OAAO;EAEX,MAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGb,QAAQ,CAACM,YAAY,CAAC;EAChD,MAAM,CAACQ,QAAQ,EAAEC,WAAW,CAAC,GAAGf,QAAQ,CAAC,KAAK,CAAC;;EAE/C;EACAE,SAAS,CAAC,MAAM;IACZW,QAAQ,CAAC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I;MAAE,GAAGK;IAAU,CAAC,CAAC,CAAC;EAClD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IAAEX,MAAM;IAAEE,UAAU;IAAEX,MAAM;IAAEU,SAAS,EAAES;EAAkB,CAAC;AACvE;AAEA,eAAe/B,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web SSO Hook
|
|
5
|
+
*
|
|
6
|
+
* Automatically handles cross-domain SSO for web apps.
|
|
7
|
+
* Uses the OxyServices.silentSignIn() method which loads a hidden iframe
|
|
8
|
+
* to check for existing session at auth.oxy.so.
|
|
9
|
+
*
|
|
10
|
+
* This is called automatically by OxyContext on web platforms.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
14
|
+
/**
|
|
15
|
+
* Check if we're running in a web browser environment (not React Native)
|
|
16
|
+
*/
|
|
17
|
+
function isWebBrowser() {
|
|
18
|
+
// Check for browser globals and that we have a real DOM (React Native has window but not documentElement)
|
|
19
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof document.documentElement !== 'undefined';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Hook for automatic web SSO
|
|
24
|
+
*
|
|
25
|
+
* Automatically checks for existing cross-domain session on mount.
|
|
26
|
+
* Only runs on web platforms. Uses OxyServices.silentSignIn() internally.
|
|
27
|
+
*/
|
|
28
|
+
export function useWebSSO({
|
|
29
|
+
oxyServices,
|
|
30
|
+
onSessionFound,
|
|
31
|
+
onError,
|
|
32
|
+
enabled = true
|
|
33
|
+
}) {
|
|
34
|
+
const isCheckingRef = useRef(false);
|
|
35
|
+
const hasCheckedRef = useRef(false);
|
|
36
|
+
const checkSSO = useCallback(async () => {
|
|
37
|
+
if (!isWebBrowser() || isCheckingRef.current) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
isCheckingRef.current = true;
|
|
41
|
+
try {
|
|
42
|
+
// Use the existing silentSignIn method from OxyServices
|
|
43
|
+
// which handles iframe creation, postMessage, and token storage
|
|
44
|
+
const session = await oxyServices.silentSignIn?.();
|
|
45
|
+
if (session) {
|
|
46
|
+
await onSessionFound(session);
|
|
47
|
+
}
|
|
48
|
+
return session;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
51
|
+
return null;
|
|
52
|
+
} finally {
|
|
53
|
+
isCheckingRef.current = false;
|
|
54
|
+
}
|
|
55
|
+
}, [oxyServices, onSessionFound, onError]);
|
|
56
|
+
|
|
57
|
+
// Auto-check SSO on mount (web only)
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!enabled || !isWebBrowser() || hasCheckedRef.current) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
hasCheckedRef.current = true;
|
|
63
|
+
checkSSO();
|
|
64
|
+
}, [enabled, checkSSO]);
|
|
65
|
+
return {
|
|
66
|
+
checkSSO,
|
|
67
|
+
isChecking: isCheckingRef.current
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export { isWebBrowser };
|
|
71
|
+
//# sourceMappingURL=useWebSSO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useCallback","isWebBrowser","window","document","documentElement","useWebSSO","oxyServices","onSessionFound","onError","enabled","isCheckingRef","hasCheckedRef","checkSSO","current","session","silentSignIn","error","Error","String","isChecking"],"sourceRoot":"../../../../src","sources":["ui/hooks/useWebSSO.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,EAAEC,MAAM,EAAEC,WAAW,QAAQ,OAAO;AAgBtD;AACA;AACA;AACA,SAASC,YAAYA,CAAA,EAAY;EAC/B;EACA,OAAO,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOC,QAAQ,KAA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EAAET,aAAa,CAACG;EAC5B,CAAC;AACH;AAEA,SAASZ,YAAY","ignoreList":[]}
|
package/lib/module/ui/index.js
CHANGED
|
@@ -2,14 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* UI Component exports - Frontend Only (with backend-safe fallbacks)
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* This module exports all React/React Native UI components and hooks.
|
|
7
7
|
* In backend, all exports are no-ops or empty objects.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: This entry point uses runtime detection which prevents tree-shaking.
|
|
10
|
+
* For better bundle optimization, use:
|
|
11
|
+
* - '@oxyhq/services/ui/client' for client bundles (tree-shakeable)
|
|
12
|
+
* - '@oxyhq/services/ui/server' for SSR environments (all noops)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Client bundle (tree-shakeable)
|
|
16
|
+
* import { OxyProvider, useOxy } from '@oxyhq/services/ui/client';
|
|
17
|
+
*
|
|
18
|
+
* // SSR (noops)
|
|
19
|
+
* import { OxyProvider, useOxy } from '@oxyhq/services/ui/server';
|
|
8
20
|
*/
|
|
9
21
|
import isFrontend from "./isFrontend.js";
|
|
10
22
|
|
|
11
23
|
// UI exports
|
|
12
|
-
let OxyProvider, OxySignInButton, OxyLogo, Avatar, FollowButton, OxyPayButton, FontLoader, setupFonts, OxyIcon, useOxy, useFollow, ProfileScreen, useAuthStore, useAccountStore, fontFamilies, fontStyles, toast, useStorage;
|
|
24
|
+
let OxyProvider, OxySignInButton, OxyLogo, Avatar, FollowButton, OxyPayButton, FontLoader, setupFonts, OxyIcon, useOxy, useAuth, useFollow, ProfileScreen, useAuthStore, useAccountStore, fontFamilies, fontStyles, toast, useStorage;
|
|
13
25
|
if (isFrontend) {
|
|
14
26
|
OxyProvider = require('./components/OxyProvider').default;
|
|
15
27
|
OxySignInButton = require('./components/OxySignInButton').default;
|
|
@@ -21,6 +33,7 @@ if (isFrontend) {
|
|
|
21
33
|
setupFonts = require('./components/FontLoader').setupFonts;
|
|
22
34
|
OxyIcon = require('./components/icon').OxyIcon;
|
|
23
35
|
useOxy = require('./context/OxyContext').useOxy;
|
|
36
|
+
useAuth = require('./hooks/useAuth').useAuth;
|
|
24
37
|
useFollow = require('./hooks').useFollow;
|
|
25
38
|
ProfileScreen = require('./screens/ProfileScreen').default;
|
|
26
39
|
useAuthStore = require('./stores/authStore').useAuthStore;
|
|
@@ -47,6 +60,7 @@ if (isFrontend) {
|
|
|
47
60
|
setupFonts = () => {};
|
|
48
61
|
OxyIcon = noopComponent;
|
|
49
62
|
useOxy = noopHook;
|
|
63
|
+
useAuth = noopHook;
|
|
50
64
|
useFollow = noopHook;
|
|
51
65
|
ProfileScreen = noopComponent;
|
|
52
66
|
useAuthStore = noopHook;
|
|
@@ -56,7 +70,7 @@ if (isFrontend) {
|
|
|
56
70
|
toast = () => {};
|
|
57
71
|
useStorage = () => noopStorageResult;
|
|
58
72
|
}
|
|
59
|
-
export { OxyProvider, OxySignInButton, OxyLogo, Avatar, FollowButton, OxyPayButton, FontLoader, setupFonts, OxyIcon, useOxy, useFollow, ProfileScreen, useAuthStore, useAccountStore, fontFamilies, fontStyles, toast, useStorage };
|
|
73
|
+
export { OxyProvider, OxySignInButton, OxyLogo, Avatar, FollowButton, OxyPayButton, FontLoader, setupFonts, OxyIcon, useOxy, useAuth, useFollow, ProfileScreen, useAuthStore, useAccountStore, fontFamilies, fontStyles, toast, useStorage };
|
|
60
74
|
|
|
61
75
|
// Re-export core services for convenience in UI context
|
|
62
76
|
export { OxyServices } from "../core/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isFrontend","OxyProvider","OxySignInButton","OxyLogo","Avatar","FollowButton","OxyPayButton","FontLoader","setupFonts","OxyIcon","useOxy","useFollow","ProfileScreen","useAuthStore","useAccountStore","fontFamilies","fontStyles","toast","useStorage","require","default","noopComponent","noopHook","noopStorageResult","storage","isReady","OxyServices","handleAuthError","isInvalidSessionError","isTimeoutOrNetworkError","extractErrorMessage"],"sourceRoot":"../../../src","sources":["ui/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,iBAAc;;AAErC;AACA,IAAIC,WAAW,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,EAAEC,YAAY,EAAEC,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,aAAa,EAAEC,YAAY,EAAEC,eAAe,EAAEC,YAAY,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU;
|
|
1
|
+
{"version":3,"names":["isFrontend","OxyProvider","OxySignInButton","OxyLogo","Avatar","FollowButton","OxyPayButton","FontLoader","setupFonts","OxyIcon","useOxy","useAuth","useFollow","ProfileScreen","useAuthStore","useAccountStore","fontFamilies","fontStyles","toast","useStorage","require","default","noopComponent","noopHook","noopStorageResult","storage","isReady","OxyServices","handleAuthError","isInvalidSessionError","isTimeoutOrNetworkError","extractErrorMessage"],"sourceRoot":"../../../src","sources":["ui/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,iBAAc;;AAErC;AACA,IAAIC,WAAW,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,EAAEC,YAAY,EAAEC,YAAY,EAAEC,UAAU,EAAEC,UAAU,EAAEC,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAEC,aAAa,EAAEC,YAAY,EAAEC,eAAe,EAAEC,YAAY,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU;AAErO,IAAInB,UAAU,EAAE;EACdC,WAAW,GAAGmB,OAAO,CAAC,0BAA0B,CAAC,CAACC,OAAO;EACzDnB,eAAe,GAAGkB,OAAO,CAAC,8BAA8B,CAAC,CAACC,OAAO;EACjElB,OAAO,GAAGi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aAAa;EAC3BpB,eAAe,GAAGoB,aAAa;EAC/BnB,OAAO,GAAGmB,aAAa;EACvBlB,MAAM,GAAGkB,aAAa;EACtBjB,YAAY,GAAGiB,aAAa;EAC5BhB,YAAY,GAAGgB,aAAa;EAC5Bf,UAAU,GAAGe,aAAa;EAC1Bd,UAAU,GAAGA,CAAA,KAAM,CAAC,CAAC;EACrBC,OAAO,GAAGa,aAAa;EACvBZ,MAAM,GAAGa,QAAQ;EACjBZ,OAAO,GAAGY,QAAQ;EAClBX,SAAS,GAAGW,QAAQ;EACpBV,aAAa,GAAGS,aAAa;EAC7BR,YAAY,GAAGS,QAAQ;EACvBR,eAAe,GAAGQ,QAAQ;EAC1BP,YAAY,GAAG,CAAC,CAAC;EACjBC,UAAU,GAAG,CAAC,CAAC;EACfC,KAAK,GAAGA,CAAA,KAAM,CAAC,CAAC;EAChBC,UAAU,GAAGA,CAAA,KAAMK,iBAAiB;AACtC;AAEA,SACEvB,WAAW,EACXC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,YAAY,EACZC,YAAY,EACZC,UAAU,EACVC,UAAU,EACVC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,aAAa,EACbC,YAAY,EACZC,eAAe,EACfC,YAAY,EACZC,UAAU,EACVC,KAAK,EACLC,UAAU;;AAGZ;AACA,SAASQ,WAAW,QAAQ,kBAAS;AAGrC;AACA,SACEC,eAAe,EACfC,qBAAqB,EACrBC,uBAAuB,EACvBC,mBAAmB,QACd,0BAAuB;;AAG9B","ignoreList":[]}
|
|
@@ -6,15 +6,36 @@ import { toast } from "../../lib/sonner.js";
|
|
|
6
6
|
import { Header, Section, Avatar, SettingRow, LoadingState, EmptyState, GroupedSection } from "../components/index.js";
|
|
7
7
|
import { useI18n } from "../hooks/useI18n.js";
|
|
8
8
|
import { useThemeStyles } from "../hooks/useThemeStyles.js";
|
|
9
|
+
import { useSettingToggles } from "../hooks/useSettingToggle.js";
|
|
9
10
|
import { normalizeTheme } from "../utils/themeUtils.js";
|
|
10
11
|
import { useOxy } from "../context/OxyContext.js";
|
|
11
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
const DEFAULT_PRIVACY_SETTINGS = {
|
|
14
|
+
isPrivateAccount: false,
|
|
15
|
+
hideOnlineStatus: false,
|
|
16
|
+
hideLastSeen: false,
|
|
17
|
+
profileVisibility: true,
|
|
18
|
+
loginAlerts: true,
|
|
19
|
+
blockScreenshots: false,
|
|
20
|
+
login: true,
|
|
21
|
+
biometricLogin: false,
|
|
22
|
+
showActivity: true,
|
|
23
|
+
allowTagging: true,
|
|
24
|
+
allowMentions: true,
|
|
25
|
+
hideReadReceipts: false,
|
|
26
|
+
allowDirectMessages: true,
|
|
27
|
+
dataSharing: true,
|
|
28
|
+
locationSharing: false,
|
|
29
|
+
analyticsSharing: true,
|
|
30
|
+
sensitiveContent: false,
|
|
31
|
+
autoFilter: true,
|
|
32
|
+
muteKeywords: false
|
|
33
|
+
};
|
|
12
34
|
const PrivacySettingsScreen = ({
|
|
13
35
|
onClose,
|
|
14
36
|
theme,
|
|
15
37
|
goBack
|
|
16
38
|
}) => {
|
|
17
|
-
// Use useOxy() hook for OxyContext values
|
|
18
39
|
const {
|
|
19
40
|
oxyServices,
|
|
20
41
|
user
|
|
@@ -22,34 +43,30 @@ const PrivacySettingsScreen = ({
|
|
|
22
43
|
const {
|
|
23
44
|
t
|
|
24
45
|
} = useI18n();
|
|
25
|
-
const [settings, setSettings] = useState({
|
|
26
|
-
isPrivateAccount: false,
|
|
27
|
-
hideOnlineStatus: false,
|
|
28
|
-
hideLastSeen: false,
|
|
29
|
-
profileVisibility: true,
|
|
30
|
-
loginAlerts: true,
|
|
31
|
-
blockScreenshots: false,
|
|
32
|
-
login: true,
|
|
33
|
-
biometricLogin: false,
|
|
34
|
-
showActivity: true,
|
|
35
|
-
allowTagging: true,
|
|
36
|
-
allowMentions: true,
|
|
37
|
-
hideReadReceipts: false,
|
|
38
|
-
allowDirectMessages: true,
|
|
39
|
-
dataSharing: true,
|
|
40
|
-
locationSharing: false,
|
|
41
|
-
analyticsSharing: true,
|
|
42
|
-
sensitiveContent: false,
|
|
43
|
-
autoFilter: true,
|
|
44
|
-
muteKeywords: false
|
|
45
|
-
});
|
|
46
46
|
const [isLoading, setIsLoading] = useState(true);
|
|
47
|
-
const [isSaving, setIsSaving] = useState(false);
|
|
48
47
|
const [blockedUsers, setBlockedUsers] = useState([]);
|
|
49
48
|
const [restrictedUsers, setRestrictedUsers] = useState([]);
|
|
50
49
|
const [isLoadingUsers, setIsLoadingUsers] = useState(false);
|
|
51
50
|
|
|
52
|
-
//
|
|
51
|
+
// Use the existing useSettingToggles hook for toggle management
|
|
52
|
+
const {
|
|
53
|
+
values: settings,
|
|
54
|
+
toggle,
|
|
55
|
+
savingKeys,
|
|
56
|
+
setValues
|
|
57
|
+
} = useSettingToggles({
|
|
58
|
+
initialValues: DEFAULT_PRIVACY_SETTINGS,
|
|
59
|
+
onSave: async (key, value) => {
|
|
60
|
+
if (!user?.id || !oxyServices) return;
|
|
61
|
+
await oxyServices.updatePrivacySettings({
|
|
62
|
+
[key]: value
|
|
63
|
+
}, user.id);
|
|
64
|
+
},
|
|
65
|
+
errorMessage: t('privacySettings.updateError') || 'Failed to update privacy setting'
|
|
66
|
+
});
|
|
67
|
+
const isSaving = savingKeys.size > 0;
|
|
68
|
+
|
|
69
|
+
// Load settings
|
|
53
70
|
useEffect(() => {
|
|
54
71
|
const loadSettings = async () => {
|
|
55
72
|
try {
|
|
@@ -57,7 +74,7 @@ const PrivacySettingsScreen = ({
|
|
|
57
74
|
if (user?.id && oxyServices) {
|
|
58
75
|
const privacySettings = await oxyServices.getPrivacySettings(user.id);
|
|
59
76
|
if (privacySettings) {
|
|
60
|
-
|
|
77
|
+
setValues(privacySettings);
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
80
|
} catch (error) {
|
|
@@ -68,7 +85,7 @@ const PrivacySettingsScreen = ({
|
|
|
68
85
|
}
|
|
69
86
|
};
|
|
70
87
|
loadSettings();
|
|
71
|
-
}, [user?.id, oxyServices, t]);
|
|
88
|
+
}, [user?.id, oxyServices, t, setValues]);
|
|
72
89
|
|
|
73
90
|
// Load blocked and restricted users
|
|
74
91
|
useEffect(() => {
|
|
@@ -87,29 +104,6 @@ const PrivacySettingsScreen = ({
|
|
|
87
104
|
};
|
|
88
105
|
loadUsers();
|
|
89
106
|
}, [oxyServices]);
|
|
90
|
-
const updateSetting = useCallback(async (key, value) => {
|
|
91
|
-
try {
|
|
92
|
-
setIsSaving(true);
|
|
93
|
-
const newSettings = {
|
|
94
|
-
...settings,
|
|
95
|
-
[key]: value
|
|
96
|
-
};
|
|
97
|
-
setSettings(newSettings);
|
|
98
|
-
if (user?.id && oxyServices) {
|
|
99
|
-
await oxyServices.updatePrivacySettings({
|
|
100
|
-
[key]: value
|
|
101
|
-
}, user.id);
|
|
102
|
-
toast.success(t('privacySettings.updated') || 'Privacy settings updated');
|
|
103
|
-
}
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error(`Failed to update ${key}:`, error);
|
|
106
|
-
toast.error(t('privacySettings.updateError') || 'Failed to update privacy setting');
|
|
107
|
-
// Revert on error
|
|
108
|
-
setSettings(settings);
|
|
109
|
-
} finally {
|
|
110
|
-
setIsSaving(false);
|
|
111
|
-
}
|
|
112
|
-
}, [settings, user?.id, oxyServices, t]);
|
|
113
107
|
const handleUnblock = useCallback(async userId => {
|
|
114
108
|
if (!oxyServices) return;
|
|
115
109
|
try {
|
|
@@ -269,7 +263,7 @@ const PrivacySettingsScreen = ({
|
|
|
269
263
|
title: t('privacySettings.isPrivateAccount') || 'Private Account',
|
|
270
264
|
description: t('privacySettings.isPrivateAccountDesc') || 'Only approved followers can see your posts',
|
|
271
265
|
value: settings.isPrivateAccount,
|
|
272
|
-
onValueChange:
|
|
266
|
+
onValueChange: () => toggle('isPrivateAccount'),
|
|
273
267
|
disabled: isSaving,
|
|
274
268
|
textColor: themeStyles.textColor,
|
|
275
269
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -278,7 +272,7 @@ const PrivacySettingsScreen = ({
|
|
|
278
272
|
title: t('privacySettings.profileVisibility') || 'Profile Visibility',
|
|
279
273
|
description: t('privacySettings.profileVisibilityDesc') || 'Control who can view your profile',
|
|
280
274
|
value: settings.profileVisibility,
|
|
281
|
-
onValueChange:
|
|
275
|
+
onValueChange: () => toggle('profileVisibility'),
|
|
282
276
|
disabled: isSaving,
|
|
283
277
|
textColor: themeStyles.textColor,
|
|
284
278
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -287,7 +281,7 @@ const PrivacySettingsScreen = ({
|
|
|
287
281
|
title: t('privacySettings.hideOnlineStatus') || 'Hide Online Status',
|
|
288
282
|
description: t('privacySettings.hideOnlineStatusDesc') || 'Don\'t show when you\'re online',
|
|
289
283
|
value: settings.hideOnlineStatus,
|
|
290
|
-
onValueChange:
|
|
284
|
+
onValueChange: () => toggle('hideOnlineStatus'),
|
|
291
285
|
disabled: isSaving,
|
|
292
286
|
textColor: themeStyles.textColor,
|
|
293
287
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -296,7 +290,7 @@ const PrivacySettingsScreen = ({
|
|
|
296
290
|
title: t('privacySettings.hideLastSeen') || 'Hide Last Seen',
|
|
297
291
|
description: t('privacySettings.hideLastSeenDesc') || 'Don\'t show when you were last active',
|
|
298
292
|
value: settings.hideLastSeen,
|
|
299
|
-
onValueChange:
|
|
293
|
+
onValueChange: () => toggle('hideLastSeen'),
|
|
300
294
|
disabled: isSaving,
|
|
301
295
|
textColor: themeStyles.textColor,
|
|
302
296
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -308,7 +302,7 @@ const PrivacySettingsScreen = ({
|
|
|
308
302
|
title: t('privacySettings.allowTagging') || 'Allow Tagging',
|
|
309
303
|
description: t('privacySettings.allowTaggingDesc') || 'Let others tag you in posts',
|
|
310
304
|
value: settings.allowTagging,
|
|
311
|
-
onValueChange:
|
|
305
|
+
onValueChange: () => toggle('allowTagging'),
|
|
312
306
|
disabled: isSaving,
|
|
313
307
|
textColor: themeStyles.textColor,
|
|
314
308
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -317,7 +311,7 @@ const PrivacySettingsScreen = ({
|
|
|
317
311
|
title: t('privacySettings.allowMentions') || 'Allow Mentions',
|
|
318
312
|
description: t('privacySettings.allowMentionsDesc') || 'Let others mention you',
|
|
319
313
|
value: settings.allowMentions,
|
|
320
|
-
onValueChange:
|
|
314
|
+
onValueChange: () => toggle('allowMentions'),
|
|
321
315
|
disabled: isSaving,
|
|
322
316
|
textColor: themeStyles.textColor,
|
|
323
317
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -326,7 +320,7 @@ const PrivacySettingsScreen = ({
|
|
|
326
320
|
title: t('privacySettings.allowDirectMessages') || 'Allow Direct Messages',
|
|
327
321
|
description: t('privacySettings.allowDirectMessagesDesc') || 'Let others send you direct messages',
|
|
328
322
|
value: settings.allowDirectMessages,
|
|
329
|
-
onValueChange:
|
|
323
|
+
onValueChange: () => toggle('allowDirectMessages'),
|
|
330
324
|
disabled: isSaving,
|
|
331
325
|
textColor: themeStyles.textColor,
|
|
332
326
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -335,7 +329,7 @@ const PrivacySettingsScreen = ({
|
|
|
335
329
|
title: t('privacySettings.hideReadReceipts') || 'Hide Read Receipts',
|
|
336
330
|
description: t('privacySettings.hideReadReceiptsDesc') || 'Don\'t show read receipts in messages',
|
|
337
331
|
value: settings.hideReadReceipts,
|
|
338
|
-
onValueChange:
|
|
332
|
+
onValueChange: () => toggle('hideReadReceipts'),
|
|
339
333
|
disabled: isSaving,
|
|
340
334
|
textColor: themeStyles.textColor,
|
|
341
335
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -347,7 +341,7 @@ const PrivacySettingsScreen = ({
|
|
|
347
341
|
title: t('privacySettings.showActivity') || 'Show Activity Status',
|
|
348
342
|
description: t('privacySettings.showActivityDesc') || 'Display your activity on your profile',
|
|
349
343
|
value: settings.showActivity,
|
|
350
|
-
onValueChange:
|
|
344
|
+
onValueChange: () => toggle('showActivity'),
|
|
351
345
|
disabled: isSaving,
|
|
352
346
|
textColor: themeStyles.textColor,
|
|
353
347
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -356,7 +350,7 @@ const PrivacySettingsScreen = ({
|
|
|
356
350
|
title: t('privacySettings.dataSharing') || 'Data Sharing',
|
|
357
351
|
description: t('privacySettings.dataSharingDesc') || 'Allow sharing data for personalization',
|
|
358
352
|
value: settings.dataSharing,
|
|
359
|
-
onValueChange:
|
|
353
|
+
onValueChange: () => toggle('dataSharing'),
|
|
360
354
|
disabled: isSaving,
|
|
361
355
|
textColor: themeStyles.textColor,
|
|
362
356
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -365,7 +359,7 @@ const PrivacySettingsScreen = ({
|
|
|
365
359
|
title: t('privacySettings.locationSharing') || 'Location Sharing',
|
|
366
360
|
description: t('privacySettings.locationSharingDesc') || 'Share your location',
|
|
367
361
|
value: settings.locationSharing,
|
|
368
|
-
onValueChange:
|
|
362
|
+
onValueChange: () => toggle('locationSharing'),
|
|
369
363
|
disabled: isSaving,
|
|
370
364
|
textColor: themeStyles.textColor,
|
|
371
365
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -374,7 +368,7 @@ const PrivacySettingsScreen = ({
|
|
|
374
368
|
title: t('privacySettings.analyticsSharing') || 'Analytics Sharing',
|
|
375
369
|
description: t('privacySettings.analyticsSharingDesc') || 'Allow analytics data collection',
|
|
376
370
|
value: settings.analyticsSharing,
|
|
377
|
-
onValueChange:
|
|
371
|
+
onValueChange: () => toggle('analyticsSharing'),
|
|
378
372
|
disabled: isSaving,
|
|
379
373
|
textColor: themeStyles.textColor,
|
|
380
374
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -386,7 +380,7 @@ const PrivacySettingsScreen = ({
|
|
|
386
380
|
title: t('privacySettings.sensitiveContent') || 'Show Sensitive Content',
|
|
387
381
|
description: t('privacySettings.sensitiveContentDesc') || 'Allow sensitive or explicit content',
|
|
388
382
|
value: settings.sensitiveContent,
|
|
389
|
-
onValueChange:
|
|
383
|
+
onValueChange: () => toggle('sensitiveContent'),
|
|
390
384
|
disabled: isSaving,
|
|
391
385
|
textColor: themeStyles.textColor,
|
|
392
386
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -395,7 +389,7 @@ const PrivacySettingsScreen = ({
|
|
|
395
389
|
title: t('privacySettings.autoFilter') || 'Auto Filter',
|
|
396
390
|
description: t('privacySettings.autoFilterDesc') || 'Automatically filter inappropriate content',
|
|
397
391
|
value: settings.autoFilter,
|
|
398
|
-
onValueChange:
|
|
392
|
+
onValueChange: () => toggle('autoFilter'),
|
|
399
393
|
disabled: isSaving,
|
|
400
394
|
textColor: themeStyles.textColor,
|
|
401
395
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -404,7 +398,7 @@ const PrivacySettingsScreen = ({
|
|
|
404
398
|
title: t('privacySettings.muteKeywords') || 'Mute Keywords',
|
|
405
399
|
description: t('privacySettings.muteKeywordsDesc') || 'Hide posts containing muted keywords',
|
|
406
400
|
value: settings.muteKeywords,
|
|
407
|
-
onValueChange:
|
|
401
|
+
onValueChange: () => toggle('muteKeywords'),
|
|
408
402
|
disabled: isSaving,
|
|
409
403
|
textColor: themeStyles.textColor,
|
|
410
404
|
mutedTextColor: themeStyles.mutedTextColor,
|
|
@@ -413,7 +407,7 @@ const PrivacySettingsScreen = ({
|
|
|
413
407
|
title: t('privacySettings.blockScreenshots') || 'Block Screenshots',
|
|
414
408
|
description: t('privacySettings.blockScreenshotsDesc') || 'Prevent screenshots of your content',
|
|
415
409
|
value: settings.blockScreenshots,
|
|
416
|
-
onValueChange:
|
|
410
|
+
onValueChange: () => toggle('blockScreenshots'),
|
|
417
411
|
disabled: isSaving,
|
|
418
412
|
textColor: themeStyles.textColor,
|
|
419
413
|
mutedTextColor: themeStyles.mutedTextColor,
|