import { Template } from '@/mission-control'; import Header from '../Header'; import PostItem from '../PostItem'; import { AdminPost } from '~/db/models'; const LockLink = (post: AdminPost, page: number) => post.locked ? `=> /admin/posts/lock/${post.id}/unlock?${page} Unlock Thread` : `=> /admin/posts/lock/${post.id}/lock?${page} Lock Thread`; const DeleteLink = (post: AdminPost, page: number) => post.deleted ? `=> /admin/posts/delete/${post.id}/permit?${page} Permit Post` : `=> /admin/posts/delete/${post.id}/remove?${page} Remove Post`; const MuteLink = (post: AdminPost, page: number) => post.muted ? `=> /admin/posts/mute/${post.id}/unmute?${page} Unmute Post` : `=> /admin/posts/mute/${post.id}/mute?${page} Mute Post`; const BanLink = (post: AdminPost, page: number) => `=> /admin/posts/ban/${post.origin}?${page} ${ post.banned ? 'Unban' : 'Ban' } Poster`; const MoveLink = (post: AdminPost) => `=> /admin/posts/move/${post.id} Move to Thread`; const PageLinks = (page: number) => (page > 0 ? `=> /admin/posts?${page - 1} Previous posts ` : '') + `=> /admin/posts?${page + 1} More posts`; interface Props { posts: Array; page: number; } const AdminPostsPage: Template = ( { each, include, when }, { page, posts }, ): string => ` ${include(Header)} => / Index => /admin Back ${each( posts, (post) => ` ${when(post.deleted === 1, () => '[DELETED] ')}${include(PostItem, { post })} ${when(post.threadId === post.id, () => LockLink(post, page))} ${when(post.threadId === post.id, () => MuteLink(post, page))} ${DeleteLink(post, page)} ${when(post.origin !== null, () => BanLink(post, page))} ${MoveLink(post)} `, )} ${PageLinks(page)} `; export default AdminPostsPage;