💾 Archived View for iich.space › src › views › admin › AdminPostsPage.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

➡️ Next capture (2022-01-08)

-=-=-=-=-=-=-

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 PageLinks = (page: number) =>
  (page > 0
    ? `=> /admin/posts?${page - 1} Previous posts
`
    : '') + `=> /admin/posts?${page + 1} More posts`;

interface Props {
  posts: Array<AdminPost>;
  page: number;
}

const AdminPostsPage: Template<Props> = (
  { 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))}
`,
)}
${PageLinks(page)}
`;

export default AdminPostsPage;