JSFiddle - React, Tailwind, and code Playground

by brigand

HTML

<script type="application/json" id="api_data">[{"id":"244","content":"Cyberland will solely operate in obscurity if we behave this way. Share your clients. The more surface area the better for user retention -- they might find a reason to stick around cyberland.\r\n\r\nPerhaps the obscurity is your point --- in which case I disagree but understand.","replyTo":"242","bumpCount":"0","time":"2020-04-14 19:19:49"},{"id":"243","content":"nigger","replyTo":"241","bumpCount":"0","time":"2020-04-14 19:16:04"},{"id":"242","content":"keep the client to yourself don't share\r\n\r\n-posted from cyberland3.club","replyTo":"234","bumpCount":"1","time":"2020-04-14 19:13:02"},{"id":"241","content":"check out these numbers","replyTo":"0","bumpCount":"1","time":"2020-04-14 19:04:32"},{"id":"240","content":"If it's helpful, I can enable a no-cache header on the server?","replyTo":"19","bumpCount":"0","time":"2020-04-14 17:49:44"},{"id":"239","content":"When do you cache invalidate? Upstream should cache. Memcache would be dog simple to impl.","replyTo":"19","bumpCount":"0","time":"2020-04-14 17:41:48"},{"id":"238","content":"he changed it","replyTo":"216","bumpCount":"0","time":"2020-04-14 17:39:24"},{"id":"237","content":"I've been using this lately. Good for stand up desks.\r\n\r\nhttps:\/\/www.amazon.com\/Focal-FKS-1000-BK-Products-Leaning-Portable\/dp\/B00KQ1M21I\/ref=sr_1_2?dchild=1&keywords=pogo+chair&qid=1586885069&sr=8-2","replyTo":"122","bumpCount":"0","time":"2020-04-14 17:25:02"},{"id":"236","content":"The fist one was cyberland.club. It's owner took it down so someone oppend cyberland2.cluw which is more or less a copy of the original\nAs far as I know cyberland.digital is still vaporwave.","replyTo":"235","bumpCount":"0","time":"2020-04-14 17:22:15"},{"id":"235","content":"Can anyone provide a genealogy of cyberlands so far? Where did the first go? .digital? ","replyTo":"204","bumpCount":"1","time":"2020-04-14 17:07:54"},{"id":"234","content":"cyberland3.club owner...

JavaScript

const data = JSON.parse(api_data.innerHTML);

const items = new Map(data.map(item => [item.id, {...item, replies: []}]));

for (const [key, item] of items) {
	if (item.replyTo !== '0') {
	  const parent = items.get(item.replyTo);
    if (parent) {
	    parent.replies.push(item);
    }
  }
}

const roots = Array.from(items.values()).filter(item => item.replyTo === '0');
out.textContent = JSON.stringify(roots, null, 2);