Skip to content

Commit

Permalink
simple display of starter packs
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Dec 12, 2024
1 parent fe26288 commit 5b17fa8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 77 deletions.
155 changes: 102 additions & 53 deletions lib/presentation_layer/components/starter_packs/open_starter_pack.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,68 @@
import 'package:camelus/helpers/helpers.dart';
import 'package:camelus/helpers/nevent_helper.dart';
import 'package:camelus/helpers/nprofile_helper.dart';
import 'package:camelus/presentation_layer/atoms/follow_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../config/palette.dart';
import '../../../domain_layer/entities/nostr_list.dart';
import '../../atoms/long_button.dart';
import '../../atoms/my_profile_picture.dart';
import '../../providers/event_signer_provider.dart';
import '../../providers/inbox_outbox_provider.dart';
import '../../providers/metadata_state_provider.dart';
import '../../routes/nostr/profile/profile_page_2.dart';

class OpenStarterPack extends ConsumerWidget {
final NostrSet followSet;
final bool isOwnStarterPack;

const OpenStarterPack({
super.key,
required this.followSet,
required this.isOwnStarterPack,
});

_onShare(WidgetRef ref) async {
final inboxOutboxP = ref.read(inboxOutboxProvider);
final nip65data = await inboxOutboxP.getNip65data(followSet.pubKey);

final outboxRelays = nip65data?.relays.entries
.where((element) => element.value.isWrite)
.map((e) => e.key)
.toList();

final npub = NprofileHelper().mapToBech32({
"pubkey": followSet.pubKey,
"relays": outboxRelays ?? [],
});

final url = "https://camelus.app/i/$npub/${followSet.name}";

await Clipboard.setData(
ClipboardData(text: url),
);
}

_navigateToProfile(BuildContext context, String pubkey) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfilePage2(
pubkey: pubkey,
),
),
);
}

@override
Widget build(BuildContext context, WidgetRef ref) {
final mySigner = ref.watch(eventSignerProvider);

final myPubkey = mySigner?.getPublicKey();

final bool isOwnStarterPack = myPubkey == followSet.pubKey;

return DefaultTabController(
length: 3,
child: Scaffold(
Expand All @@ -32,11 +74,12 @@ class OpenStarterPack extends ConsumerWidget {
backgroundColor: Palette.background,
toolbarHeight: 45,
actions: [
longButton(
name: "share",
onPressed: () {},
inverted: true,
),
if (isOwnStarterPack)
longButton(
name: "share",
onPressed: () => _onShare(ref),
inverted: true,
),
const SizedBox(
width: 20,
)
Expand Down Expand Up @@ -93,45 +136,50 @@ class OpenStarterPack extends ConsumerWidget {
.watch(metadataStateProvider(displayPubkey))
.userMetadata;
return ListTile(
onTap: () {},
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
UserImage(
imageUrl: displayMetadata?.picture,
pubkey: displayPubkey,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayMetadata?.name ?? "",
style: const TextStyle(
color: Palette.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
overflow: TextOverflow.ellipsis,
onTap: () {
_navigateToProfile(context, displayPubkey);
},
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
UserImage(
imageUrl: displayMetadata?.picture,
pubkey: displayPubkey,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayMetadata?.name ?? "",
style: const TextStyle(
color: Palette.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
const SizedBox(height: 4),
Text(
displayMetadata?.about ?? "",
style: const TextStyle(
color: Palette.gray,
fontSize: 12,
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
displayMetadata?.about ?? "",
style: const TextStyle(
color: Palette.gray,
fontSize: 12,
),
],
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
],
),
],
),
trailing: followButton(
isFollowing: false, onPressed: () {}));
),
],
),
trailing: SizedBox(
height: 0,
width: 0,
),
);
},
),
],
Expand All @@ -140,17 +188,18 @@ class OpenStarterPack extends ConsumerWidget {
const SizedBox(
height: 15,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 20),
width: 400,
height: 40,
child: longButton(
name: "wip",
onPressed: (() {}),
disabled: false,
inverted: true,
if (false)
Container(
padding: const EdgeInsets.symmetric(horizontal: 20),
width: 400,
height: 40,
child: longButton(
name: "wip",
onPressed: (() {}),
disabled: false,
inverted: true,
),
),
),
const SizedBox(
height: 15,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class StarterPacksList extends ConsumerWidget {
MaterialPageRoute(
builder: (context) => OpenStarterPack(
followSet: nostrSet,
isOwnStarterPack: false, // todo: add own check
),
),
);
Expand Down
49 changes: 26 additions & 23 deletions lib/presentation_layer/routes/nostr/profile/profile_page_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class ProfilePage2 extends ConsumerWidget {
Widget build(BuildContext context, ref) {
final myMetadata = ref.watch(metadataStateProvider(pubkey)).userMetadata;

final mySigner = ref.watch(eventSignerProvider);

final myPubkey = mySigner?.getPublicKey();

final bool isOwnProfile = myPubkey == pubkey;

return Scaffold(
backgroundColor: Palette.background,
body: GenericFeed(
Expand Down Expand Up @@ -95,19 +101,20 @@ class ProfilePage2 extends ConsumerWidget {
backgroundColor: Palette.black, // Add a background color
flexibleSpace: FlexibleSpaceBar(
background: _BuildProfileHeader(
isOwnProfile: isOwnProfile,
userMetadata: UserMetadata(
pubkey: pubkey,
eventId: '',
lastFetch: myMetadata?.lastFetch ?? 0,
name: myMetadata?.name,
picture: myMetadata?.picture,
banner: myMetadata?.banner,
nip05: myMetadata?.nip05,
about: myMetadata?.about,
website: myMetadata?.website,
lud06: myMetadata?.lud06,
lud16: myMetadata?.lud16,
)),
pubkey: pubkey,
eventId: '',
lastFetch: myMetadata?.lastFetch ?? 0,
name: myMetadata?.name,
picture: myMetadata?.picture,
banner: myMetadata?.banner,
nip05: myMetadata?.nip05,
about: myMetadata?.about,
website: myMetadata?.website,
lud06: myMetadata?.lud06,
lud16: myMetadata?.lud16,
)),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(48),
Expand Down Expand Up @@ -145,12 +152,13 @@ final _userContactsProvider =
});

class _BuildProfileHeader extends ConsumerWidget {
final UserMetadata userMetadata;
final bool isOwnProfile;
const _BuildProfileHeader({
required this.userMetadata,
required this.isOwnProfile,
});

final UserMetadata userMetadata;

Future<void> _copyToClipboard(String data) async {
await Clipboard.setData(ClipboardData(text: data));
}
Expand Down Expand Up @@ -244,9 +252,10 @@ class _BuildProfileHeader extends ConsumerWidget {
),
),
),
_FollowButton(
pubkey: userMetadata.pubkey,
),
if (!isOwnProfile)
_FollowButton(
pubkey: userMetadata.pubkey,
),
],
),
],
Expand Down Expand Up @@ -393,13 +402,7 @@ class _FollowButtonState extends ConsumerState<_FollowButton> {
@override
Widget build(BuildContext context) {
final followingP = ref.watch(followingProvider);
final signerP = ref.watch(eventSignerProvider);
final ownPubkey = signerP!.getPublicKey();

// on own profile page, don't show follow button
if (widget.pubkey == ownPubkey) {
return Container();
}
return StreamBuilder<ContactList>(
stream: followingP.getContactsStreamSelf(),
builder: (context, snapshot) {
Expand Down

0 comments on commit 5b17fa8

Please sign in to comment.