import React, { useEffect, useState } from 'react'; import { Server } from '@/api/server/getServer'; import getServers from '@/api/getServers'; import ServerRow from '@/components/dashboard/ServerRow'; import Spinner from '@/components/elements/Spinner'; import PageContentBlock from '@/components/elements/PageContentBlock'; import useFlash from '@/plugins/useFlash'; import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; import { useStoreState } from 'easy-peasy'; import { usePersistedState } from '@/plugins/usePersistedState'; import Switch from '@/components/elements/Switch'; import tw from 'twin.macro'; export default () => { const { addError, clearFlashes } = useFlash(); const [ servers, setServers ] = useState([]); const [ loading, setLoading ] = useState(true); const { rootAdmin } = useStoreState(state => state.user.data!); const [ showAdmin, setShowAdmin ] = usePersistedState('show_all_servers', false); const loadServers = () => { clearFlashes(); setLoading(true); getServers(undefined, showAdmin) .then(data => setServers(data.items)) .catch(error => { console.error(error); addError({ message: httpErrorToHuman(error) }); }) .then(() => setLoading(false)); }; useEffect(() => { loadServers(); }, [ showAdmin ]); return ( {rootAdmin &&

{showAdmin ? 'Showing all servers' : 'Showing your servers'}

setShowAdmin(s => !s)} />
} {loading ? : servers.length > 0 ? servers.map((server, index) => (
0 ? tw`mt-2` : undefined}>
)) :

There are no servers associated with your account.

}
); };