<commit_before>import { h, VTree } from '../framework/view';
import htmlescape from 'htmlescape';

import { State } from './models/state';
import { User } from './models/user';
import renderUser from './views/user';

const renderUsers = (users: User[]): VTree => {
  return h('ul.users', users.map(renderUser).map(user => h('li', [user])));
};

const renderApp = (state: State) => {
  return h('div#app', [
    h('nav', [h('a', { href: '/users' }, ['/users'])]),
    (
      state.user
      ? renderUser(state.user)
      : renderUsers(state.users)
    )
  ]);
};

const view = (state: State, all: boolean = false): VTree => {
  const app = renderApp(state);
  if (!all) return app;
  return h('html', [
    h('head', [
      h('title', ['vdom-rxjs-ssr']),
      h('script', ['var INITIAL_STATE = ' + htmlescape(state) + ';'])
    ]),
    h('body', [
      app,
      h('script', { src: '/scripts/bundle.js' }, [])
    ])
  ]);
};

export { view };<commit_msg>add new view<commit_after>import { h, VTree } from '../framework/view';
import htmlescape from 'htmlescape';

import { State } from './models/state';

const renderSignInPage = (state: State): VTree => {
  return h('div.sign-in-page', [
    h('label', [
      'email',
      h('input.email', {
        type: 'email',
        name: 'email',
        value: state.signIn.email
      }, []),
    ]),
    h('label', [
      'password',
      h('input.password', {
        type: 'password',
        name: 'password',
        value: state.signIn.password
      }, [])
    ]),
    h('button', ['sign in'])
  ]);
};

const renderStampRallyListPage = (state: State): VTree => {
  return h('div.stamp-rally-list-page', [
    h('ul', state.stampRallies.map(stampRally => {
      return h('li', [stampRally.name]);
    }))
  ]);
};

const renderNotFound = (): VTree => {
  return h('div.not-found', ['page not found']);
};

const renderPage = (state: State): VTree => {
  switch (state.currentPage) {
    case 'sign-in':
      return renderSignInPage(state);
    case 'stamp-rally-list':
      return renderStampRallyListPage(state);
    default:
      return renderNotFound();
  }
};

const renderApp = (state: State) => {
  return h('div#app', [
    h('h1', ['RALLY (unofficial)']),
    renderPage(state)
  ]);
};

const view = (state: State, all: boolean = false): VTree => {
  const app = renderApp(state);
  if (!all) return app;
  return h('html', [
    h('head', [
      h('title', ['rally-rxjs']),
      h('script', ['var INITIAL_STATE = ' + htmlescape(state) + ';'])
    ]),
    h('body', [
      app,
      h('script', { src: '/scripts/bundle.js' }, [])
    ])
  ]);
};

export { view };
{'fraction_non_alphanumeric': 0.21293494704992436, 'fraction_numerical': 0.00037821482602118004, 'mean_word_length': 2.8444767441860463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368258', 'n_tokens_mistral': 944, 'n_tokens_neox': 933, 'n_words': 198}