<commit_before>import { h } from 'snabbdom'
import { VNode } from 'snabbdom/vnode'
import { Ctrl, Challenge, ChallengeData, ChallengeDirection, ChallengeUser, TimeControl } from './interfaces'

export default function(ctrl: Ctrl): VNode {
  const d = ctrl.data();
  return h('div#challenge_app.links.dropdown',
    d && !ctrl.initiating() ? renderContent(ctrl, d) : [h('div.initiating', spinner())]);
}

function renderContent(ctrl: Ctrl, d: ChallengeData): VNode {
  const nb = d.in.length + d.out.length;
  return nb ? allChallenges(ctrl, d, nb) : empty();
}

function userPowertips(vnode: any) {
  window.lichess.powertip.manualUserIn(vnode.elm);
}

function allChallenges(ctrl: Ctrl, d: ChallengeData, nb: number) {
  return h('div', {
    key: 'all',
    class: {
      challenges: true,
      reloading: ctrl.reloading(),
      many: nb > 3
    },
    hook: {
      insert: userPowertips,
      postpatch: userPowertips
    }
  }, d.in.map(challenge(ctrl, 'in')).concat(d.out.map(challenge(ctrl, 'out'))));
}

function challenge(ctrl: Ctrl, dir: ChallengeDirection) {
  return (c: Challenge) => {
    return h('div', {
      key: c.id,
      class: {
        challenge: true,
        [dir]: true,
        declined: c.declined
      }
    }, [
      h('div.content', [
        h('span.title', renderUser(dir === 'in' ? c.challenger : c.destUser)),
        h('span.desc', [
          window.lichess.globalTrans(c.rated ? 'Rated' : 'Casual'),
          timeControl(c.timeControl),
          c.variant.name
        ].join(' • '))
      ]),<commit_msg>tweak ui/challenge2<commit_after>import { h } from 'snabbdom'
import { VNode } from 'snabbdom/vnode'
import { Ctrl, Challenge, ChallengeData, ChallengeDirection, ChallengeUser, TimeControl } from './interfaces'

export default function(ctrl: Ctrl): VNode {
  const d = ctrl.data();
  return h('div#challenge_app.links.dropdown',
    d && !ctrl.initiating() ? renderContent(ctrl, d) : [h('div.initiating', spinner())]);
}

function renderContent(ctrl: Ctrl, d: ChallengeData): VNode {
  const nb = d.in.length + d.out.length;
  return nb ? allChallenges(ctrl, d, nb) : empty();
}

function userPowertips(vnode: VNode) {
  window.lichess.powertip.manualUserIn(vnode.elm);
}

function allChallenges(ctrl: Ctrl, d: ChallengeData, nb: number) {
  return h('div.challenges', {
    key: 'all',
    class: {
      reloading: ctrl.reloading(),
      many: nb > 3
    },
    hook: {
      insert: userPowertips,
      postpatch: userPowertips
    }
  }, d.in.map(challenge(ctrl, 'in')).concat(d.out.map(challenge(ctrl, 'out'))));
}

function challenge(ctrl: Ctrl, dir: ChallengeDirection) {
  return (c: Challenge) => {
    return h('div.challenge.' + dir, {
      key: c.id,
      class: {
        declined: c.declined
      }
    }, [
      h('div.content', [
        h('span.title', renderUser(dir === 'in' ? c.challenger : c.destUser)),
        h('span.desc', [
          window.lichess.globalTrans(c.rated ? 'Rated' : 'Casual'),
          timeControl(c.timeControl),
          c.variant.name
        ].join(' • '))
      ]),
{'fraction_non_alphanumeric': 0.1650390625, 'fraction_numerical': 0.0009765625, 'mean_word_length': 3.0973333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5417673', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1046, 'n_words': 222}