mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 11:58:50 +00:00
feat: category / hashtag pages
- with links form stream info closes #12
This commit is contained in:
109
lib/widgets/category_top_zapped.dart
Normal file
109
lib/widgets/category_top_zapped.dart
Normal file
@ -0,0 +1,109 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/rx_filter.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class CategoryTopZapped extends StatelessWidget {
|
||||
final String tag;
|
||||
final int? limit;
|
||||
|
||||
const CategoryTopZapped({super.key, required this.tag, this.limit});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: Icon(Icons.bolt, color: ZAP_1),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(
|
||||
text: " Most Zapped Streamers",
|
||||
style: TextStyle(color: LAYER_4, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
primary: false,
|
||||
child: FutureBuilder(
|
||||
future:
|
||||
ndk.requests
|
||||
.query(
|
||||
filters: [
|
||||
Filter(
|
||||
kinds: [30_311],
|
||||
limit: 100,
|
||||
tTags: [tag.toLowerCase()],
|
||||
),
|
||||
],
|
||||
)
|
||||
.future,
|
||||
builder: (context, state) {
|
||||
final aTags =
|
||||
(state.data ?? [])
|
||||
.map((e) => "30311:${e.pubKey}:${e.getDtag()}")
|
||||
.toList();
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("top-zapped:$tag:${aTags.length}"),
|
||||
filters: [
|
||||
Filter(kinds: [9735], aTags: aTags),
|
||||
],
|
||||
builder: (context, zaps) {
|
||||
final parsedZaps =
|
||||
zaps?.map((e) => ZapReceipt.fromEvent(e)) ?? [];
|
||||
final topZapped = topZapReceiver(parsedZaps).entries
|
||||
.sortedBy((e) => e.value.sum)
|
||||
.reversed
|
||||
.take(limit ?? 5);
|
||||
|
||||
return Row(
|
||||
spacing: 16,
|
||||
children:
|
||||
topZapped
|
||||
.map(
|
||||
(e) => Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
AvatarWidget.pubkey(e.key),
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
spacing: 2,
|
||||
children: [
|
||||
Text(
|
||||
formatSats(e.value.sum, maxDigits: 0),
|
||||
style: TextStyle(
|
||||
color: ZAP_1,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
ProfileNameWidget.pubkey(e.key),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
25
lib/widgets/game_info.dart
Normal file
25
lib/widgets/game_info.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/pill.dart';
|
||||
|
||||
class GameInfoWidget extends StatelessWidget {
|
||||
final GameInfo info;
|
||||
|
||||
const GameInfoWidget({super.key, required this.info});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PillWidget(
|
||||
color: LAYER_2,
|
||||
onTap: () {
|
||||
context.push("/category/${Uri.encodeComponent(info.id)}", extra: info);
|
||||
},
|
||||
child: Text(
|
||||
info.name,
|
||||
style: TextStyle(color: PRIMARY_1, fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -3,12 +3,18 @@ import 'package:flutter/material.dart';
|
||||
class PillWidget extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color? color;
|
||||
final void Function()? onTap;
|
||||
|
||||
const PillWidget({super.key, required this.child, required this.color});
|
||||
const PillWidget({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.color,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
final inner = Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
@ -16,5 +22,6 @@ class PillWidget extends StatelessWidget {
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
return onTap != null ? GestureDetector(onTap: onTap, child: inner) : inner;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ class StreamGrid extends StatelessWidget {
|
||||
events
|
||||
.map((e) => StreamEvent(e))
|
||||
.where((e) => e.info.stream?.contains(".m3u8") ?? false)
|
||||
.where(
|
||||
(e) =>
|
||||
(e.info.starts ?? e.event.createdAt) <=
|
||||
(DateTime.now().millisecondsSinceEpoch / 1000),
|
||||
)
|
||||
.sortedBy((a) => a.info.starts ?? a.event.createdAt)
|
||||
.reversed;
|
||||
final live = streams.where((s) => s.info.status == StreamStatus.live);
|
||||
|
@ -1,8 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/button_follow.dart';
|
||||
import 'package:zap_stream_flutter/widgets/game_info.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||
import 'package:zap_stream_flutter/widgets/pill.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/stream_cards.dart';
|
||||
|
||||
@ -45,7 +49,36 @@ class StreamInfoWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (stream.info.summary?.isNotEmpty ?? false)
|
||||
Text(stream.info.summary!),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: textToSpans(
|
||||
stream.info.summary!,
|
||||
[],
|
||||
stream.info.host,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (stream.info.tags.isNotEmpty || stream.info.gameInfo != null)
|
||||
Row(
|
||||
spacing: 2,
|
||||
children: [
|
||||
if (stream.info.gameInfo != null)
|
||||
GameInfoWidget(info: stream.info.gameInfo!),
|
||||
...stream.info.tags.map(
|
||||
(t) => PillWidget(
|
||||
color: LAYER_2,
|
||||
onTap: () {
|
||||
context.push("/t/${Uri.encodeComponent(t)}");
|
||||
},
|
||||
child: Text(
|
||||
t,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
StreamCardsWidget(stream: stream),
|
||||
],
|
||||
),
|
||||
|
Reference in New Issue
Block a user