aboutsummaryrefslogtreecommitdiff
path: root/app.js
blob: b908bf85890a2c7888287c732416988aac464985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var screen = h('div', {id: 'screen'})
document.body.appendChild(screen)

function route (keys) {
  src = window.location.hash.substring(1)

  var scroller = h('div', {id: 'scroller'})
  var screen = document.getElementById('screen')
  screen.appendChild(scroller)

  if (src === 'settings') {
    settingsPage(keys)
  } else if (src[0] === '@') {
    profilePage(src, keys)
  } else if (src[0] === '?') {
    searchPage(src, keys)
  } else if (src[0] === '%') {
    threadPage(src, keys)
  } else {
    publicPage(keys)
  }
}

keys().then(key => { 
  var search = h('input', {placeholder: 'Serĉilo', classList: 'search'})

  var navbar = h('div', {classList: 'navbar'}, [
    h('div', {classList: 'internal'}, [
      h('li', [h('a', {href: '#' + key.publicKey}, 
        [
          getImage(key.publicKey, keys),
        ])
      ]),
      h('li', [h('a', {href: '#' + key.publicKey}, 
        [
          getName(key.publicKey, keys)
        ])
      ]),
      h('li', [h('a', {href: '#'}, ['Ĉiuj'])]),
      h('li', [h('a', {href: '#?' + key.publicKey}, ['Mencioj'])]),
      h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Agordoj'])]),
      h('form', { classList: 'search', 
        onsubmit: function (e) {
          window.location.hash = '?' + search.value
          e.preventDefault()
        }},
        [search]
      )
    ])
  ])
  document.body.appendChild(navbar)

  route(key)
})

window.onhashchange = function () {
  keys().then(key => {
    var oldscreen = document.getElementById('screen')
    var newscreen = h('div', {id: 'screen'})
    oldscreen.parentNode.replaceChild(newscreen, oldscreen)

    route(key)
  })
}