diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx new file mode 100644 index 0000000..1d03264 --- /dev/null +++ b/src/components/app/app.tsx @@ -0,0 +1,63 @@ +import { useMemo } from 'react'; +import { useShallow } from 'zustand/react/shallow'; +import { BiSolidHeart } from 'react-icons/bi/index'; + +import { useSoundStore } from '@/store'; + +import { Container } from '@/components/container'; +import { StoreConsumer } from '@/components/store-consumer'; +import { Buttons } from '@/components/buttons'; +import { Categories } from '@/components/categories'; + +import { sounds } from '@/data/sounds'; + +interface Sound { + src: string; + label: string; + id: string; + icon: React.ReactNode; +} + +export function App() { + const categories = useMemo(() => sounds.categories, []); + + const favorites = useSoundStore(useShallow(state => state.getFavorites())); + + const favoriteSounds = useMemo(() => { + const favoriteSounds = categories + .map(category => category.sounds) + .flat() + .filter(sound => favorites.includes(sound.id)); + + /** + * Reorder based on the order of favorites + */ + return favorites.map(favorite => + favoriteSounds.find(sound => sound.id === favorite), + ); + }, [favorites, categories]); + + const allCategories = useMemo(() => { + const favorites = []; + + if (favoriteSounds.length) { + favorites.push({ + icon: , + id: 'favorites', + sounds: favoriteSounds as Array, + title: 'Favorites', + }); + } + + return [...favorites, ...categories]; + }, [favoriteSounds, categories]); + + return ( + + + + + + + ); +} diff --git a/src/components/app/index.ts b/src/components/app/index.ts new file mode 100644 index 0000000..e657810 --- /dev/null +++ b/src/components/app/index.ts @@ -0,0 +1 @@ +export { App } from './app'; diff --git a/src/components/categories/categories.tsx b/src/components/categories/categories.tsx index e36d683..c1b4ce7 100644 --- a/src/components/categories/categories.tsx +++ b/src/components/categories/categories.tsx @@ -1,65 +1,31 @@ -import { useMemo } from 'react'; -import { useShallow } from 'zustand/react/shallow'; -import { BiSolidHeart } from 'react-icons/bi/index'; import { AnimatePresence } from 'framer-motion'; -import { useSoundStore } from '@/store'; - -import { Container } from '@/components/container'; -import { StoreConsumer } from '../store-consumer'; import { Category } from '@/components/category'; -import { Buttons } from '@/components/buttons'; -import { sounds } from '@/data/sounds'; - -export function Categories() { - const categories = useMemo(() => sounds.categories, []); - - const favorites = useSoundStore(useShallow(state => state.getFavorites())); - - const favoriteSounds = useMemo(() => { - const favoriteSounds = categories - .map(category => category.sounds) - .flat() - .filter(sound => favorites.includes(sound.id)); - - /** - * Reorder based on the order of favorites - */ - return favorites.map(favorite => - favoriteSounds.find(sound => sound.id === favorite), - ); - }, [favorites, categories]); +interface CategoriesProps { + categories: Array<{ + id: string; + title: string; + icon: React.ReactNode; + sounds: Array<{ + label: string; + src: string; + icon: React.ReactNode; + id: string; + }>; + }>; +} +export function Categories({ categories }: CategoriesProps) { return ( - - - -
- - {!!favoriteSounds.length && ( - } - id="favorites" - title="Favorites" - sounds={ - favoriteSounds as Array<{ - src: string; - label: string; - id: string; - icon: React.ReactNode; - }> - } - /> - )} - - {categories.map(category => ( - - ))} - -
-
-
+ + {categories.map(category => ( + + ))} + ); } diff --git a/src/pages/index.astro b/src/pages/index.astro index 154067e..a80c9b8 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -2,13 +2,13 @@ import Layout from '@/layouts/layout.astro'; import { Hero } from '@/components/hero'; -import { Categories } from '@/components/categories'; +import { App } from '@/components/app'; ---
- +