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

View Raw

More Information

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

import { Template } from '@/mission-control';

import { Board, BoardType, PostStats, ThreadWithReplies } from '~/db/models';
import { IdentityDisplay } from '~/util/identity';

import Header from './Header';
import ThreadItem from './ThreadItem';

interface Props {
  board: Board;
  boardStats: Omit<PostStats, 'replyCount'>;
  threads: Array<ThreadWithReplies>;
  repliesPerThread: number;
  page: number;
  threadsPerPage: number;
  identity: IdentityDisplay | null;
}

const BoardPage: Template<Props> = (
  { each, include, link, t, when },
  {
    board,
    boardStats,
    identity,
    page,
    repliesPerThread,
    threads,
    threadsPerPage,
  },
): string => `
${include(Header, { board })}

=> / ${t('index')}

${each(
  threads,
  (thread) =>
    include(ThreadItem, {
      repliesPerThread,
      showLinks: board.type === BoardType.Image,
      thread,
    }),
  3,
)}

${when(
  page * threadsPerPage < boardStats.threadCount,
  () => `
=> ${board.path}${page + 1} ${t('more_threads')}
`,
)}

${when(
  board.type === BoardType.Text,
  () => `
${link(`${board.path}post`, t('start_thread'))}
${when(
  identity !== null,
  () => `
${link(`${board.path}post?signed`, t('start_thread_as', identity!.display))}
`,
)}
`,
)}
${when(
  board.type === BoardType.Image,
  () => `
${link(`${board.path}post?image`, t('start_image_thread'))}
${when(
  identity !== null,
  () => `
${link(
  `${board.path}post?signed,image`,
  t('start_image_thread_as', identity!.display),
)}
`,
)}
`,
)}
`;

export default BoardPage;