Skip to content

Commit

Permalink
fix: edit thread shows edition without refresh #298
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlourenco committed Nov 19, 2022
1 parent 24a8491 commit 5911a2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
7 changes: 6 additions & 1 deletion frontend/lib/components/threads/editThreadForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import 'package:frontend/services/threadService.dart';
class EditThreadForm extends StatefulWidget {
final Thread? thread;
final Post? post;
EditThreadForm({Key? key, this.thread, this.post}) : super(key: key);
final void Function(BuildContext, Thread?)? onEditThread;

EditThreadForm({Key? key, this.thread, this.post, this.onEditThread})
: super(key: key);

@override
_EditThreadFormState createState() => _EditThreadFormState();
Expand Down Expand Up @@ -39,6 +42,8 @@ class _EditThreadFormState extends State<EditThreadForm> {
await _threadService.updateThread(id: widget.thread!.id, kind: kind);

if (p != null && t != null) {
widget.onEditThread!(context, t);

ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
Expand Down
16 changes: 13 additions & 3 deletions frontend/lib/components/threads/threadCard/threadCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ final Map<String, Color> THREADCOLOR = {
enum CommunicationType { COMPANY, MEETING, SPEAKER }

class ThreadCard extends StatefulWidget {
final Thread thread;
Thread thread;
// ID of the meeting/company/speaker
final String id;
final CommunicationType type;
final bool small;
const ThreadCard(
ThreadCard(
{Key? key,
required this.thread,
required this.small,
Expand All @@ -35,6 +35,13 @@ class ThreadCardState extends State<ThreadCard>
with AutomaticKeepAliveClientMixin {
bool get wantKeepAlive => true;

Future<void> threadChangedCallback(BuildContext context,
{Thread? thread}) async {
setState(() {
widget.thread = thread!;
});
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down Expand Up @@ -62,7 +69,10 @@ class ThreadCardState extends State<ThreadCard>
thread: widget.thread,
small: widget.small,
id: widget.id,
type: widget.type),
type: widget.type,
onEditThread: (context, _thread) {
threadChangedCallback(context, thread: _thread);
}),
SizedBox(
height: 16,
),
Expand Down
16 changes: 10 additions & 6 deletions frontend/lib/components/threads/threadCard/threadCardHeader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:frontend/models/member.dart';
import 'package:frontend/models/post.dart';
import 'package:frontend/models/speaker.dart';
import 'package:frontend/models/thread.dart';
import 'package:frontend/routes/meeting/MeetingsNotifier.dart';
import 'package:frontend/services/companyService.dart';
import 'package:frontend/services/meetingService.dart';
import 'package:frontend/services/speakerService.dart';
Expand All @@ -21,13 +22,16 @@ class ThreadCardHeader extends StatelessWidget {
final String id;
final CommunicationType type;
final bool small;
final void Function(BuildContext, Thread?) onEditThread;

const ThreadCardHeader(
{Key? key,
required this.p,
required this.thread,
required this.small,
required this.id,
required this.type})
required this.type,
required this.onEditThread})
: super(key: key);

void _deleteThread(context) async {
Expand Down Expand Up @@ -66,10 +70,9 @@ class ThreadCardHeader extends StatelessWidget {
Meeting? m =
await _meetingService.deleteThread(id: id, threadID: thread.id);
if (m != null) {
// FIXME: notifier not working well
// MeetingsNotifier notifier =
// Provider.of<MeetingsNotifier>(context, listen: false);
// notifier.edit(m);
MeetingsNotifier notifier =
Provider.of<MeetingsNotifier>(context, listen: false);
notifier.edit(m);

isThreadDeleted = true;
}
Expand Down Expand Up @@ -111,7 +114,8 @@ class ThreadCardHeader extends StatelessWidget {
context: context,
builder: (context) {
return Container(
child: EditThreadForm(thread: thread, post: p),
child: EditThreadForm(
thread: thread, post: p, onEditThread: onEditThread),
);
},
);
Expand Down

0 comments on commit 5911a2a

Please sign in to comment.