import { Text, Fieldset, Spacer, Link } from '@geist-ui/core' import getPostPath from '@lib/get-post-path' import { Post, User } from '@lib/types' import Cookies from 'js-cookie' import useSWR from 'swr' import styles from './admin.module.css' const fetcher = (url: string) => fetch(url, { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${Cookies.get('drift-token')}`, } }).then(res => res.json()) const Admin = () => { const { data: posts, error } = useSWR('/server-api/admin/posts', fetcher) const { data: users, error: errorUsers } = useSWR('/server-api/admin/users', fetcher) console.log(posts, error) return (
Administration
Users {users && {users.length} users} {!users && Loading...} {users && {users?.map(user => ( ))}
Username Posts Created Role
{user.username} {user.posts?.length} {new Date(user.createdAt).toLocaleDateString()} {new Date(user.createdAt).toLocaleTimeString()} {user.role}
}
Posts {posts && {posts.length} posts} {!posts && Loading...} {posts && {posts?.map(post => ( ))}
Title Visibility Created Author
{post.title} {post.visibility} {new Date(post.createdAt).toLocaleDateString()} {new Date(post.createdAt).toLocaleTimeString()} {post.users ? post.users[0].username : ''}
}
) } export default Admin