2024-02-17 20:32:01 +05:30
|
|
|
import "package:auto_route/auto_route.dart";
|
|
|
|
|
import "package:flutter/material.dart";
|
|
|
|
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
|
|
|
|
|
2026-09-26 22:45:38 +03:00
|
|
|
import "package:smol_mail/data/providers/providers.dart";
|
|
|
|
|
import "package:smol_mail/presentation/routes/app_router.gr.dart";
|
|
|
|
|
import "package:smol_mail/presentation/widgets/drawer/app_drawer.dart";
|
|
|
|
|
import "package:smol_mail/presentation/widgets/image_banner.dart";
|
|
|
|
|
import "package:smol_mail/presentation/widgets/message/message_list.dart";
|
|
|
|
|
import "package:smol_mail/shared/utils/snackbar.dart";
|
|
|
|
|
import "package:smol_mail/smol/errors.dart";
|
2024-02-17 20:32:01 +05:30
|
|
|
|
2026-09-26 22:45:38 +03:00
|
|
|
/// No server push in v1 (SPEC.md §13): new mail arrives when the user taps
|
|
|
|
|
/// fetch, which pulls everything and acknowledges what verifies.
|
2024-02-17 20:32:01 +05:30
|
|
|
@RoutePage()
|
2026-09-26 22:45:38 +03:00
|
|
|
class InboxScreen extends ConsumerWidget {
|
2024-02-17 20:32:01 +05:30
|
|
|
const InboxScreen({super.key});
|
|
|
|
|
|
2026-09-26 22:45:38 +03:00
|
|
|
Future<void> _fetch(BuildContext context, WidgetRef ref) async {
|
|
|
|
|
final client = ref.read(clientProvider);
|
|
|
|
|
try {
|
|
|
|
|
final summary = await client.fetch();
|
|
|
|
|
ref.read(revisionProvider.notifier).bump();
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
final tail = summary.rejected.isEmpty
|
|
|
|
|
? ""
|
|
|
|
|
: "\n${summary.rejected.length} left on the server";
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(content: Text("${summary.stored} new$tail")),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} on SmolError catch (err) {
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
showErrorSnackBar(context, err.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-17 20:32:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2026-09-26 22:45:38 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-02-17 20:32:01 +05:30
|
|
|
final messages = ref.watch(messagesProvider);
|
2026-09-26 22:45:38 +03:00
|
|
|
final folder = ref.watch(folderProvider);
|
2024-02-17 20:32:01 +05:30
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2026-09-26 22:45:38 +03:00
|
|
|
title: Text(folder == "inbox" ? "Inbox" : "Sent"),
|
|
|
|
|
actions: [
|
|
|
|
|
if (folder == "inbox")
|
|
|
|
|
IconButton(
|
|
|
|
|
tooltip: "Fetch",
|
|
|
|
|
onPressed: () => _fetch(context, ref),
|
|
|
|
|
icon: const Icon(Icons.cloud_download),
|
|
|
|
|
),
|
|
|
|
|
],
|
2024-02-17 20:32:01 +05:30
|
|
|
),
|
|
|
|
|
drawer: const AppDrawer(),
|
2026-09-26 22:45:38 +03:00
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
|
onPressed: () => AutoRouter.of(context).push(ComposeRoute()),
|
|
|
|
|
child: const Icon(Icons.edit),
|
2024-02-17 20:32:01 +05:30
|
|
|
),
|
2026-09-26 22:45:38 +03:00
|
|
|
body: messages.isEmpty
|
|
|
|
|
? RefreshIndicator(
|
|
|
|
|
onRefresh: () => folder == "inbox"
|
|
|
|
|
? _fetch(context, ref)
|
|
|
|
|
: Future.value(),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: const [
|
|
|
|
|
ImageBanner(
|
|
|
|
|
imgSrc: "assets/images/empty.png",
|
|
|
|
|
text: "Nothing here yet!",
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: MessageList(
|
|
|
|
|
onRefresh: () => folder == "inbox"
|
|
|
|
|
? _fetch(context, ref)
|
|
|
|
|
: Future.value(),
|
|
|
|
|
),
|
2024-02-17 20:32:01 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|