'use client'; import { getSpells } from '@/api/spells'; import { Spell } from '@/api/spells.types'; import SpellModal from '@/components/SpellModal'; import React, { useEffect, useState } from 'react'; import './spells.css'; import { Box, TextInput } from '@mantine/core'; import { AiOutlineVerticalAlignTop } from 'react-icons/ai'; export default function Page() { const [cantrips, setCantrips] = useState([]); const [level1, setLevel1] = useState([]); const [level2, setLevel2] = useState([]); const [level3, setLevel3] = useState([]); const [level4, setLevel4] = useState([]); const [level5, setLevel5] = useState([]); const [level6, setLevel6] = useState([]); const [level7, setLevel7] = useState([]); const [level8, setLevel8] = useState([]); const [level9, setLevel9] = useState([]); const [activeSpell, setActiveSpell] = useState(undefined); const [isOpen, setIsOpen] = useState(false); const [searchName, setSearchName] = useState(''); useEffect(() => { getSpells({ levels: [0] }).then((s) => setCantrips(s.data)); getSpells({ levels: [1] }).then((s) => setLevel1(s.data)); getSpells({ levels: [2] }).then((s) => setLevel2(s.data)); getSpells({ levels: [3] }).then((s) => setLevel3(s.data)); getSpells({ levels: [4] }).then((s) => setLevel4(s.data)); getSpells({ levels: [5] }).then((s) => setLevel5(s.data)); getSpells({ levels: [6] }).then((s) => setLevel6(s.data)); getSpells({ levels: [7] }).then((s) => setLevel7(s.data)); getSpells({ levels: [8] }).then((s) => setLevel8(s.data)); getSpells({ levels: [9] }).then((s) => setLevel9(s.data)); }, []); return (

Spells

setSearchName(e.target.value)} style={{ width: '25%' }} /> s.name.toLowerCase().includes(searchName.toLowerCase()))} onClick={(spell) => { setActiveSpell(spell); setIsOpen(true); }} />
{activeSpell && setIsOpen(false)} />}
); } function SpellSection({ title, spells, onClick }: { title: string; spells: Spell[]; onClick: (spell: Spell) => void }) { const isBrowser = () => typeof window !== 'undefined'; //The approach recommended by Next.js function scrollToTop() { if (!isBrowser()) return; window.scrollTo({ top: 0, behavior: 'smooth' }); } return (

{title}

    {spells.map((spell) => (
  • onClick(spell)} > {spell.name}
  • ))}
Back to top
); }