@oxyhq/services
Version:
Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀
205 lines (203 loc) • 7.64 kB
JavaScript
"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 SavesCollectionsScreen = ({
onClose,
theme,
goBack
}) => {
const {
oxyServices,
user
} = (0, _OxyContext.useOxy)();
const {
t
} = (0, _useI18n.useI18n)();
const [savedItems, setSavedItems] = (0, _react.useState)([]);
const [collections, setCollections] = (0, _react.useState)([]);
const [isLoading, setIsLoading] = (0, _react.useState)(true);
const [activeTab, setActiveTab] = (0, _react.useState)('saves');
// Load saved items and collections
(0, _react.useEffect)(() => {
const loadData = async () => {
try {
setIsLoading(true);
if (user?.id && oxyServices) {
setSavedItems([]);
setCollections([]);
}
} catch (error) {
_sonner.toast.error(t('saves.loadError') || 'Failed to load saved items');
} finally {
setIsLoading(false);
}
};
loadData();
}, [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',
tabActiveColor: '#007AFF',
tabInactiveColor: isDarkTheme ? '#888888' : '#666666'
};
}, [theme]);
const formatDate = date => {
return date.toLocaleDateString();
};
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
style: [styles.container, {
backgroundColor: themeStyles.backgroundColor
}],
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Header, {
title: t('saves.title') || 'Saves & Collections',
theme: theme,
onBack: goBack || onClose,
variant: "minimal",
elevation: "subtle"
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
style: [styles.tabs, {
borderBottomColor: themeStyles.borderColor
}],
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
style: [styles.tab, activeTab === 'saves' && {
borderBottomColor: themeStyles.tabActiveColor
}],
onPress: () => setActiveTab('saves'),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.tabText, {
color: activeTab === 'saves' ? themeStyles.tabActiveColor : themeStyles.tabInactiveColor,
fontWeight: activeTab === 'saves' ? '600' : '400'
}],
children: t('saves.tabs.saves') || 'Saves'
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
style: [styles.tab, activeTab === 'collections' && {
borderBottomColor: themeStyles.tabActiveColor
}],
onPress: () => setActiveTab('collections'),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.tabText, {
color: activeTab === 'collections' ? themeStyles.tabActiveColor : themeStyles.tabInactiveColor,
fontWeight: activeTab === 'collections' ? '600' : '400'
}],
children: t('saves.tabs.collections') || 'Collections'
})
})]
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
style: styles.content,
children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
style: styles.loadingContainer,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
size: "large",
color: themeStyles.textColor
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.loadingText, {
color: themeStyles.textColor
}],
children: t('saves.loading') || 'Loading...'
})]
}) : activeTab === 'saves' ? savedItems.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: styles.emptyContainer,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.emptyText, {
color: themeStyles.textColor
}],
children: t('saves.empty') || 'No saved items yet'
})
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Section, {
title: t('saves.savedItems') || 'Saved Items',
theme: theme,
isFirst: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.GroupedSection, {
items: savedItems.map(item => ({
id: item.id,
icon: item.type === 'post' ? 'document-text' : 'folder',
iconColor: item.type === 'post' ? '#007AFF' : '#FF9500',
title: item.title,
subtitle: formatDate(item.savedAt)
})),
theme: theme
})
}) : collections.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: styles.emptyContainer,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.emptyText, {
color: themeStyles.textColor
}],
children: t('saves.noCollections') || 'No collections yet'
})
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Section, {
title: t('saves.collections') || 'Collections',
theme: theme,
isFirst: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.GroupedSection, {
items: collections.map(collection => ({
id: collection.id,
icon: 'folder',
iconColor: '#FF9500',
title: collection.name,
subtitle: `${collection.itemCount || 0} items`
})),
theme: theme
})
})
})]
});
};
const styles = _reactNative.StyleSheet.create({
container: {
flex: 1
},
tabs: {
flexDirection: 'row',
borderBottomWidth: 1
},
tab: {
flex: 1,
paddingVertical: 16,
alignItems: 'center',
borderBottomWidth: 2,
borderBottomColor: 'transparent'
},
tabText: {
fontSize: 16
},
content: {
flex: 1,
padding: 16
},
loadingContainer: {
padding: 40,
alignItems: 'center',
justifyContent: 'center'
},
loadingText: {
marginTop: 12,
fontSize: 16
},
emptyContainer: {
padding: 40,
alignItems: 'center',
justifyContent: 'center'
},
emptyText: {
fontSize: 16,
textAlign: 'center'
}
});
var _default = exports.default = /*#__PURE__*/_react.default.memo(SavesCollectionsScreen);
//# sourceMappingURL=SavesCollectionsScreen.js.map