import React, { useEffect, useState } from 'react'; import getNests from '@/api/admin/nests/getNests'; import { httpErrorToHuman } from '@/api/http'; import NewNestButton from '@/components/admin/nests/NewNestButton'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { useDeepMemoize } from '@/plugins/useDeepMemoize'; import useFlash from '@/plugins/useFlash'; import { AdminContext } from '@/state/admin'; import { NavLink, useRouteMatch } from 'react-router-dom'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminCheckbox, { TableCheckbox } from '@/components/admin/AdminCheckbox'; const RowCheckbox = ({ id }: { id: number}) => { const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0); const appendSelectedNest = AdminContext.useStoreActions(actions => actions.nests.appendSelectedNest); const removeSelectedNest = AdminContext.useStoreActions(actions => actions.nests.removeSelectedNest); return ( ) => { if (e.currentTarget.checked) { appendSelectedNest(name); } else { removeSelectedNest(name); } }} /> ); }; export default () => { const match = useRouteMatch(); const { addError, clearFlashes } = useFlash(); const [ loading, setLoading ] = useState(true); const nests = useDeepMemoize(AdminContext.useStoreState(state => state.nests.data)); const setNests = AdminContext.useStoreActions(state => state.nests.setNests); const setSelectedNests = AdminContext.useStoreActions(actions => actions.nests.setSelectedNests); const selectedNestsLength = AdminContext.useStoreState(state => state.nests.selectedNests.length); useEffect(() => { setLoading(!nests.length); clearFlashes('nests'); getNests() .then(nests => setNests(nests)) .catch(error => { console.error(error); addError({ message: httpErrorToHuman(error), key: 'nests' }); }) .then(() => setLoading(false)); }, []); const onSelectAllClick = (e: React.ChangeEvent) => { setSelectedNests(e.currentTarget.checked ? (nests?.map(nest => nest.id) || []) : []); }; return (

Nests

All nests currently available on this system.

{ loading ?
: nests.length < 1 ?
{'No

No items could be found, it's almost like they are hiding.

: <>
{/* { nests.map(nest => ( )) }
ID
Name
Description
*/}
{nest.id} {nest.name} {nest.description}

Showing 1 to 10 of 97 results

}
); };