Skip to content

Commit

Permalink
redirct to contact details after successful coagulation
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 1, 2024
1 parent 0dd6b1e commit 222f81f
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 137 deletions.
14 changes: 7 additions & 7 deletions lib/ui/receive_request/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ class ReceiveRequestCubit extends HydratedCubit<ReceiveRequestState> {
}
}

void linkExistingContact(CoagContact contact) {
Future<void> linkExistingContact(CoagContact contact) async {
final updatedContact = contact.copyWith(
dhtSettingsForReceiving: state.profile!.dhtSettingsForReceiving);
unawaited(contactsRepository.updateContact(updatedContact));
dhtSettingsForReceiving: state.profile!.dhtSettingsForReceiving,
details: state.profile!.details);
await contactsRepository.updateContact(updatedContact);
if (!isClosed) {
emit(const ReceiveRequestState(ReceiveRequestStatus.qrcode));
emit(ReceiveRequestState(ReceiveRequestStatus.success,
profile: updatedContact));
}
// TODO: Forward instead to contact details page to share back etc.
}

Future<void> createNewContact() async {
Expand All @@ -140,9 +141,8 @@ class ReceiveRequestCubit extends HydratedCubit<ReceiveRequestState> {
await contactsRepository.updateContact(contact);

if (!isClosed) {
emit(const ReceiveRequestState(ReceiveRequestStatus.qrcode));
emit(ReceiveRequestState(ReceiveRequestStatus.success, profile: contact));
}
// TODO: Forward instead to contact details page to share back etc.
}

void updateNewRequesterContact(String value) {
Expand Down
1 change: 1 addition & 0 deletions lib/ui/receive_request/cubit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

260 changes: 131 additions & 129 deletions lib/ui/receive_request/page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2024 The Coagulate Authors. All rights reserved.
// SPDX-License-Identifier: MPL-2.0
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand All @@ -24,138 +26,138 @@ class ReceiveRequestPage extends StatelessWidget {
create: (context) =>
ReceiveRequestCubit(context.read<ContactsRepository>()),
child: BlocConsumer<ReceiveRequestCubit, ReceiveRequestState>(
listener: (context, state) async {},
builder: (context, state) {
switch (state.status) {
case ReceiveRequestStatus.processing:
return Scaffold(
appBar: AppBar(
title: const Text('Processing...'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: const Center(child: CircularProgressIndicator()));
listener: (context, state) async {
if (state.status == ReceiveRequestStatus.success) {
await Navigator.of(context)
.pushReplacement(ContactPage.route(state.profile!));
}
}, builder: (context, state) {
switch (state.status) {
case ReceiveRequestStatus.processing:
return Scaffold(
appBar: AppBar(
title: const Text('Processing...'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: const Center(child: CircularProgressIndicator()));

case ReceiveRequestStatus.qrcode:
if (state.profile != null) {
Navigator.of(context).pop();
Navigator.of(context).push(ContactPage.route(state.profile!));
}
return Scaffold(
appBar: AppBar(title: const Text('Scan QR Code')),
body: BarcodeScannerPageView(
onDetectCallback: context
.read<ReceiveRequestCubit>()
.qrCodeCaptured));
case ReceiveRequestStatus.qrcode:
return Scaffold(
appBar: AppBar(title: const Text('Scan QR Code')),
body: BarcodeScannerPageView(
onDetectCallback:
context.read<ReceiveRequestCubit>().qrCodeCaptured));

case ReceiveRequestStatus.receivedRequest:
return Scaffold(
// TODO: Theme
backgroundColor: const Color.fromARGB(255, 244, 244, 244),
appBar: AppBar(
title: const Text('Received Request'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Text(
'Someone asks you to share your profile '
'with them. If you already have them in your '
'contacts, pick the matching one, or enter '
'their name to create a new contact.')),
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 16),
child: TextFormField(
decoration: const InputDecoration(
labelText: 'Their Name',
border: OutlineInputBorder()),
onChanged: context
.read<ReceiveRequestCubit>()
.updateNewRequesterContact)),
TextButton(
onPressed: context
case ReceiveRequestStatus.receivedRequest:
return Scaffold(
// TODO: Theme
backgroundColor: const Color.fromARGB(255, 244, 244, 244),
appBar: AppBar(
title: const Text('Received Request'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Text('Someone asks you to share your profile '
'with them. If you already have them in your '
'contacts, pick the matching one, or enter '
'their name to create a new contact.')),
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 16),
child: TextFormField(
decoration: const InputDecoration(
labelText: 'Their Name',
border: OutlineInputBorder()),
onChanged: context
.read<ReceiveRequestCubit>()
.createNewContact,
child: const Text(
'Create new contact & start sharing with them')),
if (state.contactProporsalsForLinking.isNotEmpty)
const Center(
.updateNewRequesterContact)),
TextButton(
onPressed: context
.read<ReceiveRequestCubit>()
.createNewContact,
child: const Text(
'Create new contact & start sharing with them')),
if (state.contactProporsalsForLinking.isNotEmpty)
const Center(
child: Text(
'or pick an existing contact to start sharing with')),
const SizedBox(height: 12),
if (state.contactProporsalsForLinking.isNotEmpty)
_pickExisting(
context, state.contactProporsalsForLinking),
])));

case ReceiveRequestStatus.receivedShare:
return Scaffold(
// TODO: Theme
backgroundColor: const Color.fromARGB(255, 244, 244, 244),
appBar: AppBar(
title: const Text('Received Shared Contact'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// TODO: Display proper profile
const SizedBox(height: 8),
Card(
color: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
margin:
const EdgeInsets.only(left: 8, right: 8, bottom: 8),
child: SizedBox(
child: Padding(
padding: const EdgeInsets.all(16),
child: Text(
'or pick an existing contact to start sharing with')),
const SizedBox(height: 12),
if (state.contactProporsalsForLinking.isNotEmpty)
_pickExisting(
context, state.contactProporsalsForLinking),
])));
state.profile!.details!.displayName)))),
if (state.profile!.details!.phones.isNotEmpty)
phones(state.profile!.details!.phones),
if (state.profile!.details!.emails.isNotEmpty)
emails(state.profile!.details!.emails),
TextButton(
onPressed: context
.read<ReceiveRequestCubit>()
.createNewContact,
child: const Text('Create new contact')),
if (state.contactProporsalsForLinking.isNotEmpty)
const Center(
child: Text('or link to an existing contact')),
if (state.contactProporsalsForLinking.isNotEmpty)
_pickExisting(context, state.contactProporsalsForLinking),
TextButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
child: const Text('Cancel')),
],
)));

case ReceiveRequestStatus.receivedShare:
return Scaffold(
// TODO: Theme
backgroundColor: const Color.fromARGB(255, 244, 244, 244),
appBar: AppBar(
title: const Text('Received Shared Contact'),
actions: [
IconButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
icon: const Icon(Icons.qr_code))
],
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// TODO: Display proper profile
const SizedBox(height: 8),
Card(
color: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
margin: const EdgeInsets.only(
left: 8, right: 8, bottom: 8),
child: SizedBox(
child: Padding(
padding: const EdgeInsets.all(16),
child: Text(
state.profile!.details!.displayName)))),
if (state.profile!.details!.phones.isNotEmpty)
phones(state.profile!.details!.phones),
if (state.profile!.details!.emails.isNotEmpty)
emails(state.profile!.details!.emails),
TextButton(
onPressed: context
.read<ReceiveRequestCubit>()
.createNewContact,
child: const Text('Create new contact')),
if (state.contactProporsalsForLinking.isNotEmpty)
const Center(
child: Text('or link to an existing contact')),
if (state.contactProporsalsForLinking.isNotEmpty)
_pickExisting(
context, state.contactProporsalsForLinking),
TextButton(
onPressed:
context.read<ReceiveRequestCubit>().scanQrCode,
child: const Text('Cancel')),
],
)));
}
}));
case ReceiveRequestStatus.success:
return const Center(child: CircularProgressIndicator());
}
}));
}

Widget _pickExisting(BuildContext context,
Expand All @@ -168,7 +170,7 @@ Widget _pickExisting(BuildContext context,
leading: avatar(c.systemContact, radius: 18),
title: Text(c.details!.displayName),
//trailing: Text(_contactSyncStatus(c)),
onTap: () =>
context.read<ReceiveRequestCubit>().linkExistingContact(c)))
onTap: () => unawaited(
context.read<ReceiveRequestCubit>().linkExistingContact(c))))
.toList(),
));
9 changes: 8 additions & 1 deletion lib/ui/receive_request/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

part of 'cubit.dart';

enum ReceiveRequestStatus { qrcode, processing, receivedShare, receivedRequest }
enum ReceiveRequestStatus {
qrcode,
processing,
receivedShare,
receivedRequest,
success
}

extension ReceiveRequestStatusX on ReceiveRequestStatus {
bool get isQrcode => this == ReceiveRequestStatus.qrcode;
bool get isProcessing => this == ReceiveRequestStatus.processing;
bool get isReceivedShare => this == ReceiveRequestStatus.receivedShare;
bool get isReceivedRequest => this == ReceiveRequestStatus.receivedRequest;
bool get isSuccess => this == ReceiveRequestStatus.success;
}

@JsonSerializable()
Expand Down

0 comments on commit 222f81f

Please sign in to comment.