mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 20:08:50 +00:00
@ -1,4 +1,3 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:ndk/ndk.dart';
|
import 'package:ndk/ndk.dart';
|
||||||
@ -9,6 +8,7 @@ import 'package:zap_stream_flutter/theme.dart';
|
|||||||
import 'package:zap_stream_flutter/utils.dart';
|
import 'package:zap_stream_flutter/utils.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/avatar.dart';
|
import 'package:zap_stream_flutter/widgets/avatar.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/button.dart';
|
import 'package:zap_stream_flutter/widgets/button.dart';
|
||||||
|
import 'package:zap_stream_flutter/widgets/button_follow.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/header.dart';
|
import 'package:zap_stream_flutter/widgets/header.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||||
@ -89,6 +89,7 @@ class ProfilePage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (!isMe) FollowButton(pubkey: hexPubkey),
|
||||||
Text(
|
Text(
|
||||||
"Past Streams",
|
"Past Streams",
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
|
||||||
|
@ -8,8 +8,9 @@ class FollowButton extends StatelessWidget {
|
|||||||
final void Function()? onTap;
|
final void Function()? onTap;
|
||||||
final void Function()? onFollow;
|
final void Function()? onFollow;
|
||||||
final void Function()? onUnfollow;
|
final void Function()? onUnfollow;
|
||||||
|
final ValueNotifier<bool> _loading = ValueNotifier(false);
|
||||||
|
|
||||||
const FollowButton({
|
FollowButton({
|
||||||
super.key,
|
super.key,
|
||||||
required this.pubkey,
|
required this.pubkey,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
@ -24,6 +25,9 @@ class FollowButton extends StatelessWidget {
|
|||||||
return SizedBox.shrink();
|
return SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ValueListenableBuilder(
|
||||||
|
valueListenable: _loading,
|
||||||
|
builder: (context, loading, _) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: ndk.follows.getContactList(signer.getPublicKey()),
|
future: ndk.follows.getContactList(signer.getPublicKey()),
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@ -32,21 +36,33 @@ class FollowButton extends StatelessWidget {
|
|||||||
return BasicButton(
|
return BasicButton(
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
spacing: 4,
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
Icon(isFollowing ? Icons.person_remove : Icons.person_add, size: 16),
|
loading
|
||||||
|
? SizedBox(
|
||||||
|
height: 16,
|
||||||
|
width: 16,
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
isFollowing ? Icons.person_remove : Icons.person_add,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
isFollowing ? "Unfollow" : "Follow",
|
isFollowing ? "Unfollow" : "Follow",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
disabled: loading,
|
||||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
|
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: DEFAULT_BR,
|
borderRadius: DEFAULT_BR,
|
||||||
color: LAYER_2,
|
color: LAYER_2,
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
_loading.value = true;
|
||||||
|
try {
|
||||||
if (onTap != null) {
|
if (onTap != null) {
|
||||||
onTap!();
|
onTap!();
|
||||||
}
|
}
|
||||||
@ -61,6 +77,11 @@ class FollowButton extends StatelessWidget {
|
|||||||
onFollow!();
|
onFollow!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
_loading.value = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:ndk/ndk.dart';
|
import 'package:ndk/ndk.dart';
|
||||||
|
import 'package:zap_stream_flutter/main.dart';
|
||||||
import 'package:zap_stream_flutter/theme.dart';
|
import 'package:zap_stream_flutter/theme.dart';
|
||||||
import 'package:zap_stream_flutter/utils.dart';
|
import 'package:zap_stream_flutter/utils.dart';
|
||||||
import 'package:zap_stream_flutter/widgets/stream_tile.dart';
|
import 'package:zap_stream_flutter/widgets/stream_tile.dart';
|
||||||
@ -35,17 +36,35 @@ class StreamGrid extends StatelessWidget {
|
|||||||
final live = streams.where((s) => s.info.status == StreamStatus.live);
|
final live = streams.where((s) => s.info.status == StreamStatus.live);
|
||||||
final ended = streams.where((s) => s.info.status == StreamStatus.ended);
|
final ended = streams.where((s) => s.info.status == StreamStatus.ended);
|
||||||
final planned = streams.where((s) => s.info.status == StreamStatus.planned);
|
final planned = streams.where((s) => s.info.status == StreamStatus.planned);
|
||||||
|
|
||||||
|
final followList =
|
||||||
|
ndk.accounts.isLoggedIn
|
||||||
|
? ndk.follows.getContactList(ndk.accounts.getPublicKey()!)
|
||||||
|
: Future.value(null);
|
||||||
|
return FutureBuilder(
|
||||||
|
future: followList,
|
||||||
|
builder: (context, state) {
|
||||||
|
final follows = state.data?.contacts ?? [];
|
||||||
|
final followsLive = live.where((e) => follows.contains(e.info.host));
|
||||||
|
final liveNotFollowing = live.where(
|
||||||
|
(e) => !follows.contains(e.info.host),
|
||||||
|
);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
children: [
|
children: [
|
||||||
if (showLive && live.isNotEmpty)
|
if (followsLive.isNotEmpty)
|
||||||
_streamGroup(context, "Live", live.toList()),
|
_streamGroup(context, "Following", followsLive.toList()),
|
||||||
|
if (showLive && liveNotFollowing.isNotEmpty)
|
||||||
|
_streamGroup(context, "Live", liveNotFollowing.toList()),
|
||||||
if (showPlanned && planned.isNotEmpty)
|
if (showPlanned && planned.isNotEmpty)
|
||||||
_streamGroup(context, "Planned", planned.toList()),
|
_streamGroup(context, "Planned", planned.toList()),
|
||||||
if (showEnded && ended.isNotEmpty)
|
if (showEnded && ended.isNotEmpty)
|
||||||
_streamGroup(context, "Ended", ended.toList()),
|
_streamGroup(context, "Ended", ended.toList()),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _streamTitle(String title) {
|
Widget _streamTitle(String title) {
|
||||||
|
Reference in New Issue
Block a user