Skip to content

Create the mobile-first Inbox page with grouping, unread state, dismissal, and badging #1723

Closed

Description

@propr-dev

Context

The existing header popovers expose only subsets of plan and task review data and disappear below the md breakpoint. A dedicated Inbox route should be the primary mobile view and must include every requested operational notification class.

Requirements

  • Add /inbox as an authenticated route.
  • Display plan-ready, failed/stalled task, completed implementation/review, PR-attention, indexing-failure, and system-failure items.
  • Group items into Needs attention, Ready for review, Completed, and System sections.
  • Show repository, relative time, unread state, event type, and available actions.
  • Deep-link the card itself to the relevant plan, task, repository, or system panel.
  • Mark an item read when its detail link is followed.
  • Allow optimistic dismissal with rollback and toast feedback on failure.
  • Support cursor pagination and pull-to-refresh-friendly manual refresh.
  • Synchronize the installed icon badge with the server unread count.
  • Consume ?intent=dismiss&notification=... from service-worker clicks.

Acceptance Criteria

  • Every required event kind has a visible label and correct group.
  • Dismissing one item immediately removes it and updates the badge.
  • A failed dismissal restores the item.
  • Opening a card marks it read and follows its server-provided deep link.
  • Loading more does not duplicate items when new notifications arrive.
  • Empty, loading, offline, and error states are usable on a 320px-wide viewport.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Aug 2, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    Build the Inbox as a normal server-backed route rather than another header dropdown. Cards render server-provided deep links and action capabilities, while the UI owns presentation grouping. Badge updates always use the server count so multiple devices and dismissal state converge. Optimistic dismissal improves mobile responsiveness but retains rollback on error.

    File: propr-ui/src/pages/InboxPage.tsx (new file)

    Why this file: This is the dedicated responsive notification workflow replacing hidden mobile header popovers.

    import React, { useCallback, useEffect, useMemo, useState } from 'react';
    import { Bell, CheckCircle2, RefreshCw, TriangleAlert, X } from 'lucide-react';
    import { useNavigate, useSearchParams } from 'react-router-dom';
    import type { NotificationEvent, NotificationKind } from '@propr/shared';
    import { dismissNotification, getNotifications, markNotificationRead } from '../api/notificationsApi';
    import { useToast } from '../components/ui/useToast';
    
    const kindLabels: Record<NotificationKind, string> = {
      plan_ready: 'Plan ready',
      task_failed: 'Task failed',
      task_stalled: 'Task stalled',
      implementation_completed: 'Implementation completed',
      review_completed: 'Review completed',
      pr_attention: 'PR ready',
      indexing_failed: 'Indexing failed',
      system_failed: 'System failure',
    };
    
    type GroupName = 'Needs attention' | 'Ready for review' | 'Completed' | 'System';
    
    const groupFor = (item: NotificationEvent): GroupName => {
      if (item.kind === 'plan_ready') return 'Ready for review';
      if (['implementation_completed', 'review_completed', 'pr_attention'].includes(item.kind)) return 'Completed';
      if (['indexing_failed', 'system_failed'].includes(item.kind)) return 'System';
      return 'Needs attention';
    };
    
    const relativeTime = (value: string): string => {
      const seconds = Math.max(0, Math.floor((Date.now() - new Date(value).getTime()) / 1000));
      if (seconds < 60) return 'just now';
      if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
      if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
      return `${Math.floor(seconds / 86400)}d ago`;
    };
    
    const updateBadge = (count: number) => {
      const worker = navigator.serviceWorker?.controller;
      worker?.postMessage({ type: 'SET_BADGE', count });
    };
    
    export default function InboxPage() {
      const navigate = useNavigate();
      const [searchParams, setSearchParams] = useSearchParams();
      const { addToast } = useToast();
      const [items, setItems] = useState<NotificationEvent[]>([]);
      const [cursor, setCursor] = useState<string | null>(null);
      const [loading, setLoading] = useState(true);
      const [loadingMore, setLoadingMore] = useState(false);
      const [error, setError] = useState<string | null>(null);
    
      const load = useCallback(async (nextCursor?: string) => {
        nextCursor ? setLoadingMore(true) : setLoading(true);
        setError(null);
        try {
          const result = await getNotifications(nextCursor);
          setItems(current => nextCursor
            ? [...new Map([...current, ...result.notifications].map(item => [item.id, item])).values()]
            : result.notifications);
          setCursor(result.nextCursor);
          updateBadge(result.unreadCount);
        } catch (reason) {
          setError((reason as Error).message);
        } finally {
          setLoading(false);
          setLoadingMore(false);
        }
      }, []);
    
      useEffect(() => { void load(); }, [load]);
    
      useEffect(() => {
        const id = searchParams.get('notification');
        if (searchParams.get('intent') !== 'dismiss' || !id) return;
        void dismissNotification(id).then(result => {
          setItems(current => current.filter(item => item.id !== id));
          updateBadge(result.unreadCount);
          setSearchParams({}, { replace: true });
        });
      }, [searchParams, setSearchParams]);
    
      const groups = useMemo(() => {
        const result = new Map<GroupName, NotificationEvent[]>();
        for (const name of ['Needs attention', 'Ready for review', 'Completed', 'System'] as GroupName[]) result.set(name, []);
        for (const item of items) result.get(groupFor(item))!.push(item);
        return result;
      }, [items]);
    
      const open = async (item: NotificationEvent) => {
        try {
          const result = await markNotificationRead(item.id);
          updateBadge(result.unreadCount);
        } finally {
          // Navigation remains useful during a transient receipt-write failure; the
          // detail view is more important than blocking on cosmetic read state.
          navigate(item.deepLink);
        }
      };
    
      const dismiss = async (item: NotificationEvent) => {
        const index = items.findIndex(candidate => candidate.id === item.id);
        setItems(current => current.filter(candidate => candidate.id !== item.id));
        try {
          const result = await dismissNotification(item.id);
          updateBadge(result.unreadCount);
        } catch (reason) {
          setItems(current => {
            const restored = [...current];
            restored.splice(Math.max(0, index), 0, item);
            return restored;
          });
          addToast({ type: 'error', message: (reason as Error).message });
        }
      };
    
      return (
        <main className='mx-auto w-full max-w-3xl px-3 sm:px-6 py-4 pb-24'>
          <header className='mb-4 flex items-center justify-between gap-3'>
            <div><h1 className='text-xl font-semibold text-slate-900'>Inbox</h1><p className='text-sm text-slate-500'>Plans, tasks, PRs, and system alerts.</p></div>
            <button type='button' onClick={() => load()} className='rounded-md border p-2' aria-label='Refresh Inbox'><RefreshCw className='h-4 w-4' /></button>
          </header>
    
          {loading && <p className='py-12 text-center text-slate-500'>Loading Inbox…</p>}
          {error && <div className='rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700'>{error}<button type='button' onClick={() => load()} className='ml-2 underline'>Retry</button></div>}
          {!loading && !error && items.length === 0 && <div className='py-16 text-center text-slate-500'><Bell className='mx-auto mb-3 h-8 w-8' /><p>You are all caught up.</p></div>}
    
          {[...groups.entries()].map(([name, notifications]) => notifications.length > 0 && (
            <section key={name} className='mb-6'>
              <h2 className='mb-2 text-xs font-bold uppercase tracking-wider text-slate-500'>{name}</h2>
              <div className='space-y-2'>
                {notifications.map(item => {
                  const failed = ['task_failed', 'task_stalled', 'indexing_failed', 'system_failed'].includes(item.kind);
                  return (
                    <article key={item.id} className={`rounded-xl border bg-white p-3 shadow-sm ${item.readAt ? 'border-slate-200' : 'border-teal-400'}`}>
                      <div className='flex gap-3'>
                        <div className={`mt-0.5 ${failed ? 'text-red-600' : 'text-teal-700'}`}>{failed ? <TriangleAlert className='h-5 w-5' /> : <CheckCircle2 className='h-5 w-5' />}</div>
                        <button type='button' onClick={() => open(item)} className='min-w-0 flex-1 text-left'>
                          <div className='flex items-center gap-2'><span className='text-xs font-semibold text-slate-500'>{kindLabels[item.kind]}</span><span className='text-xs text-slate-400'>{relativeTime(item.occurredAt)}</span></div>
                          <h3 className='truncate font-medium text-slate-900'>{item.title}</h3>
                          <p className='mt-1 line-clamp-2 text-sm text-slate-600'>{item.body}</p>
                          {item.projectSlug && <p className='mt-1 truncate text-xs text-slate-400'>{item.projectSlug}</p>}
                        </button>
                        <button type='button' onClick={() => dismiss(item)} className='self-start rounded p-1 text-slate-400 hover:bg-slate-100' aria-label={`Dismiss ${item.title}`}><X className='h-4 w-4' /></button>
                      </div>
                      <div className='notification-actions mt-3 flex flex-wrap gap-2' data-notification-id={item.id} />
                    </article>
                  );
                })}
              </div>
            </section>
          ))}
    
          {cursor && <button type='button' disabled={loadingMore} onClick={() => load(cursor)} className='w-full rounded-lg border py-2 text-sm'>{loadingMore ? 'Loading…' : 'Load older notifications'}</button>}
        </main>
      );
    }

    File: propr-ui/src/App.tsx

    Why this file: The Inbox must participate in the existing authentication and compatibility gates.

    --- a/propr-ui/src/App.tsx
    +++ b/propr-ui/src/App.tsx
    @@ -1,5 +1,6 @@
    +import InboxPage from './pages/InboxPage';
    @@ -140,6 +141,7 @@
    +          <Route path='/inbox' element={<InboxPage />} />
  2. propr-dev commented on Aug 24, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: codex
    • Model: gpt-5.6-sol
    • Branch: 1723/gpt-5.6-sol-create-the-mobile-first-i-20260824-1227-mud
    • Base Branch: 1716-epic-failed-to-3m8
    • Worktree: issue-1723-20260824-1227-gpt-5.6-sol-mud

    🔍 Track Task Execution

  3. added a commit that references this issue on Aug 24, 2026
  4. added a commit that references this issue on Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions