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 { useStoreState } from 'easy-peasy'; import { usePersistedState } from '@/plugins/usePersistedState'; import Switch from '@/components/elements/Switch'; import tw from 'twin.macro'; import useSWR from 'swr'; import { PaginatedResult } from '@/api/http'; import Pagination from '@/components/elements/Pagination'; export default () => { const { clearFlashes, clearAndAddHttpError } = useFlash(); const [ page, setPage ] = useState(1); const { rootAdmin } = useStoreState(state => state.user.data!); const [ includeAdmin, setIncludeAdmin ] = usePersistedState('show_all_servers', false); const { data: servers, error } = useSWR>( [ '/api/client/servers', includeAdmin, page ], () => getServers({ includeAdmin, page }), ); useEffect(() => { if (error) clearAndAddHttpError({ key: 'dashboard', error }); if (!error) clearFlashes('dashboard'); }, [ error ]); return ( {rootAdmin &&

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

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

There are no servers associated with your account.

)}
}
); };