diff --git a/src/features/marketplace/components/Elements/ItemUtilities/ItemUtilities.jsx b/src/features/marketplace/components/Elements/ItemUtilities/ItemUtilities.jsx new file mode 100644 index 00000000..54706dcb --- /dev/null +++ b/src/features/marketplace/components/Elements/ItemUtilities/ItemUtilities.jsx @@ -0,0 +1,85 @@ +// src/components/ItemUtilities/ItemUtilities.js +import React, { useCallback, useMemo } from 'react'; +import { motion } from 'framer-motion'; +import { PiGridFourFill } from 'react-icons/pi'; +import { MdFormatListBulleted } from 'react-icons/md'; +import clsx from 'clsx'; +import variables from 'config/variables'; + +const filterTypes = [ + { key: 'all', label: 'marketplace:photo_packs' }, + { key: 'photo_packs', label: 'marketplace:photo_packs' }, + { key: 'quote_packs', label: 'marketplace:quote_packs' }, + { key: 'preset_settings', label: 'marketplace:preset_settings' }, +]; + +const ItemUtilities = ({ itemsFilter, setItemsFilter, itemsView, setItemsView }) => { + const FilterOptions = useCallback(() => { + return ( +
+ {filterTypes.map(({ key, label }) => ( +
setItemsFilter(key)} + className={clsx( + 'cursor-pointer transition-all duration-200 rounded-full px-6 py-2 text-base', + { + 'bg-white text-black': itemsFilter === key, + 'bg-[#333] hover:bg-[#222222] text-white': itemsFilter !== key, + }, + )} + > + {key !== 'all' ? <>{variables.getMessage(`${label}`) || 'marketplace'} : <>All} +
+ ))} +
+ ); + }, [itemsFilter]); + + const viewOptions = useMemo( + () => [ + { id: 'grid', icon: }, + { id: 'list', icon: }, + ], + [], + ); + + const ItemView = useCallback(() => { + return ( +
+ {viewOptions.map((option) => ( + + ))} +
+ ); + }, [itemsView, setItemsView, viewOptions]); + + return ( +
+ {itemsFilter && } +
+ +
+
+ ); +}; + +export { ItemUtilities as default, ItemUtilities }; diff --git a/src/features/marketplace/components/Elements/ItemUtilities/index.jsx b/src/features/marketplace/components/Elements/ItemUtilities/index.jsx new file mode 100644 index 00000000..a07e008f --- /dev/null +++ b/src/features/marketplace/components/Elements/ItemUtilities/index.jsx @@ -0,0 +1 @@ +export * from './ItemUtilities'; \ No newline at end of file diff --git a/src/features/marketplace/components/Elements/index.jsx b/src/features/marketplace/components/Elements/index.jsx index 185686c9..e7cd72e9 100644 --- a/src/features/marketplace/components/Elements/index.jsx +++ b/src/features/marketplace/components/Elements/index.jsx @@ -2,3 +2,4 @@ export * from './Carousel'; export * from './SideloadFailedModal'; export * from './Lightbox'; export * from './ItemCard'; +export * from './ItemUtilities'; \ No newline at end of file diff --git a/src/features/marketplace/views/Library.jsx b/src/features/marketplace/views/Library.jsx index 9ddd70d5..5165c11b 100644 --- a/src/features/marketplace/views/Library.jsx +++ b/src/features/marketplace/views/Library.jsx @@ -1,15 +1,27 @@ -import variables from 'config/variables'; -import { NewItems as Items } from '../components/Items/Items'; +// src/library/Library.js +import React, { useState, useEffect, useCallback, useMemo } from 'react'; import { useMarketData } from 'features/marketplace/api/MarketplaceDataContext'; import { useTab } from 'components/Elements/MainModal/backend/TabContext'; -import { ItemPage } from '../views/ItemPage'; +import { NewItems as Items } from '../components/Items/Items'; +import ItemPage from '../views/ItemPage'; import { MdOutlineExtensionOff } from 'react-icons/md'; +import { ItemUtilities } from '../components/Elements'; +import variables from 'config/variables'; + +const filterItems = (items, filter) => { + if (filter === 'all') return items; + return items.filter((item) => item.type === filter); +}; const Library = () => { let installed = JSON.parse(localStorage.getItem('installed')); const { selectedItem } = useMarketData(); const { subTab, changeTab } = useTab(); + const [itemsView, setItemsView] = useState('list'); + const [itemsFilter, setItemsFilter] = useState('all'); + const [filteredItems, setFilteredItems] = useState([]); + // Ensure installed is an array if (!Array.isArray(installed)) { installed = []; @@ -36,7 +48,17 @@ const Library = () => { return ( <> - {subTab === '' && selectedItem === null && } + {subTab === '' && selectedItem === null && ( + <> + + + + )} {subTab !== '' && selectedItem !== null && } ); diff --git a/src/features/misc/views/Marketplace.jsx b/src/features/misc/views/Marketplace.jsx index 716e47ba..d7af0e82 100644 --- a/src/features/misc/views/Marketplace.jsx +++ b/src/features/misc/views/Marketplace.jsx @@ -1,33 +1,20 @@ -import { memo, useCallback, useEffect, useState, useMemo } from 'react'; -import variables from 'config/variables'; +// src/marketplace/Marketplace.js +import { memo, useEffect, useState, useCallback, useMemo } from 'react'; import { useMarketData } from 'features/marketplace/api/MarketplaceDataContext'; -import MarketplaceTab from '../../marketplace/views/Browse'; import { useTab } from 'components/Elements/MainModal/backend/TabContext'; - -import { ItemPage } from '../../marketplace/views/ItemPage'; -import { CollectionPage } from '../../marketplace/views/CollectionPage'; -import { NewItems as Items } from '../../marketplace/components/Items/Items'; - import { AnimatePresence, motion } from 'framer-motion'; -import Collection from '../../marketplace/components/Collection/Collection'; -import clsx from 'clsx'; - -import { PiGridFourFill } from 'react-icons/pi'; -import { MdFormatListBulleted } from 'react-icons/md'; - -const filterTypes = [ - { key: 'all', label: 'marketplace:photo_packs' }, - { key: 'photo_packs', label: 'marketplace:photo_packs' }, - { key: 'quote_packs', label: 'marketplace:quote_packs' }, - { key: 'preset_settings', label: 'marketplace:preset_settings' }, -]; +import { Collection } from '../../marketplace/components/Collection'; +import { NewItems as Items } from '../../marketplace/components/Items/Items'; +import ItemPage from '../../marketplace/views/ItemPage'; +import CollectionPage from '../../marketplace/views/CollectionPage'; +import { ItemUtilities } from '../../marketplace/components/Elements'; const filterItems = (items, filter) => { if (filter === 'all') return items; return items.filter((item) => item.type === filter); }; -function Marketplace(props) { +function Marketplace() { const { done, items = [], @@ -53,64 +40,6 @@ function Marketplace(props) { } }; - const FilterOptions = useCallback(() => { - return ( -
- {filterTypes.map(({ key, label }) => ( -
setItemsFilter(key)} - className={clsx( - 'cursor-pointer transition-all duration-200 rounded-full px-6 py-2 text-base', - { - 'bg-white text-black': itemsFilter === key, - 'bg-[#333] hover:bg-[#222222] text-white': itemsFilter !== key, - }, - )} - > - {key !== 'all' ? <>{variables.getMessage(`${label}`) || 'marketplace'} : <>All} -
- ))} -
- ); - }, [itemsFilter]); - - const viewOptions = useMemo( - () => [ - { id: 'grid', icon: }, - { id: 'list', icon: }, - ], - [], - ); - - const ItemView = useCallback(() => { - return ( -
- {viewOptions.map((option) => ( - - ))} -
- ); - }, [itemsView, setItemsView, viewOptions]); - useEffect(() => { if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') { return; @@ -135,12 +64,12 @@ function Marketplace(props) { <> -
- -
- -
-
+
@@ -153,24 +82,6 @@ function Marketplace(props) { {selectedCollection !== null && ( )} - {/*{subTab === '' ? ( - <> - - -
- -
- -
-
- -
- - ) : ( - - - - )}*/} );