UNPKG

@oxyhq/services

Version:

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

414 lines (408 loc) 15.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _fonts = require("../styles/fonts.js"); var _core = require("@oxyhq/core"); var _sonner = require("../../lib/sonner"); var _vectorIcons = require("@expo/vector-icons"); var _OxyServices = _interopRequireDefault(require("../../assets/icons/OxyServices.js")); var _index = require("../components/index.js"); var _useThemeStyles = require("../hooks/useThemeStyles.js"); var _useColorScheme = require("../hooks/useColorScheme.js"); var _OxyContext = require("../context/OxyContext.js"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const AppInfoScreen = ({ onClose, theme, navigate }) => { // Use useOxy() hook for OxyContext values const { user, sessions, oxyServices, isAuthenticated } = (0, _OxyContext.useOxy)(); const [systemInfo, setSystemInfo] = (0, _react.useState)(null); const [isRunningSystemCheck, setIsRunningSystemCheck] = (0, _react.useState)(false); const [connectionStatus, setConnectionStatus] = (0, _react.useState)('unknown'); const colorScheme = (0, _useColorScheme.useColorScheme)(); const themeStyles = (0, _useThemeStyles.useThemeStyles)(theme || 'light', colorScheme); // AppInfoScreen uses a slightly different light background const backgroundColor = themeStyles.isDarkTheme ? themeStyles.backgroundColor : '#f2f2f2'; const primaryColor = themeStyles.colors.iconSecurity; (0, _react.useEffect)(() => { const updateDimensions = () => { const dimensions = _reactNative.Dimensions.get('window'); setSystemInfo(prev => ({ ...prev, platform: _reactNative.Platform.OS, version: _reactNative.Platform.Version?.toString() || 'Unknown', screenDimensions: { width: dimensions.width, height: dimensions.height }, timestamp: new Date().toISOString() })); }; // Set initial dimensions updateDimensions(); // Listen for dimension changes const subscription = _reactNative.Dimensions.addEventListener('change', updateDimensions); // Check API connection on mount const checkConnection = async () => { setConnectionStatus('checking'); if (!oxyServices) { setConnectionStatus('disconnected'); return; } try { await oxyServices.healthCheck(); setConnectionStatus('connected'); } catch (error) { setConnectionStatus('disconnected'); } }; checkConnection(); // Cleanup listener on unmount return () => { subscription?.remove(); }; }, [oxyServices]); const copyToClipboard = async (text, label) => { try { await _reactNative.Clipboard.setString(text); _sonner.toast.success(`${label} copied to clipboard`); } catch (error) { _sonner.toast.error('Failed to copy to clipboard'); } }; const runSystemCheck = async () => { setIsRunningSystemCheck(true); try { // Simulate system check await new Promise(resolve => setTimeout(resolve, 2000)); // Check API connection if (oxyServices) { try { await oxyServices.healthCheck(); setConnectionStatus('connected'); } catch (error) { setConnectionStatus('disconnected'); } } _sonner.toast.success('System check completed successfully'); } catch (error) { _sonner.toast.error('System check failed'); } finally { setIsRunningSystemCheck(false); } }; const generateFullReport = () => { const report = { package: _core.packageInfo, system: systemInfo, user: user ? { id: user.id, username: user.username, email: user.email, isPremium: user.isPremium } : null, sessions: sessions?.length || 0, connection: connectionStatus, timestamp: new Date().toISOString() }; return JSON.stringify(report, null, 2); }; const handleCopyFullReport = () => { const report = generateFullReport(); copyToClipboard(report, 'Full system report'); }; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.header, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: styles.cancelButton, onPress: onClose, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "close", size: 24, color: "#666" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.headerTitle, children: "App Information" }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.placeholder })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, { style: styles.content, showsVerticalScrollIndicator: false, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "Package Information", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'name', icon: 'information', iconColor: themeStyles.colors.iconSecurity, title: 'Name', subtitle: _core.packageInfo.name, onPress: () => copyToClipboard(_core.packageInfo.name, 'Package name'), customContent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_OxyServices.default, { width: 20, height: 20, style: styles.settingIcon }) }, { id: 'version', icon: 'tag', iconColor: themeStyles.colors.iconData, title: 'Version', subtitle: _core.packageInfo.version, onPress: () => copyToClipboard(_core.packageInfo.version, 'Version') }, { id: 'description', icon: 'file-document', iconColor: themeStyles.colors.iconPersonalInfo, title: 'Description', subtitle: _core.packageInfo.description || 'No description' }, { id: 'main-entry', icon: 'code-tags', iconColor: themeStyles.colors.iconStorage, title: 'Main Entry', subtitle: _core.packageInfo.main || 'N/A', onPress: () => copyToClipboard(_core.packageInfo.main || 'N/A', 'Main entry') }, { id: 'module-entry', icon: 'library', iconColor: themeStyles.colors.iconSharing, title: 'Module Entry', subtitle: _core.packageInfo.module || 'N/A', onPress: () => copyToClipboard(_core.packageInfo.module || 'N/A', 'Module entry') }, { id: 'types-entry', icon: 'wrench', iconColor: themeStyles.colors.iconPersonalInfo, title: 'Types Entry', subtitle: _core.packageInfo.types || 'N/A', onPress: () => copyToClipboard(_core.packageInfo.types || 'N/A', 'Types entry') }] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "System Information", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'platform', icon: 'cellphone', iconColor: themeStyles.colors.iconSecurity, title: 'Platform', subtitle: _reactNative.Platform.OS }, { id: 'platform-version', icon: 'chip', iconColor: themeStyles.colors.iconData, title: 'Platform Version', subtitle: systemInfo?.version || 'Loading...' }, { id: 'screen-width', icon: 'resize', iconColor: themeStyles.colors.iconStorage, title: 'Screen Width', subtitle: `${systemInfo?.screenDimensions.width || 0}px` }, { id: 'screen-height', icon: 'resize', iconColor: themeStyles.colors.iconSharing, title: 'Screen Height', subtitle: `${systemInfo?.screenDimensions.height || 0}px` }, { id: 'environment', icon: 'cog', iconColor: themeStyles.colors.iconPersonalInfo, title: 'Environment', subtitle: __DEV__ ? 'Development' : 'Production' }] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "User Information", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'auth-status', icon: 'shield-check', iconColor: isAuthenticated ? themeStyles.colors.iconPersonalInfo : themeStyles.colors.iconSharing, title: 'Authentication Status', subtitle: isAuthenticated ? 'Authenticated' : 'Not Authenticated' }, ...(user ? [{ id: 'user-id', icon: 'account', iconColor: themeStyles.colors.iconSecurity, title: 'User ID', subtitle: user.id, onPress: () => copyToClipboard(user.id, 'User ID') }, { id: 'username', icon: 'at', iconColor: themeStyles.colors.iconData, title: 'Username', subtitle: user.username || 'N/A', onPress: () => { if (user?.username && navigate) { navigate('Profile', { userId: user.id }); } else { _sonner.toast.info('No username available or navigation not supported'); } } }, { id: 'email', icon: 'mail', iconColor: themeStyles.colors.iconStorage, title: 'Email', subtitle: user.email || 'N/A' }, { id: 'premium-status', icon: 'star', iconColor: user.isPremium ? '#FFD700' : '#8E8E93', title: 'Premium Status', subtitle: user.isPremium ? 'Premium' : 'Standard' }] : []), { id: 'active-sessions', icon: 'account-group', iconColor: themeStyles.colors.iconPersonalInfo, title: 'Total Active Sessions', subtitle: sessions?.length?.toString() || '0' }] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "API Configuration", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'api-base-url', icon: 'server', iconColor: themeStyles.colors.iconSecurity, title: 'API Base URL', subtitle: oxyServices?.getBaseURL() || 'Not configured', onPress: () => copyToClipboard(oxyServices?.getBaseURL() || 'Not configured', 'API Base URL') }, { id: 'connection-status', icon: connectionStatus === 'checking' ? 'sync' : connectionStatus === 'connected' ? 'wifi' : 'wifi-off', iconColor: connectionStatus === 'checking' ? themeStyles.colors.iconStorage : connectionStatus === 'connected' ? themeStyles.colors.iconPersonalInfo : themeStyles.colors.iconSharing, title: 'Connection Status', subtitle: connectionStatus === 'checking' ? 'Checking...' : connectionStatus === 'connected' ? 'Connected' : connectionStatus === 'disconnected' ? 'Disconnected' : 'Unknown', onPress: async () => { setConnectionStatus('checking'); if (!oxyServices) { setConnectionStatus('disconnected'); _sonner.toast.error('OxyServices not initialized'); return; } try { await oxyServices.healthCheck(); setConnectionStatus('connected'); _sonner.toast.success('API connection successful'); } catch (error) { setConnectionStatus('disconnected'); _sonner.toast.error('Failed to connect to API server'); } } }] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "Build Information", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'build-timestamp', icon: 'clock', iconColor: themeStyles.colors.iconSecurity, title: 'Build Timestamp', subtitle: systemInfo?.timestamp || 'Loading...', onPress: () => copyToClipboard(systemInfo?.timestamp || 'Loading...', 'Build timestamp') }, { id: 'react-native', icon: 'react', iconColor: '#61DAFB', title: 'React Native', subtitle: 'Expo/React Native' }, { id: 'js-engine', icon: 'flash', iconColor: themeStyles.colors.iconSharing, title: 'JavaScript Engine', subtitle: 'Hermes' }] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Section, { title: "Quick Actions", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.GroupedSection, { items: [{ id: 'copy-full-report', icon: 'content-copy', iconColor: themeStyles.colors.iconSecurity, title: 'Copy Full Report', subtitle: 'Copy complete application information to clipboard', onPress: handleCopyFullReport }, { id: 'run-system-check', icon: isRunningSystemCheck ? 'sync' : 'check-circle', iconColor: isRunningSystemCheck ? '#FF9500' : '#34C759', title: isRunningSystemCheck ? 'Running System Check...' : 'Run System Check', subtitle: isRunningSystemCheck ? 'Checking API, authentication, and platform status...' : 'Verify application health and status', onPress: runSystemCheck, disabled: isRunningSystemCheck, customContent: isRunningSystemCheck ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { color: "#FF9500", size: "small", style: { marginRight: 16 } }) : null }] }) })] })] }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16, paddingVertical: 12, backgroundColor: '#fff' }, cancelButton: { padding: 5 }, headerTitle: { fontSize: 24, fontWeight: 'bold', color: '#000', fontFamily: _fonts.fontFamilies.interBold }, placeholder: { width: 34 // Same width as cancel button to center title }, content: { flex: 1, padding: 16 }, settingIcon: { marginRight: 12 } }); var _default = exports.default = AppInfoScreen; //# sourceMappingURL=AppInfoScreen.js.map