Skip to content

Commit

Permalink
Add some utils
Browse files Browse the repository at this point in the history
  • Loading branch information
redsolver committed Nov 14, 2023
1 parent 5a9272d commit 6cfd2d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/util/regex.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
final postUrlRegex = RegExp(
r'https:\/\/bsky\.app\/profile\/[a-z0-9A-Z\-\.:]+\/post\/[a-z0-9A-Z\-\_\~]+',
);

final feedUrlRegex = RegExp(
r'https:\/\/bsky\.app\/profile\/[a-z0-9A-Z\-\.:]+\/feed\/[a-z0-9A-Z\-\_\~]+',
);
16 changes: 16 additions & 0 deletions lib/util/render_timestamp.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
String renderTimestamp(DateTime ts) {
final dur = DateTime.now().difference(ts);
if (dur < Duration.zero) {
return 'in ${dur.inHours.abs()}h';
} else if (dur < const Duration(minutes: 1)) {
return '${dur.inSeconds}s';
} else if (dur < const Duration(hours: 1)) {
return '${dur.inMinutes}m';
} else if (dur < const Duration(hours: 24)) {
return '${dur.inHours}h';
} else if (dur < const Duration(days: 30)) {
return '${dur.inDays}d';
} else {
return '${(dur.inDays / 30).round()}mon';
}
}
15 changes: 15 additions & 0 deletions lib/util/show_popup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:skyfeed/app.dart';

void showPopup(BuildContext context, Function buildItems) {
final RenderBox renderBox = context.findRenderObject() as RenderBox;

final offset = renderBox.localToGlobal(Offset.zero);
final left = offset.dx;
final top = offset.dy + renderBox.size.height;
final right = left + renderBox.size.width;
showMenu(
context: context,
position: RelativeRect.fromLTRB(left, top, right, 0.0),
items: buildItems(context),
);
}

0 comments on commit 6cfd2d9

Please sign in to comment.