Skip to content

Commit

Permalink
starter packs state
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Nov 24, 2024
1 parent 2a678b5 commit ad496ef
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 55 deletions.
60 changes: 39 additions & 21 deletions lib/presentation_layer/routes/nostr/onboarding/onboarding.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import 'package:camelus/presentation_layer/providers/onboarding_provider.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_done.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_follow_graph/onboarding_follow_graph.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_login.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_login_amber.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_name.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_page01.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_picture.dart';
import 'package:camelus/presentation_layer/routes/nostr/onboarding/onboarding_profile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../config/onboard_conf.dart';
import '../../../providers/onboarding_provider.dart';
import 'onboarding_done.dart';
import 'onboarding_invited_by.dart';
import 'onboarding_login.dart';
import 'onboarding_login_amber.dart';
import 'onboarding_login_select.dart';
import 'onboarding_name.dart';
import 'onboarding_page01.dart';
import 'onboarding_picture.dart';
import 'onboarding_profile.dart';
import 'onboarding_starter_pack.dart';

class NostrOnboarding extends ConsumerStatefulWidget {
const NostrOnboarding({super.key});
final String? invitedByPubkey;
final String? inviteListName;

const NostrOnboarding({
super.key,
this.invitedByPubkey =
"717ff238f888273f5d5ee477097f2b398921503769303a0c518d06a952f2a75e", // test
this.inviteListName = "news organizations",
});

@override
ConsumerState<NostrOnboarding> createState() => _NostrOnboardingState();
Expand Down Expand Up @@ -148,16 +155,26 @@ class _NostrOnboardingState extends ConsumerState<NostrOnboarding>
controller: _tabController,
physics: pageLock ? const NeverScrollableScrollPhysics() : null,
children: [
OnboardingPage01(
loginCallback: _navigateToLogin,
registerCallback: () {
_tabController.animateTo(
1,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 500),
);
},
),
if (widget.invitedByPubkey == null)
OnboardingPage01(
loginCallback: _navigateToLogin,
registerCallback: () {
_tabController.animateTo(
1,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 500),
);
},
),
if (widget.invitedByPubkey != null)
OnboardingInvitedBy(
nextCallback: () {
_nextTab();
},
userInfo: signUpInfo,
invitedByPubkey: widget.invitedByPubkey!,
inviteListName: widget.inviteListName!,
),
OnboardingName(
userInfo: signUpInfo,
submitCallback: (_) {
Expand All @@ -177,6 +194,7 @@ class _NostrOnboardingState extends ConsumerState<NostrOnboarding>
signUpInfo: signUpInfo,
),
OnboardingStarterPack(
invitedByPubkey: widget.invitedByPubkey,
submitCallback: (followPubkeys) {
signUpInfo.followPubkeys = followPubkeys;
_nextTab();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import 'package:camelus/presentation_layer/atoms/long_button.dart';
import 'package:camelus/config/palette.dart';
import 'package:camelus/presentation_layer/atoms/my_profile_picture.dart';
import 'package:camelus/presentation_layer/providers/metadata_state_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../config/palette.dart';
import '../../../../domain_layer/entities/nostr_list.dart';
import '../../../../domain_layer/entities/onboarding_user_info.dart';
import '../../../atoms/long_button.dart';
import '../../../atoms/my_profile_picture.dart';
import '../../../providers/metadata_state_provider.dart';
import '../../../providers/nostr_lists_follow_state_provider.dart';

class OnboardingInvitedBy extends ConsumerStatefulWidget {
Function nextCallback;
OnboardingUserInfo userInfo;
String invitedByPubkey;
String inviteListName;
final Function nextCallback;
final OnboardingUserInfo userInfo;
final String invitedByPubkey;
final String inviteListName;

OnboardingInvitedBy({
const OnboardingInvitedBy({
super.key,
required this.nextCallback,
required this.userInfo,
Expand All @@ -28,6 +28,21 @@ class OnboardingInvitedBy extends ConsumerStatefulWidget {
}

class _OnboardingInvitedByState extends ConsumerState<OnboardingInvitedBy> {
onJoinWithStarterPack(NostrSet? invitedSet) {
if (invitedSet == null) {
widget.nextCallback();
return;
}

widget.userInfo.followPubkeys
.addAll(invitedSet.elements.map((e) => e.value));

// remove duplicates
widget.userInfo.followPubkeys =
widget.userInfo.followPubkeys.toSet().toList();
widget.nextCallback();
}

NostrSet? _getInvitedSet(WidgetRef ref) {
final inviteeLists =
ref.watch(nostrListsFollowStateProvider(widget.invitedByPubkey));
Expand Down Expand Up @@ -61,7 +76,7 @@ class _OnboardingInvitedByState extends ConsumerState<OnboardingInvitedBy> {
children: [
// Header section (1/4 of the screen)
Container(
height: 200,
height: 180,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
Expand Down Expand Up @@ -165,16 +180,6 @@ class _OnboardingInvitedByState extends ConsumerState<OnboardingInvitedBy> {
.watch(metadataStateProvider(displayPubkey))
.userMetadata;
return ListTile(
onTap: () {
// Toggle selection
//setState(() {
// if (wselectedPubkeys.contains(displayPubkey)) {
// selectedPubkeys.remove(displayPubkey);
// } else {
// selectedPubkeys.add(displayPubkey);
// }
//});
},
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -222,29 +227,30 @@ class _OnboardingInvitedByState extends ConsumerState<OnboardingInvitedBy> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
SizedBox(
width: 400,
height: 40,
child: longButton(
name: "Join Camelus",
onPressed: () {
widget.nextCallback();
onJoinWithStarterPack(invitedSet);
},
inverted: true,
),
),
const SizedBox(height: 15),
Container(
width: 400,
height: 40,
child: longButton(
name: "Signup without a starter pack",
onPressed: () {
// Add cancel functionality
},
inverted: false,
if (invitedSet != null)
SizedBox(
width: 400,
height: 40,
child: longButton(
name: "Signup without a starter pack",
onPressed: () {
widget.nextCallback();
},
inverted: false,
),
),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class OnboardingStarterPack extends ConsumerStatefulWidget {
final Function(List<String>) submitCallback;

final OnboardingUserInfo userInfo;
final String? invitedByPubkey;

const OnboardingStarterPack({
super.key,
required this.submitCallback,
required this.userInfo,
this.invitedByPubkey,
});
@override
ConsumerState<OnboardingStarterPack> createState() =>
Expand All @@ -30,18 +32,30 @@ class OnboardingStarterPack extends ConsumerStatefulWidget {
class _OnboardingStarterPackState extends ConsumerState<OnboardingStarterPack> {
late List<String> selectedPubkeys;

final List<String> recommendedStarterPacks = CAMELUS_RECOMMEDED_STARTER_PACKS;

@override
void initState() {
super.initState();
selectedPubkeys = widget.userInfo.followPubkeys;

if (widget.invitedByPubkey != null && widget.invitedByPubkey!.isNotEmpty) {
// check if its already in the list
if (recommendedStarterPacks.contains(widget.invitedByPubkey!)) {
return;
}

// add to beginning of list
recommendedStarterPacks.insert(0, widget.invitedByPubkey!);
}
}

@override
Widget build(BuildContext context) {
final List<NostrListsFollowState> followSetsList = [];
final List<MetadataState> recommenderMetadataList = [];

for (var element in CAMELUS_RECOMMEDED_STARTER_PACKS) {
for (var element in recommendedStarterPacks) {
followSetsList.add(
ref.watch(nostrListsFollowStateProvider(element)),
);
Expand All @@ -56,7 +70,9 @@ class _OnboardingStarterPackState extends ConsumerState<OnboardingStarterPack> {
backgroundColor: Palette.background,
leading: Container(),
leadingWidth: 0,
title: Text("Starter Packs"),
title: widget.invitedByPubkey == null
? Text("Starter Packs")
: Text("Additional Starter Packs"),
),
body: Column(
children: [
Expand Down

0 comments on commit ad496ef

Please sign in to comment.