Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

4.0 KB
Raw Blame
/* Orkas Frontend — sidebar "Recent Tasks" (formerly "Today's Tasks")
 *
 * Aggregates every conversation with activity today or yesterday (local
 * calendar), whether it lives under a
 * Project or in the catch-all Tasks list, so running work and finished work
 * that still needs a look sit in one place. The section is a mirror only:
 * rows reuse the shared conversation row renderer, click/menu handlers,
 * unread dots, and live-run badges, and the `conversations` cache remains the
 * single source of truth. Only the visible row limit belongs to this list;
 * opening a task from either copy clears both copies' attention cue.
 *
 * Day boundary: `selectRecentConversations` (conv-bucket.js) reads the same
 * activity timestamp and local-midnight rule as the "Today"/"Yesterday" bucket
 * headers, so a row is never "today" or "yesterday" in one list and absent
 * here. The date rollover re-render (conversation.js
 * `_refreshConversationBucketsForDateChange`) is the once-a-day check that drops
 * rows older than yesterday. Rows for collapsed projects reach the cache through
 * the startup slice's `active_since` filter (start of yesterday).
 *
 * DOM ids, the i18n keys and the section's collapse key keep their historical
 * `today` names; only the window and the label changed.
 *
 * Regular refreshes use `renderConversationList`'s trailing badge pass.
 * Loading more or reopening refreshes only this list and its badges;
 * reopening resets the visible row limit to the first page.
 */

const _RECENT_TASK_PAGE_SIZE = 10;
let _recentTaskVisibleCount = _RECENT_TASK_PAGE_SIZE;

function _todayTaskRows(now) {
  const rows = typeof conversations !== 'undefined' && Array.isArray(conversations)
    ? conversations
    : [];
  const selected = typeof selectRecentConversations === 'function'
    ? selectRecentConversations(rows, now)
    : [];
  const recent = Array.isArray(selected) ? selected : [];
  if (typeof _compareConversationsForSidebar === 'function') {
    recent.sort(_compareConversationsForSidebar);
  }
  return recent;
}

function renderTodayTasksSection() {
  const container = document.getElementById('today-list');
  if (!container) return;
  // An inline rename that lives in this list keeps its editor mounted; the
  // owning submit/cancel path renders again. Other lists refresh normally.
  if (typeof _conversationInlineRenameBlocksRender === 'function'
      && _conversationInlineRenameBlocksRender(container)) {
    return;
  }
  const rows = _todayTaskRows(new Date());
  if (!rows.length) {
    container.innerHTML = `<div class="conv-empty" data-i18n="sidebar.today_empty">${escapeHtml(t('sidebar.today_empty'))}</div>`;
    return;
  }
  const visibleRows = rows.slice(0, _recentTaskVisibleCount);
  const projectByCid = new Map(visibleRows.map((c) => [c.conversation_id, c.project_id || '']));
  container.innerHTML = visibleRows.map((c) => _renderConversationSidebarItem(c, { listId: 'today-list' })).join('');
  if (rows.length > visibleRows.length) {
    container.insertAdjacentHTML('beforeend', `<button type="button" class="conversation-list-load-more" data-recent-conv-more="1">
      ${escapeHtml(t('sidebar.load_more_conversations'))}</button>`);
    container.querySelector('[data-recent-conv-more]').addEventListener('click', () => {
      _recentTaskVisibleCount += _RECENT_TASK_PAGE_SIZE;
      renderTodayTasksSection();
      _refreshAllConvBadges();
      container.querySelector('[data-recent-conv-more]')?.focus({ preventScroll: true });
    });
  }
  _bindConversationSidebarItems(container, {
    scope: 'recent',
    async afterDelete(cid) {
      // A projected task also changes its project's count; the nested project
      // list does the same refresh after its own delete.
      if (projectByCid.get(cid) && typeof loadProjects === 'function') await loadProjects(true);
    },
  });
}

window.addEventListener('sidebar-section-toggle', (event) => {
  if (event?.detail?.name !== 'today' || event.detail.collapsed !== false) return;
  _recentTaskVisibleCount = _RECENT_TASK_PAGE_SIZE;
  renderTodayTasksSection();
  _refreshAllConvBadges();
});