feat: reformat some pages
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../models/app_error.dart';
|
||||
import '../models/remote_command.dart';
|
||||
import '../models/update_failure.dart';
|
||||
import 'app_localizations.dart';
|
||||
|
||||
@@ -17,6 +20,32 @@ extension AppLocalizationsHelpers on AppLocalizations {
|
||||
};
|
||||
}
|
||||
|
||||
/// "just now", "5 minutes ago"…, and the full date once a day has passed.
|
||||
String relativeTime(DateTime time, String locale, {DateTime? now}) {
|
||||
final elapsed = (now ?? DateTime.now()).difference(time);
|
||||
|
||||
if (elapsed.inMinutes < 1) return justNow;
|
||||
if (elapsed.inHours < 1) return minutesAgo(elapsed.inMinutes);
|
||||
if (elapsed.inDays < 1) return hoursAgo(elapsed.inHours);
|
||||
return DateFormat.yMMMd(locale).add_jm().format(time.toLocal());
|
||||
}
|
||||
|
||||
String remoteCommandLabel(String rawType) {
|
||||
return switch (CommandType.fromValue(rawType)) {
|
||||
CommandType.closeTab => remoteCommandCloseTab,
|
||||
null => remoteCommandUnknown(rawType),
|
||||
};
|
||||
}
|
||||
|
||||
String commandResultLabel(CommandResult result) {
|
||||
return switch (result) {
|
||||
CommandResult.completed => commandCompleted,
|
||||
CommandResult.conflict => commandConflict,
|
||||
CommandResult.failed => commandFailed,
|
||||
CommandResult.expired => commandExpired,
|
||||
};
|
||||
}
|
||||
|
||||
String errorText(AppError? error) {
|
||||
return switch (error) {
|
||||
null => genericError,
|
||||
|
||||
Reference in New Issue
Block a user