Skip to content

Commit

Permalink
feat: can delete threads (notifier not working still) #298
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlourenco committed Nov 19, 2022
1 parent b6b7f69 commit eb1304a
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/threads/participations/participationThreadsWidget.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/models/participation.dart';

class CommunicationsList extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/models/participation.dart';
import 'package:frontend/models/thread.dart';

Expand All @@ -20,7 +20,6 @@ class ParticipationThreadsWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
print('Getting ${participation.event}');
return Padding(
padding: const EdgeInsets.all(8.0),
child: FutureBuilder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/threads/threadCardBody.dart';
import 'package:frontend/components/threads/threadCardHeader.dart';
import 'package:frontend/components/threads/threadCard/threadCardBody.dart';
import 'package:frontend/components/threads/threadCard/threadCardHeader.dart';
import 'package:frontend/models/post.dart';
import 'package:frontend/models/thread.dart';
import 'package:shimmer/shimmer.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/blurryDialog.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/models/company.dart';
import 'package:frontend/models/meeting.dart';
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/company/CompanyTableNotifier.dart';
import 'package:frontend/routes/meeting/MeetingsNotifier.dart';
import 'package:frontend/routes/speaker/speakerNotifier.dart';
import 'package:frontend/services/companyService.dart';
import 'package:frontend/services/meetingService.dart';
import 'package:frontend/services/speakerService.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';

Expand All @@ -22,6 +32,82 @@ class ThreadCardHeader extends StatelessWidget {
required this.type})
: super(key: key);

void _deleteThread(context) async {
bool isThreadDeleted = false;

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Deleting')),
);

if (type == CommunicationType.COMPANY) {
CompanyService _companyService = CompanyService();
Company? c =
await _companyService.deleteThread(id: id, threadID: thread.id);
if (c != null) {
// FIXME: notifier not working well
// CompanyTableNotifier notifier =
// Provider.of<CompanyTableNotifier>(context, listen: false);
// notifier.edit(c);

isThreadDeleted = true;
}
} else if (type == CommunicationType.SPEAKER) {
SpeakerService _speakerService = SpeakerService();
Speaker? s =
await _speakerService.deleteThread(id: id, threadID: thread.id);
if (s != null) {
// FIXME: notifier not working well
// SpeakerTableNotifier notifier =
// Provider.of<SpeakerTableNotifier>(context, listen: false);
// notifier.edit(s);

isThreadDeleted = true;
}
} else if (type == CommunicationType.MEETING) {
MeetingService _meetingService = MeetingService();
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);

isThreadDeleted = true;
}
}

if (isThreadDeleted) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Done'),
duration: Duration(seconds: 2),
),
);
} else {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('An error occured.')),
);
}
}

void _deleteThreadDialog(context) {
showDialog(
context: context,
builder: (BuildContext context) {
return BlurryDialog('Warning',
'Are you sure you want to delete thread with content ${p.text} (and all of its comments)?',
() {
_deleteThread(context);
});
},
);
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
Expand Down Expand Up @@ -83,7 +169,7 @@ class ThreadCardHeader extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: IconButton(
onPressed: () {
print("Delete thread");
_deleteThreadDialog(context);
},
icon: Icon(Icons.delete)),
),
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/models/speaker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class Speaker {
return '${this.name}';
}

@override
String toString() => name;
// @override
// String toString() => name;

bool operator ==(o) => o is Speaker && id == o.id;
int get hashCode => id.hashCode;
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/company/CompanyScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:frontend/components/deckTheme.dart';
import 'package:frontend/components/eventNotifier.dart';
import 'package:frontend/components/participationCard.dart';
import 'package:frontend/components/threads/participations/communicationsList.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/models/company.dart';
import 'package:frontend/routes/company/CompanyTableNotifier.dart';
import 'package:frontend/routes/company/EditCompanyForm.dart';
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/company/CompanyTableNotifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CompanyTableNotifier extends ChangeNotifier {
}

void edit(Company s) {
int index = companies.indexOf(s);
int index = companies.indexWhere((comp) => s.id == comp.id);
if (index != -1) {
companies[index] = s;
notifyListeners();
Expand Down
10 changes: 6 additions & 4 deletions frontend/lib/routes/meeting/MeetingCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ class MeetingCard extends StatelessWidget {
_uploadMeetingMinute(context),
icon: Icon(Icons.article),
style: ElevatedButton.styleFrom(
primary: meeting.minute!.isNotEmpty
? const Color(0xFF5C7FF2)
: Colors.green),
backgroundColor:
meeting.minute!.isNotEmpty
? const Color(0xFF5C7FF2)
: Colors.green),
label: meeting.minute!.isNotEmpty
? const Text("Minutes")
: const Text("Add Minutes")),
Expand All @@ -340,7 +341,8 @@ class MeetingCard extends StatelessWidget {
_deleteMeetingMinuteDialog(context),
icon: Icon(Icons.article),
style: ElevatedButton.styleFrom(
primary: const Color(0xFFF25C5C)),
backgroundColor:
const Color(0xFFF25C5C)),
label: const Text("Delete Minutes")))
])),
),
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/meeting/MeetingScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:frontend/components/appbar.dart';
import 'package:frontend/components/blurryDialog.dart';
import 'package:frontend/components/deckTheme.dart';
import 'package:frontend/components/eventNotifier.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/models/meeting.dart';
import 'package:frontend/models/member.dart';
import 'package:frontend/models/thread.dart';
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/speaker/SpeakerScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:frontend/components/eventNotifier.dart';
import 'package:frontend/components/participationCard.dart';
import 'package:frontend/components/router.dart';
import 'package:frontend/components/threads/participations/communicationsList.dart';
import 'package:frontend/components/threads/threadCard.dart';
import 'package:frontend/components/threads/threadCard/threadCard.dart';
import 'package:frontend/routes/speaker/speakerNotifier.dart';
import 'package:frontend/components/status.dart';
import 'package:frontend/main.dart';
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/speaker/speakerNotifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SpeakerTableNotifier extends ChangeNotifier {
}

void edit(Speaker s) {
int index = speakers.indexOf(s);
int index = speakers.indexWhere((speak) => s.id == speak.id);
if (index != -1) {
speakers[index] = s;
notifyListeners();
Expand Down

0 comments on commit eb1304a

Please sign in to comment.