feat(offline): tier 2 phase 4 — per-row pending-sync indicators
A small cloud-upload glyph appears next to any row whose id has a queued offline write (offline-created temp ids and pending edits both count). Tooltip reads "Pending sync — will save when online". Renders nothing during normal online operation so the list stays clean. - DB: `watchPendingIds(domain)` streams the union of target_id and temp_id across the queue, scoped per domain. - Per-domain Riverpod stream providers for notes / tasks / projects. - New `PendingSyncBadge` widget — used by KnowledgeItemCard (both list and grid variants), `_ProjectCard`, and `_TaskRow` in the project workspace. flutter analyze clean; 21 tests pass. Closes #147 — all four phases of Tier 2 offline mode are in place. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../data/local/database.dart';
|
||||
import '../data/models/knowledge_item.dart';
|
||||
import 'pending_sync_badge.dart';
|
||||
|
||||
class KnowledgeItemCard extends StatelessWidget {
|
||||
final KnowledgeItem item;
|
||||
const KnowledgeItemCard({super.key, required this.item});
|
||||
|
||||
String get _pendingDomain =>
|
||||
item.noteType == 'task' ? kSyncDomainTasks : kSyncDomainNotes;
|
||||
|
||||
IconData get _icon => switch (item.noteType) {
|
||||
'person' => LucideIcons.user,
|
||||
'place' => LucideIcons.mapPin,
|
||||
@@ -52,10 +57,17 @@ class KnowledgeItemCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(_icon, color: _statusColor(context)),
|
||||
title: Text(
|
||||
item.title.isEmpty ? '(untitled)' : item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
title: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
item.title.isEmpty ? '(untitled)' : item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
PendingSyncBadge(domain: _pendingDomain, id: item.id),
|
||||
],
|
||||
),
|
||||
subtitle: _subtitle != null
|
||||
? Text(
|
||||
@@ -100,6 +112,7 @@ class KnowledgeItemCard extends StatelessWidget {
|
||||
?.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
PendingSyncBadge(domain: _pendingDomain, id: item.id),
|
||||
],
|
||||
),
|
||||
if (_subtitle != null) ...[
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../data/local/database.dart';
|
||||
import '../providers/api_client_provider.dart';
|
||||
|
||||
/// Small cloud-upload glyph shown next to a row whose id has a queued
|
||||
/// offline write (Phase 4). Renders nothing when the queue is empty for
|
||||
/// that id, so list views stay clean during normal online operation.
|
||||
class PendingSyncBadge extends ConsumerWidget {
|
||||
final String domain;
|
||||
final int id;
|
||||
final double size;
|
||||
|
||||
const PendingSyncBadge({
|
||||
super.key,
|
||||
required this.domain,
|
||||
required this.id,
|
||||
this.size = 14,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final pending = switch (domain) {
|
||||
kSyncDomainNotes => ref.watch(pendingNoteIdsProvider).asData?.value,
|
||||
kSyncDomainTasks => ref.watch(pendingTaskIdsProvider).asData?.value,
|
||||
kSyncDomainProjects =>
|
||||
ref.watch(pendingProjectIdsProvider).asData?.value,
|
||||
_ => null,
|
||||
};
|
||||
if (pending == null || !pending.contains(id)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Tooltip(
|
||||
message: 'Pending sync — will save when online',
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Icon(
|
||||
LucideIcons.uploadCloud,
|
||||
size: size,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user