diff --git a/assets/i18n/en-US.json b/assets/i18n/en-US.json index 2890874..125e488 100644 --- a/assets/i18n/en-US.json +++ b/assets/i18n/en-US.json @@ -107,6 +107,7 @@ "connectionConnected": "Connected", "connectionDisconnected": "Disconnected", "connectionReconnecting": "Reconnecting", + "checkIn": "Check In", "checkInNone": "Not checked-in yet", "checkInNoneHint": "Get your fortune tips and daily rewards by checking in.", "checkInResultLevel0": "Wrost Luck", @@ -114,6 +115,7 @@ "checkInResultLevel2": "A Normal Day", "checkInResultLevel3": "Good Luck", "checkInResultLevel4": "Best Luck", + "checkInActivityTitle": "{} checked in on {} and got a {}", "eventCalander": "Event Calander", "eventCalanderEmpty": "No events on that day." } diff --git a/lib/screens/account/me/event_calendar.dart b/lib/screens/account/me/event_calendar.dart index 9909cb3..d613721 100644 --- a/lib/screens/account/me/event_calendar.dart +++ b/lib/screens/account/me/event_calendar.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:auto_route/auto_route.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index ee0a5ec..4a85ab8 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -64,6 +64,8 @@ class ExploreScreen extends ConsumerWidget { ); }, ); + case 'accounts.check-in': + return CheckInActivityWidget(item: item); default: return Placeholder(); } diff --git a/lib/widgets/check_in.dart b/lib/widgets/check_in.dart index 7b2ac28..7a25492 100644 --- a/lib/widgets/check_in.dart +++ b/lib/widgets/check_in.dart @@ -1,12 +1,17 @@ +import 'dart:convert'; + import 'package:auto_route/auto_route.dart'; import 'package:dio/dio.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:island/models/activity.dart'; import 'package:island/pods/network.dart'; import 'package:island/route.gr.dart'; +import 'package:island/screens/auth/captcha.dart'; import 'package:island/widgets/alert.dart'; +import 'package:island/widgets/content/cloud_files.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:styled_widget/styled_widget.dart'; @@ -42,6 +47,20 @@ class CheckInWidget extends HookConsumerWidget { await client.post('/accounts/me/check-in'); ref.invalidate(checkInResultTodayProvider); } catch (err) { + if (err is DioException) { + if (err.response?.statusCode == 423 && context.mounted) { + final captchaTk = await Navigator.of( + context, + ).push(MaterialPageRoute(builder: (context) => CaptchaScreen())); + if (captchaTk == null) return; + await client.post( + '/accounts/me/check-in', + data: jsonEncode(captchaTk), + ); + ref.invalidate(checkInResultTodayProvider); + return; + } + } showErrorAlert(err); } } @@ -155,3 +174,48 @@ class _CheckInNoneWidget extends StatelessWidget { ); } } + +class CheckInActivityWidget extends StatelessWidget { + final SnActivity item; + const CheckInActivityWidget({super.key, required this.item}); + + @override + Widget build(BuildContext context) { + final result = SnCheckInResult.fromJson(item.data); + return Row( + spacing: 12, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ProfilePictureWidget( + fileId: result.account!.profile.pictureId, + radius: 12, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Icon(Symbols.local_fire_department, size: 14), + const Gap(4), + Text('checkIn').fontSize(11).tr(), + ], + ).opacity(0.85), + Text('checkInActivityTitle') + .tr( + args: [ + result.account!.nick, + DateFormat.yMd().format(result.createdAt), + 'checkInResultLevel${result.level}'.tr(), + ], + ) + .fontSize(13) + .padding(left: 2), + ], + ), + ), + ], + ).padding(horizontal: 16, vertical: 12); + } +}