diff --git a/static/index.js b/static/index.js index 3e40dd6..c0fac55 100644 --- a/static/index.js +++ b/static/index.js @@ -39,18 +39,27 @@ function renderItems() { } function getLocString(items, item) { - if (item.is_in == item.id) { - return ['in ↻', `${item.id} is in itself`]; - } let ancestors = []; let next = item; + let loop = false; while (next) { + if (ancestors.includes(next)) { + loop = true; + if (ancestors.length == 1) { + ancestors.push(null); + } + break; + } ancestors.unshift(next); next = items[next.is_in]; } ancestors.pop(); - const loc = ancestors.map(i => i.id).join(' ➜ ') || '⬚'; + let loc = ancestors.map(i => i.id).join(' ➜ ') || '⬚'; let longloc = ancestors.map(i => `${i.type || ''} ${i.id} ${i.name && `(${i.name})` || ''}`).join(' ➜ ') || 'universe'; + if (loop) { + loc += ' ↻'; + longloc += ' ↻'; + } return [loc, `${item.id} is in ${longloc}`]; }