!7

concept AIList {
  S name;
  S text;
  long modified;
}

p {
  db();
}

html {
  if (!webAuthed()) ret redirectToWebAuth();
  
  new Matches m;
  if (startsWith(uri, "/list/", m)) {
    AIList l = conceptWhere(AIList, name := m.get(0));
    if (l == null) ret "List not found";
    ret nav() + htitle_h3(htmlencode(l.name));
  }
  
  S newList = params.get('newList);
  if (nempty(newList)) {
    AIList l = uniq(AIList, name := newList);
    ret hrefresh(rawLink("/list/" + urlencode(l.name)));
  }
  
  ret htitle("Lists DB")
    + h3("Lists")
    + ul(map(list(AIList), func(AIList l) -> S {
      ahref(rawLink("/list/" + urlencode(l.name), htmlencode(l.name)))
    }))
    + h3("New list")
    + hpostform("Name: " + htextinput('newList) + " " + hsubmit("Create list"));
}

sS nav() {
  ret p(ahref(rawLink(), "<< back"));
}